Skip to content

Commit ae29826

Browse files
committed
doc: make clear that locks can leak and what that means on acquiring a lock (#1026)
1 parent fda4337 commit ae29826

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

gix-lock/src/acquire.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ impl File {
5959
///
6060
/// If `boundary_directory` is given, non-existing directories will be created automatically and removed in the case of
6161
/// a rollback. Otherwise the containing directory is expected to exist, even though the resource doesn't have to.
62+
///
63+
/// ### Warning of potential resource leak
64+
///
65+
/// Please note that the underlying file will remain if destructors don't run, as is the case when interrupting the application.
66+
/// This results in the resource being locked permanently unless the lock file is removed by other means.
67+
/// See [the crate documentation](crate) for more information.
6268
pub fn acquire_to_update_resource(
6369
at_path: impl AsRef<Path>,
6470
mode: Fail,
@@ -80,6 +86,12 @@ impl Marker {
8086
///
8187
/// If `boundary_directory` is given, non-existing directories will be created automatically and removed in the case of
8288
/// a rollback.
89+
///
90+
/// ### Warning of potential resource leak
91+
///
92+
/// Please note that the underlying file will remain if destructors don't run, as is the case when interrupting the application.
93+
/// This results in the resource being locked permanently unless the lock file is removed by other means.
94+
/// See [the crate documentation](crate) for more information.
8395
pub fn acquire_to_hold_resource(
8496
at_path: impl AsRef<Path>,
8597
mode: Fail,

gix-lock/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
//! git-style registered lock files to make altering resources atomic.
22
//!
3-
//! In this model, reads are always atomic and can be performed directly while writes are facilitated by a locking mechanism
4-
//! implemented here.
3+
//! In this model, reads are always atomic and can be performed directly while writes are facilitated by the locking mechanism
4+
//! implemented here. Locks are acquired atomically, then written to, to finally atomically overwrite the actual resource.
55
//!
6-
//! Lock files mostly `gix-tempfile` with its auto-cleanup and the following:
6+
//! Lock files are wrapped [`gix-tempfile`](gix_tempfile)-handles and add the following:
77
//!
88
//! * consistent naming of lock files
99
//! * block the thread (with timeout) or fail immediately if a lock cannot be obtained right away
1010
//! * commit lock files to atomically put them into the location of the originally locked file
1111
//!
1212
//! # Limitations
1313
//!
14+
//! * [All limitations of `gix-tempfile`](gix_tempfile) apply. **A highlight of such a limitation is resource leakage
15+
//! which results in them being permanently locked unless there is user-intervention.**
1416
//! * As the lock file is separate from the actual resource, locking is merely a convention rather than being enforced.
15-
//! * The limitations of `gix-tempfile` apply.
1617
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
1718

19+
use gix_tempfile::handle::{Closed, Writable};
1820
use std::path::PathBuf;
1921

2022
pub use gix_tempfile as tempfile;
21-
use gix_tempfile::handle::{Closed, Writable};
2223

2324
const DOT_LOCK_SUFFIX: &str = ".lock";
2425

0 commit comments

Comments
 (0)