The std::filesystem current_path returns the root one

1.1k views Asked by At

I just wanna to print the current path and its content, via std::filesystem::path::current_path (the compiler is emcc this one). Some code below:

//... some stuff ...
namespace fs = 
#if defined(_MSC_VER) || defined(_WIN32) 
  std::filesystem;
#else
  std::__fs::filesystem;
#endif
//... some stuff ...
cfg::Config::Config() { this->Path = fs::current_path(); }

void cfg::Config::getPath()
{
    for (auto &p : fs::directory_iterator(this->Path)) std::cout << p.path() << '\n';
}

And for windows it works fine, the output looks like:

...
"D:\\GitHub\\Emscripten_OpenGL\\build\\cmake_install.cmake"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Debug"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.dir"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.sln"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.vcxproj"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.vcxproj.filters"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.vcxproj.user"
...

However, whether for Linux subsystem or for docker container with Ubuntu image it just prints the root directory:

application_1  | [100%] Built target Emscripten_Graphics
application_1  | make: make
application_1  | "/tmp"
application_1  | "/home"
application_1  | "/dev"
application_1  | "/proc"

May be I something missed apropos the Linux's std::filesystem?

1

There are 1 answers

0
JuiceFV On BEST ANSWER

I found a solution, so it's may be useful to others. Thanks to @Sugar I dug in the Emscripten Filesystem API. The emscripten creates its own virtual filesystem and uploading there files used in c++ code. According to this issue the way to fix it is to add the -s NODERAWFS=1 as flag, whilst compile.