Modify

Ticket #6809 (closed Bugs: fixed)

Opened 2 years ago

Last modified 2 years ago

Implementation of filesystem::rename() method for MS Windows is wrong

Reported by: Sergey Kazakov <sergeyyk@…> Owned by: bemandawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.48.0 Severity: Problem
Keywords: filesystem rename windows Cc:

Description

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.

Attachments

libs_filesystem_src_operations.cpp.patch Download (774 bytes) - added by Sergey Kazakov <sergeyyk@…> 2 years ago.

Change History

Changed 2 years ago by Sergey Kazakov <sergeyyk@…>

comment:1 Changed 2 years ago by bemandawes

  • Status changed from new to closed
  • Resolution set to fixed

(In [78078]) Filesystem: Fix #6809, Implementation of filesystem::rename() method for MS Windows is wrong, by adding MOVEFILE_COPY_ALLOWED to deal with renames across drives, volumes, file systems. Fix has no effect on non-Windows systems.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.