copy_file() returns false for a non-regular source but may leave the supplied std::error_code clear.
The implementation first queries the source status, and when from exists but is a directory or another non-regular file type, status() succeeds and leaves tecf clear. Consequently:
std::error_code ec;
bool copied = fs::copy_file(directory, destination, ec);
returns false while ec indicates success. The throwing overload also returns false instead of throwing because it relies on the same error code.
The filesystem specification requires an error to be reported when the source is not a regular file.
Expected behavior
- A directory source returns
false and sets an appropriate error code, such as the library's portable is_a_directory error.
- Other existing non-regular source types return
false with an appropriate nonzero error.
- The throwing overload throws
filesystem_error.
- A missing source continues to report the original lookup error.
- No destination file is created after any rejected source.
copy_file()returnsfalsefor a non-regular source but may leave the suppliedstd::error_codeclear.The implementation first queries the source status, and when
fromexists but is a directory or another non-regular file type,status()succeeds and leavestecfclear. Consequently:std::error_code ec; bool copied = fs::copy_file(directory, destination, ec);returns
falsewhileecindicates success. The throwing overload also returnsfalseinstead of throwing because it relies on the same error code.The filesystem specification requires an error to be reported when the source is not a regular file.
Expected behavior
falseand sets an appropriate error code, such as the library's portableis_a_directoryerror.falsewith an appropriate nonzero error.filesystem_error.