Function file_lock::lock
[−]
[src]
pub fn lock(filename: &str) -> Result<Lock, Error>
Locks the specified file.
The lock()
and lock_wait()
functions try to perform a lock on the
specified file. The difference between the two is what they do when
another process has a lock on the same file:
- lock() - immediately return with an
Errno
error. - lock_wait() - waits (i.e. blocks the running thread) for the current owner of the lock to relinquish the lock.
Example
extern crate file_lock; use file_lock::*; use file_lock::Error::*; fn main() { let l = lock("/tmp/file-lock-test"); match l { Ok(_) => println!("Got lock"), Err(e) => match e { InvalidFilename => println!("Invalid filename"), Errno(i) => println!("Got filesystem error {}", i), } } }