emscripten-core/emscripten
Auf GitHub ansehenstd::filesystem::permissions() does not give me the correct permission value
Open
#12.932 geöffnet am 1. Dez. 2020
help wantedwontfix
Repository-Metriken
- Stars
- (27.361 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 19T 10h) (147 gemergte PRs in 30 T)
Beschreibung
Hi,
I see the different behavior of permissions() function in 1.39.7 and 2.0.8
Below is the sample Code:
#include <stdio.h>
#include <iostream>
#include <filesystem>
#include <fstream>
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 <fileName.cpp> node a.out.js
reference: https://en.cppreference.com/w/cpp/experimental/fs/perms
Is there anything I am doing wrong here.