Boost C++ Libraries: Ticket #4930: filesystem::copy_file() has inconsistent behavior when copy_option::overwrite_if_exists is used https://svn.boost.org/trac10/ticket/4930 <p> 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. </p> <p> On Windows <a class="missing wiki">CopyFile</a>() API is used for this which correctly overwrites the target file if it exists. </p> <p> 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'. </p> <p> The fix seems trivial: add O_TRUNC option when opening the destination file. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4930 Trac 1.4.3 Beman Dawes Mon, 06 Dec 2010 14:00:54 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4930#comment:1 https://svn.boost.org/trac10/ticket/4930#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Ouch! That was nasty! </p> <p> Thanks for the bug report, </p> <p> --Beman </p> Ticket Beman Dawes Mon, 06 Dec 2010 14:03:50 GMT <link>https://svn.boost.org/trac10/ticket/4930#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4930#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/67067" title="Fix #4930, add V3 test case to detect any future regression">[67067]</a>) Fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4930" title="#4930: Bugs: filesystem::copy_file() has inconsistent behavior when ... (closed: fixed)">#4930</a>, add V3 test case to detect any future regression </p> </description> <category>Ticket</category> </item> </channel> </rss>