[][src]Crate lockfile

This crate provides a lockfile struct that marks a location in the filesystem as locked.

A lock is conceptually created when the file is created, and released when it is deleted.

If the file is already present, the create function will fail.

Examples

use lockfile::Lockfile;

const PATH: &str = "/tmp/some_file/s8329894";
let lockfile = Lockfile::create(PATH)?;
assert_eq!(lockfile.path(), Path::new(PATH));
lockfile.release()?; // or just let the lockfile be dropped
// File has been unlinked/deleted.
assert_eq!(fs::metadata(PATH).unwrap_err().kind(),
           io::ErrorKind::NotFound);

Structs

Lockfile

A lockfile that cleans up after itself.