emscripten-core/emscripten

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

Open

#12 932 ouverte le 1 déc. 2020

Voir sur GitHub
 (11 commentaires) (0 réactions) (0 assignés)C++ (3 519 forks)batch import
help wantedwontfix

Métriques du dépôt

Stars
 (27 361 stars)
Métriques de merge PR
 (Merge moyen 19j 10h) (147 PRs mergées en 30 j)

Description

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.

Guide contributeur