If a folder doesn't have read/write access, if (!(permission & fs::perms::owner_read) == fs::perms::no_perms) will always return success.
Rahool24 opened this issue · 1 comments
I have used the boost-1.79.0 version.
Case 1:
If the folder doesn't have read or write permission, the boost fs::status(filename, error). permissions() returns success.
then I have checked.
if (!(permission & fs::perms::owner_read) == fs::perms::no_perms)
this condition ,it returns true. but actually that folder doesn't have permissions.
boost::system::error_code error;
fs::perms permission = fs::status(filename, error).permissions();
if (error.value() == boost::system::errc::success)
{
if (!(permission & fs::perms::owner_read) == fs::perms::no_perms) // if folder have not permissions this condition should failed for folder , but this condition satisfied , then execute next line
{
if (file.is_open()) // here try to open the folder using (file.is_open()) function .It return false because the folder doesn't have permissions.
{
buffer.Resize(GetFileSize(filename, status));
if(status.GetStatus())
file.read(&buffer[0], buffer.Size());
}
else
cout<<"Can not Open File/Folder" <<endl;
}
else
cout<<"Permission Denied For Read" <<endl;
}
For example:
F:\home\test this folder doesn't have write permission. should not write a file in F:\home\test folder.
Case 2:
-
Check the read access to the folder using
"if (!(permission & fs::perms::owner_read) == fs::perms::no_perms)";
here this condition gets true even though the folder doesn't have read access.
ex:
F:\home\test -
In this same case, I have checked for the file permission ("F:/home/test/check.json") in the same folder. "
If (!(permission & fs::perms::owner_read) == fs::perms::no_perms),
" this condition works (it returns false). -
The same issue is happening for the write permission check for the folder.
how to validate folder permission?
Thanks!
if (!(permission & fs::perms::owner_read) == fs::perms::no_perms)
is likely incorrect.operator!
has higher precedence thanoperator==
, so the condition reads asif ( (!(permission & fs::perms::owner_read)) == fs::perms::no_perms )
, i.e. the result ofpermission & fs::perms::owner_read
is converted tobool
, then an inverse of it is converted tofs::perms
and compared tofs::perms::no_perms
. This makes no sense at all. I think, you wanted to sayif ((permission & fs::perms::owner_read) != fs::perms::no_perms)
instead.- On Windows, read permission is always indicated as present because Windows doesn't really support POSIX permissions. Basically, if a file is marked with the "read-only" attribute, Boost.Filesystem will indicate the file as readable. If it is not marked, it will indicate it as both readable and writable.
- Boost.Filesystem does not support or interpret ACLs, if that's how you define the file as "readable". There are no plans to support ACLs, and such support would not translate to POSIX-style permissions anyway.