Msys2-packages: g++ 9.3.0 throw after trying to overwrite with std::filesystem::copy_options::overwrite_existing

Created on 1 May 2020  路  3Comments  路  Source: msys2/MSYS2-packages

The following program throws if the regular file "bar" already exist with

terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
  what():  filesystem error: cannot copy file: File exists [foo] [bar]

This does not happen under linux and also not under cygwin as I have been told. So I guess it could be an msys2 issue.

#include <filesystem>
int main() {
    std::filesystem::copy_file("foo","bar",std::filesystem::copy_options::overwrite_existing);
}

If "bar" does not exist yet, the copying succeeds. I use an up to date msys2 64bit system.

Most helpful comment

Yeah, I'm getting the same bug, 10.1.0, regardless of copy_options passed.

All 3 comments

MSYS2 gcc 10.1.0, bug reproduced

Yeah, I'm getting the same bug, 10.1.0, regardless of copy_options passed.

Similar error with copy (msys2/g++ 10.2.0):

#include <filesystem>
int main() {
    std::filesystem::copy("fooDir", "barDir", std::filesystem::copy_options::overwrite_existing | std::filesystem::copy_options::recursive);
    return 0;
}

If "barDir" does not exist yet, the copying succeeds. Otherwise, I've got this error:

terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot copy: File exists [fooDir] [barDir]

Was this page helpful?
0 / 5 - 0 ratings