Invalid communication error between devices with boost file system

I am trying to move a file from a location to another using boost::filesystem . I used the boost::filesystem::rename function, but when I try to do this, I have the following error.

 terminate called after throwing an instance of 'boost::filesystem::filesystem_error' what(): boost::filesystem::rename: Invalid cross-device link: "./file_A.csv", "/opt/data/file_B.csv" Aborted (core dumped) 

I realized that the problem is that I am trying to move a file from one folder to another installed on another volume.

Is there any solution other than

  • COPY the file and then DELETE it (this gives me some sense of security).
  • wrapping mv in a call to std::systen ?

Is there any other function in boost::filesystem for what I want to achieve? I can not find it myself.

I work with g ++ and linux.

+7
c ++ linux boost-filesystem
source share
1 answer

If renaming a file (ultimately through calling the rename() library, whether it was completed in boost:: or something else) fails because the source and destination are on different file systems, the only option is to copy the file and delete the original after verifying that the copy is completed and completed successfully. This is what /bin/mv does - it first tries rename() , and if the error code returned by it indicates a connection situation between devices, it returns to the copy and delete script.

+13
source share

All Articles