23 releases

new 0.2.4 Sep 10, 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

#19 in Filesystem

Download history 739/week @ 2019-05-28 637/week @ 2019-06-04 842/week @ 2019-06-11 575/week @ 2019-06-18 1063/week @ 2019-06-25 486/week @ 2019-07-02 990/week @ 2019-07-09 931/week @ 2019-07-16 669/week @ 2019-07-23 963/week @ 2019-07-30 1276/week @ 2019-08-06 1764/week @ 2019-08-13 879/week @ 2019-08-20 863/week @ 2019-08-27 1313/week @ 2019-09-03

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

MIT license

11KB
170 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

~310–600KB
~10K SLoC