boost文件系统的跨设备链接错误无效 [英] Invalid cross-device link error with boost filesystem
问题描述
我试图使用 boost :: filesystem
将文件从一个位置移动到另一个位置。
我使用 boost :: filesystem :: rename
函数,但是当我尝试这样做,我有以下错误。
I am trying to move a file from a location to another using boost::filesystem
.
I used boost::filesystem::rename
function but when I try to do that 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 understood that the problem is that I am trying to move a file from one folder into another mounted on a different volume.
有与
- 不同的解决方案COPYING该文件,然后删除它(它给我一些安全感)在
- 包装
mv
?
std :: systen
的调用中 - COPYING the file and then DELETE it (it gives me some feeling of security).
- wrapping
mv
in a call tostd::systen
?
boost :: filesystem
中有任何其他函数实现?我不能自己找到它。
Is there any other funciton in boost::filesystem
for what I want to achieve? I cannot find it myself.
我使用g ++和linux。
I am working with g++ and linux.
推荐答案
如果重命名文件(最终通过 rename()
库调用,无论它是否包含在 boost ::
或任何其他)失败,因为源和目标位于不同的文件系统上,唯一的选择是然后复制文件,并在验证副本是否完整和成功后删除原始文件。这是 / bin / mv
的作用 - 它首先尝试 rename()
,如果返回的错误代码它的失败指示跨设备链接情况,它会回到一个副本和删除的情况。
If renaming a file (ultimately through the rename()
library call, whether it's wrapped up in boost::
or anything else) fails because the source and destination are on different file systems, the only option is to then copy the file and delete the original after verifying that the copy was complete and successful. This is what /bin/mv
does - it first tries a rename()
, and if the error code returned by it's failure indicates a cross-device link situation, it falls back to a copy and remove scenario.
这篇关于boost文件系统的跨设备链接错误无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!