As I can see FileUtils.mv can only move directories within a filesystem so basically it is a rename. Is there another method that can also move between filesystems?
rename is an atomic operation and a usual way of moving files on the same filesystem. when source and target are on different filesystems, there is no way to make the move atomic and avoid race conditions.
AFAIK stdlib doesn’t have
mv like opeation .
If you cannot use the
rename (because source and target are on different filesystems), instead of manually going through cumbersome process of finding the stats via
File#info, going through loop of reading, writing, changing attributes etc, i would suggest to use
mv utility via invoking the
system("mv src dest")
Thanks. That would be a solution, but that also makes the code platform-dependent. (AFAIK On Windows the command would be
In some other languages there is function that will hide the complexity of this operation.
e.g. I see in ruby the FileUtile.mv would do the trick. I am not sure if it is a good idea to have the same function do both, but IMHO it is a good idea to provide such a function.
Totally with you. May I suggest you to please raise a RFC on github repo? That might help others to join the discussion and/or provide a patch for the same.
Quick search on github repo revealed below results:
Unfortunately none of them addresses the cross filesystems move operation.
But its still worth a shot to re-raise this request and see how things goes
I raised a feature request