rust-vfs
rust-vfs copied to clipboard
move_file shouldn't require the destination to not exist
The documentation on the move_file method states "The destination must not exist, but its parent directory must".
This doesn't align with the behavior of the built-in fs::rename method (which the PhysicalFS calls to do this).
Should this library align with the lower-level behavior? Without the same behavior, you cannot do an atomic rename, something I need.
Thanks for the comment.
This might be a thorny issue, since it probably is platform dependent. The docs for fs::rename even state that this behaviour may change in the future. Therefore I think it might be best to circumvent the issue by requiring the destination to not exist.
I think atomic renames are probably out of scope for this VFS abstraction as well, since it cannot be guaranteed for all filesystems, either due to platform support or because of unioning/overlaying different implementations.
I've used the atomicwrites crate (https://crates.io/crates/atomicwrites) in the past for this use case.
Agreed on it being thorny. I've rolled my own version of atomicwrites against vfs using temp files etc, but it isn't ideal.
How about adding a replace_file function that is documented similarly to how the std::fs::rename function is?
I like the idea of adding a replace_file
or even replace_file_atomic
function, which would only work as long as the underlying filesystem is the same and supports atomic renames.
I'll have to think about the implementation and possible caveats some more.