#4930 closed Bugs (fixed)
filesystem::copy_file() has inconsistent behavior when copy_option::overwrite_if_exists is used
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The behavior of filesystem::copy_file() function with copy_option::overwrite_if_exists option set is misleading and differs on Windows and on the rest (POSIX) systems.
On Windows CopyFile() API is used for this which correctly overwrites the target file if it exists.
On non-Windows systems open(2) is used with O_CREAT|O_WRONLY which causes only the first size(from_file) bytes of the destination file tp be overwritten with the source leaving the rest tail intact. So if the source file initially contains 'ABCD' and the destination contains 'abcde' the result of copy_file() with 'overwrite_if_exists option' set results the destination to contain 'ABCDe'.
The fix seems trivial: add O_TRUNC option when opening the destination file.
Change History (2)
comment:1 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Ouch! That was nasty!
Thanks for the bug report,
--Beman