Subject: [Boost-bugs] [Boost C++ Libraries] #4930: filesystem::copy_file() has inconsistent behavior when copy_option::overwrite_if_exists is used
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-12-04 17:04:34
#4930: filesystem::copy_file() has inconsistent behavior when
copy_option::overwrite_if_exists is used
------------------------------------+---------------------------------------
Reporter: postoronnimv77@⦠| Owner: bemandawes
Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.44.0 | Severity: Problem
Keywords: |
------------------------------------+---------------------------------------
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4930> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC