Crates.io | bak |
lib.rs | bak |
version | 2.0.0 |
source | src |
created_at | 2019-09-04 05:15:46.33987 |
updated_at | 2019-09-05 06:59:38.610997 |
description | 📦 move files out of the way |
homepage | https://github.com/casey/bak |
repository | |
max_upload_size | |
id | 162065 |
size | 20,302 |
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)
.
bak
skips holes in sequences of backup files. For exmaple, if you
call bak::move_aside("foo")
, and "foo.bak.12" exists, bak will
move "foo" to "foo.bak.13".
bak
is in the middle of renaming a file from foo
to
foo.bak
, and another process or thread concurrently creates a
file called foo.bak
, bak
will silently overwrite the newly
created foo.bak
with foo
. This is because bak
uses
std::fs::rename
, which clobbers destination files.