1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Simple filelock library for rust, using `flock` on Unix-like systems and `LockFileEx` on Windows under the hood.
//!
//! ## Platform behavior
//!
//! All participants must use this locking protocol and resolve the same stable
//! lock-file path. The lock file must not be deleted, renamed, or replaced while
//! participants may be running.
//!
//! Unix locks are advisory and associated with the opened file, not its path.
//! Do not `fork` while holding a guard and then let both parent and child continue
//! through the protected critical section. Lock files are opened read-write and
//! created with mode `0644` before applying the process umask, so cross-user use
//! requires permissions to be arranged explicitly.
//!
//! Windows uses an exclusive byte-range lock. It prevents ordinary reads and
//! writes to that range from other processes, but not access through memory-mapped
//! views. On network filesystems, locking behavior can additionally depend on the
//! client, server, filesystem, and mount configuration.
//!
//! ## Usage
//!
//! ```no_run
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut lock = filelock::new("myfile.lock");
//! let _guard = lock.lock()?;
//!
//! // Perform critical operations
//!
//! // Lock is automatically released when _guard goes out of scope
//! Ok(())
//! }
//! ```
//! To attempt locking without waiting:
//!
//! ```no_run
//! let mut lock = filelock::new("myfile.lock");
//! if let Some(_guard) = lock.try_lock()? {
//! // The lock was acquired.
//! } else {
//! // The lock is currently held elsewhere.
//! }
//! # Ok::<(), filelock::Error>(())
//! ```
//!
//! For manual control:
//!
//! ```no_run
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut lock = filelock::new("myfile.lock");
//! let guard = lock.lock()?;
//!
//! // Perform critical operations
//!
//! // Manually unlock with error handling
//! guard.unlock()?;
//!
//! Ok(())
//! }
//! ```
pub use FileLockGuard;
pub use ;
pub use FileLock;
pub use FileLock;
use Path;
/// Creates a new FileLock instance.
///
/// This is a convenience function equivalent to `FileLock::new(filename)`.
///
/// # Examples
///
/// ```no_run
/// use filelock;
///
/// let mut lock = filelock::new("myfile.lock");
/// let _guard = lock.lock().unwrap();
/// ```