https://github.com/casey/bak
📦 Move files out of the way
https://github.com/casey/bak
Last synced: over 1 year ago
JSON representation
📦 Move files out of the way
- Host: GitHub
- URL: https://github.com/casey/bak
- Owner: casey
- License: cc0-1.0
- Created: 2019-09-03T07:48:02.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-11T22:42:33.000Z (over 4 years ago)
- Last Synced: 2025-03-18T15:49:03.724Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
# bak
[](https://crates.io/crates/bak) [](http://docs.rs/bak)
`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` 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".
## caveats
- If `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.