View Full Version : Create a private directory under user
thru
21st March 2011, 20:02
I want to create a simple directory in under QDir::homePath() but that is only readable by the owner (active user). Using QDir::mkdir creates it but is visible, its contents is accessible to other users (at least under Mac)
What would be the most portable procedure to create a private folder?, I've been making some attemps opening the new dir as a QFile and using setPermissions but it looks like doesnt change anything, would be this the correct route?
Thanks!
qlands
22nd March 2011, 09:11
hi,
So this:
QDir dir;
dir.setCurrent(dir.homePath());
dir.mkdir("FromQT");
Will create a directory in your Mac home that is accessible by other?
Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath()
rootPath: For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/".
Check if you get a proper path for homePath().
Carlos.
thru
22nd March 2011, 09:41
So this:
QDir dir;
dir.setCurrent(dir.homePath());
dir.mkdir("FromQT");
Will create a directory in your Mac home that is accessible by other?
Yes, I've copypasted your code and it created Macintosh HD/Users/me/FromQT and I can get into and read from another user -non admin-. ReadOnly, it can not write though. I guess these are the default permissions.
Somehow replying to my first question, I will create the folders on
QDesktopServices::storageLocation(QDesktopServices ::DocumentsLocation) so they go into a directory already fully protected and it looks like it will keep the disk more clean.
Thanks,
Juan
wysota
22nd March 2011, 09:49
Did you try like this?
if(file.setPermissions(QFile::ReadOwner|QFile::Wri teOwner)){
qDebug() << "Permissions changed";
} else {
qDebug() << "Couldn't change permissions";
}
thru
22nd March 2011, 12:44
Did you try like this?
if(file.setPermissions(QFile::ReadOwner|QFile::Wri teOwner)){
qDebug() << "Permissions changed";
} else {
qDebug() << "Couldn't change permissions";
}
Yes, I tried but I did witht the file open and didn't work (setPermissions was returning true but the actual permissions didn't change).
I've just tried not opening the file and it woks perfectly.
Thanks!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.