26 releases

Uses old Rust 2015

0.3.1 Jan 11, 2022
0.3.0 Feb 28, 2021
0.2.5 Oct 9, 2019
0.2.3 Jun 5, 2019
0.0.9 Mar 15, 2015

#82 in Filesystem

Download history 18082/week @ 2022-08-06 16344/week @ 2022-08-13 19399/week @ 2022-08-20 14016/week @ 2022-08-27 12912/week @ 2022-09-03 14812/week @ 2022-09-10 13478/week @ 2022-09-17 15205/week @ 2022-09-24 20285/week @ 2022-10-01 18802/week @ 2022-10-08 17971/week @ 2022-10-15 19853/week @ 2022-10-22 20897/week @ 2022-10-29 18941/week @ 2022-11-05 17472/week @ 2022-11-12 15466/week @ 2022-11-19

75,660 downloads per month
Used in 40 crates (20 directly)

MIT license

10KB
174 lines

rust-atomicwrites

Build Status Windows build status

Atomic file-writes. Works on both POSIX and Windows.

The basic idea is to write to temporary files (in the same file system), and move them when done writing. This avoids the problem of two programs writing to the same file. For AllowOverwrite, rename is used. For DisallowOverwrite, link + unlink is used instead to raise errors when the target path already exists.

This is mostly a port of the same-named Python package.

Example

use atomicwrites::{AtomicFile,DisallowOverwrite};

let af = AtomicFile::new("foo", DisallowOverwrite);
try!(af.write(|f| {
    f.write_all(b"HELLO")
}));

Alternatives

  • tempfile has a persist method doing the same thing.

License

Licensed under MIT, see LICENSE.

Dependencies

~155KB