24 releases

0.2.5 Oct 9, 2019
0.2.3 Jun 5, 2019
0.2.2 Jun 5, 2018
0.2.1 Mar 21, 2018
0.0.9 Mar 15, 2015

#24 in Filesystem

Download history 1027/week @ 2019-06-26 531/week @ 2019-07-03 1033/week @ 2019-07-10 829/week @ 2019-07-17 788/week @ 2019-07-24 956/week @ 2019-07-31 1472/week @ 2019-08-07 1577/week @ 2019-08-14 789/week @ 2019-08-21 976/week @ 2019-08-28 1297/week @ 2019-09-04 1107/week @ 2019-09-11 1069/week @ 2019-09-18 1027/week @ 2019-09-25 938/week @ 2019-10-02

4,541 downloads per month
Used in 10 crates (9 directly)

MIT license

11KB
172 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.

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

~320–610KB
~10K SLoC