Open HenrikBengtsson opened 8 years ago
One question/concern is that file / directory renaming is sometimes used as an atomic operation. This will no longer be true with a copy'n'delete approach. How closely can we emulate an atomic operation using copy'n'delete?
Atomic copy'n'delete algorithm for files (not directories):
copyFile(pathname, newPathname.tmp)
.If Step 2 fails, then remove newPathname.tmp. If Step 3 fails, then rename pathname.tmp -> pathname and then remove newPathname.tmp. If Step 4 fails, (try again? and) then give an informative error message.
A similar approach could work for directories too.
It would be nice to have the copying logic as a patch to file.rename()
. One obvious error to handle from rename()
is EXDEV
, where the hard link fails across devices.
Thanks for the feedback / comment. Having this in base R would be ideal. I've moved this over to https://github.com/HenrikBengtsson/Wishlist-for-R/issues/33 to keep it independent of the R.utils package.
Add
renameFile(..., methods=c("file.rename", "copy-delete"))
so thatrenameFile()
first tries withbase::file.rename()
and if that does not succeed it should fall back to:copyFile()
.digest::digest()
.Background
Apparently Unix
mv
falls back to copy'n'delete if rename fails, cf. http://stackoverflow.com/questions/24209886/invalid-cross-device-link-error-with-boost-filesystem