Code Monkey home page Code Monkey logo

bak.rlib's Introduction

bak

crates.io docs

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".

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.

bak.rlib's People

Contributors

casey avatar ctrlcctrlv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.