Create a private directory under user
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!
Re: Create a private directory under user
hi,
So this:
Code:
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.
Re: Create a private directory under user
Quote:
Originally Posted by
qlands
So this:
Code:
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 so they go into a directory already fully protected and it looks like it will keep the disk more clean.
Thanks,
Juan
Re: Create a private directory under user
Did you try like this?
Code:
if(file.
setPermissions(QFile::ReadOwner|QFile
::WriteOwner)){ qDebug() << "Permissions changed";
} else {
qDebug() << "Couldn't change permissions";
}
Re: Create a private directory under user
Quote:
Originally Posted by
wysota
Did you try like this?
Code:
if(file.
setPermissions(QFile::ReadOwner|QFile
::WriteOwner)){ 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!