Boost :: filesystem :: rename: cannot create file when this file already exists

I rename the file using boost :: filesystem and sometimes the target file will exist. According to the acceleration instructions:

http://www.boost.org/doc/libs/1_42_0/libs/filesystem/doc/reference.html#Non-member-functions

void rename template (const Path1 & from_p, const Path2 & Up); Required: Path1 :: external_string_type and Path2 :: external_string_type are the same type.

Effects: renames from_p to to_p, as if using POSIX rename ().

Postconditions :! exists (from_p) && & exists (to_p), and the contents and attributes of the file are initially Named from_p otherwise do not change.

[Note: if from_p and to_p allow the same file, no action is taken. Otherwise , if to_p resolves an existing file, it is deleted . the symlink itself is renamed, not the file that it allows is renamed. - final note]

(my emphasis)

When testing this code compiled through MS Visual Studio 2008 on XP SP3, renaming causes boost :: filesystem :: filesystem_error with the message:

Unable to create file if this file already exists

I note that this was raised in the bug report: https://svn.boost.org/trac/boost/ticket/2866

... but claims to be closed in Boost 1.41.0, and I'm using Boost 1.42.0.

Am I doing something wrong here or do I just need to go back to std :: rename?

Linux, , .

+3
1

, , Boost.Filesystem "V3", Boost .

Boost 1.43.0 Linux - , POSIX . , , MoveFile Windows ? V3 MoveFileEx Windows std::rename POSIX .

, , boost::filesystem::remove boost::filesystem::rename, , .

+3

Source: https://habr.com/ru/post/1752604/


All Articles