Expand description
bak is a Rust library for safely moving files out of the way.
The API has a few methods, but the one to start with is
bak::move_aside(PATH).
move_aside("foo") will move the file or directory “foo” to
“foo.bak”, if there isn’t already something there. If there is
already a file called “foo.bak”, it will move it to “foo.bak.0”, and
so on.
move_aside() returns an io::Result<PathBuf> containing the path
to the renamed file.
You can call move_aside_with_extension(PATH, EXTENSION) if you’d
like to use an extension other than “bak”. To see where a file would
be moved without actually moving it, call destination_path(PATH)
or destination_with_extension(PATH, EXTENSION).
§caveats
- If
bakis in the middle of renaming a file fromfootofoo.bak, and another process or thread concurrently creates a file calledfoo.bak,bakwill silently overwrite the newly createdfoo.bakwithfoo. This is becausebakusesstd::fs::rename, which clobbers destination files.
Functions§
- destination
- Get the destination that
pathwould be moved to bymove_aside(path)without actually moving it. - destination_
with_ extension - Get the destination that
pathwould be moved to bymove_aside(path, extension)without actually moving it. - move_
aside - Move aside
pathusing the default extension, “bak”. - move_
aside_ with_ extension - Move aside
pathusingextension.