emscripten-core/emscripten

std::filesystem::permissions() does not give me the correct permission value

Open

#12,932 建立於 2020年12月1日

在 GitHub 查看
 (11 留言) (0 反應) (0 負責人)C++ (3,519 fork)batch import
help wantedwontfix

倉庫指標

Star
 (27,361 star)
PR 合併指標
 (平均合併 19天 10小時) (30 天內合併 147 個 PR)

描述

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.

貢獻者指南