[Haskell-cafe] How to move files?

David Kraeutmann kane at kane.cx
Thu Apr 15 04:40:36 UTC 2021


The source code to mv.c might be useful:

https://github.com/coreutils/coreutils/blob/master/src/mv.c

On 4/15/21 12:32 AM, ☂Josh Chia (謝任中) wrote:
> I'm trying to write to a temp file in /tmp and then move it to another 
> location that may be in /tmp.
>
> If I use System.Directory.renameFile and the final location is in 
> another filesystem, I'll get an error "renameFile:renamePath:rename: 
> unsupported operation (Invalid cross-device link)".
>
> If I copy to the new location and then remove the temp file, but the 
> new location is also in /tmp, I am doing an unnecessary copy (instead 
> of mv), which is inefficient.
>
> I don't know how to detect whether two filepaths are in the same 
> filesystem.
>
> What's the best way to move the file if possible but copy-and-delete 
> if necessary?
>
> Josh
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list