Subject: [Boost-bugs] [Boost C++ Libraries] #6809: Implementation of filesystem::rename() method for MS Windows is wrong
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-04-19 10:01:10
#6809: Implementation of filesystem::rename() method for MS Windows is wrong
-------------------------------------------------+--------------------------
Reporter: Sergey Kazakov <sergeyyk@â¦> | Owner: bemandawes
Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.48.0 | Severity: Problem
Keywords: filesystem rename windows |
-------------------------------------------------+--------------------------
simple program:
try
{
boost::filesystem::rename( "c:\1.txt", "d:\1.txt" );
}
catch( boost::filesystem::filesystem_error& e )
{
std::cout << "filesystem_error: " << e.what();
}
output:
filesystem_error: boost::filesystem::rename: The system cannot move the
file to a different disk drive: "c:\1.txt", "d:\1.txt"
The problem is caused by BOOST_MOVE_FILE macro definition
in \libs\filesystem\v3\src\operations.cpp file
# define BOOST_MOVE_FILE(OLD,NEW)(::MoveFileExW(OLD, NEW,
MOVEFILE_REPLACE_EXISTING)!= 0)
According to MSDN:
When moving a file, the destination can be on a different file system or
volume. If the destination is on another drive, you must set the
MOVEFILE_COPY_ALLOWED flag in dwFlags.
Without this flag MoveFileEx() method fails with error code 0x11 ("The
system cannot move the file to a different disk drive").
So bug can be fixed in following way
# define BOOST_MOVE_FILE(OLD,NEW)(::MoveFileExW(OLD, NEW,
MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED)!= 0)
Please find a patch attached.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6809> 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:09 UTC