emscripten-core / emscripten-core/emscripten
std::filesystem::permissions() does not give me the correct permission value
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Hi,
I see the different behavior of permissions() function in `1.39.7` and `2.0.8`
Below is the sample Code:
```
#include
#include
#include
#include
int main() {
std::error_code ec;
// Creates a unique filename that does not name a currently existing file
const auto fileName = std::tmpnam(nullptr);
std::wofstream ofs{ fileName };
ofs.close();
// check whether file exist or not
if (std::filesystem::exists(fileName))
{
std::cout <<__FILE__<<" "<<__FUNCTION__ <<" "<<__LINE__<<"\n" ;
}
std::cout <<__FILE__<<" "<<__FUNCTION__ <<" "<<__LINE__<< " " << " std::filesystem::perms::group_read = " <<(int)std::filesystem::perms::group_read <<"\n" ;
// now set the permission to the file
std::filesystem::permissions(fileName,std::filesystem::perms::group_read,ec);
if (ec) {
std::cout <<__FILE__<<" "<<__FUNCTION__ <<" "<<__LINE__<< " " << ec << "\n" ;
}
// Now get the File Status
auto s = std::filesystem::status(fileName, ec);
// Now get the file permission which was set above
std::filesystem::perms perm = s.permissions();
std::cout <<__FILE__<<" "<<__FUNCTION__ <<" "<<__LINE__<< " " << "perm = " <<(int)perm <<" std::filesystem::perms::group_read = " <<(int)std::filesystem::perms::group_read <<"\n" ;
return 0;
}
```
I get below output in `1.39.7`
perm = `32` std::filesystem::perms::group_read = 32
I get below output in `2.0.8`
perm = `0` std::filesystem::perms::group_read = 32
The perm value = 0 means no permission set. However, I had set the permission
Here is the command I used to build and run:
> em++ -std=c++17
> node a.out.js
reference:
https://en.cppreference.com/w/cpp/experimental/fs/perms
Is there anything I am doing wrong here.
Contributor guide
Assessment
This issue has not been assessed yet.