Boost logo

Boost Users :

Subject: [Boost-users] Atomic boost::filesystem::rename
From: Lars (laasunde_at_[hidden])
Date: 2019-01-15 20:02:01


Hello,

What is the most "atomic" way to move two files from a local disk to a server location? The meaning of atomic in this context means that either both files are moved or both files stay in original location. No intermediate files should be present once operation is finished.

The two files are located in different directories;
/root/file_a
/root/data/file_b

The solution must support both Windows and Linux environment.

It appears boost::filesystem::rename(..) uses Win32 API MoveFileExW for the Windows implementation. The documentation for MoveFileExW states;
"If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions.
If the file is successfully copied to a different volume and the original file is unable to be deleted, the function succeeds leaving the source file intact."

This means boost::filesystem::rename(..) could potentially just perform a file copy which is undesirable behaviour.

Our understanding is that Boost filesystem does not contain ACL permission support [1] which make it difficult to check privileges prior to performing moves.

Appreciate any input on the matter.

Using C++14 and Boost.

[1] - https://lists.boost.org/boost-users/2018/12/89232.php



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net