summaryrefslogtreecommitdiffstats
path: root/vendor/gix-lock/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-lock/src
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-lock/src')
-rw-r--r--vendor/gix-lock/src/acquire.rs28
-rw-r--r--vendor/gix-lock/src/file.rs2
-rw-r--r--vendor/gix-lock/src/lib.rs11
3 files changed, 32 insertions, 9 deletions
diff --git a/vendor/gix-lock/src/acquire.rs b/vendor/gix-lock/src/acquire.rs
index c94fd110a..2242a72e1 100644
--- a/vendor/gix-lock/src/acquire.rs
+++ b/vendor/gix-lock/src/acquire.rs
@@ -30,6 +30,16 @@ impl fmt::Display for Fail {
}
}
+impl From<Duration> for Fail {
+ fn from(value: Duration) -> Self {
+ if value.is_zero() {
+ Fail::Immediately
+ } else {
+ Fail::AfterDurationWithBackoff(value)
+ }
+ }
+}
+
/// The error returned when acquiring a [`File`] or [`Marker`].
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
@@ -49,12 +59,18 @@ impl File {
///
/// If `boundary_directory` is given, non-existing directories will be created automatically and removed in the case of
/// a rollback. Otherwise the containing directory is expected to exist, even though the resource doesn't have to.
+ ///
+ /// ### Warning of potential resource leak
+ ///
+ /// Please note that the underlying file will remain if destructors don't run, as is the case when interrupting the application.
+ /// This results in the resource being locked permanently unless the lock file is removed by other means.
+ /// See [the crate documentation](crate) for more information.
pub fn acquire_to_update_resource(
at_path: impl AsRef<Path>,
mode: Fail,
boundary_directory: Option<PathBuf>,
) -> Result<File, Error> {
- let (lock_path, handle) = lock_with_mode(at_path.as_ref(), mode, boundary_directory, |p, d, c| {
+ let (lock_path, handle) = lock_with_mode(at_path.as_ref(), mode, boundary_directory, &|p, d, c| {
gix_tempfile::writable_at(p, d, c)
})?;
Ok(File {
@@ -70,12 +86,18 @@ impl Marker {
///
/// If `boundary_directory` is given, non-existing directories will be created automatically and removed in the case of
/// a rollback.
+ ///
+ /// ### Warning of potential resource leak
+ ///
+ /// Please note that the underlying file will remain if destructors don't run, as is the case when interrupting the application.
+ /// This results in the resource being locked permanently unless the lock file is removed by other means.
+ /// See [the crate documentation](crate) for more information.
pub fn acquire_to_hold_resource(
at_path: impl AsRef<Path>,
mode: Fail,
boundary_directory: Option<PathBuf>,
) -> Result<Marker, Error> {
- let (lock_path, handle) = lock_with_mode(at_path.as_ref(), mode, boundary_directory, |p, d, c| {
+ let (lock_path, handle) = lock_with_mode(at_path.as_ref(), mode, boundary_directory, &|p, d, c| {
gix_tempfile::mark_at(p, d, c)
})?;
Ok(Marker {
@@ -100,7 +122,7 @@ fn lock_with_mode<T>(
resource: &Path,
mode: Fail,
boundary_directory: Option<PathBuf>,
- try_lock: impl Fn(&Path, ContainingDirectory, AutoRemove) -> std::io::Result<T>,
+ try_lock: &dyn Fn(&Path, ContainingDirectory, AutoRemove) -> std::io::Result<T>,
) -> Result<(PathBuf, T), Error> {
use std::io::ErrorKind::*;
let (directory, cleanup) = dir_cleanup(boundary_directory);
diff --git a/vendor/gix-lock/src/file.rs b/vendor/gix-lock/src/file.rs
index 24ec98f13..e0c17bbf6 100644
--- a/vendor/gix-lock/src/file.rs
+++ b/vendor/gix-lock/src/file.rs
@@ -48,7 +48,7 @@ mod io_impls {
}
fn flush(&mut self) -> io::Result<()> {
- self.inner.with_mut(|f| f.flush())?
+ self.inner.with_mut(io::Write::flush)?
}
}
diff --git a/vendor/gix-lock/src/lib.rs b/vendor/gix-lock/src/lib.rs
index 3f131f7a6..1466b3d3b 100644
--- a/vendor/gix-lock/src/lib.rs
+++ b/vendor/gix-lock/src/lib.rs
@@ -1,9 +1,9 @@
//! git-style registered lock files to make altering resources atomic.
//!
-//! In this model, reads are always atomic and can be performed directly while writes are facilitated by a locking mechanism
-//! implemented here.
+//! In this model, reads are always atomic and can be performed directly while writes are facilitated by the locking mechanism
+//! implemented here. Locks are acquired atomically, then written to, to finally atomically overwrite the actual resource.
//!
-//! Lock files mostly `gix-tempfile` with its auto-cleanup and the following:
+//! Lock files are wrapped [`gix-tempfile`](gix_tempfile)-handles and add the following:
//!
//! * consistent naming of lock files
//! * block the thread (with timeout) or fail immediately if a lock cannot be obtained right away
@@ -11,14 +11,15 @@
//!
//! # Limitations
//!
+//! * [All limitations of `gix-tempfile`](gix_tempfile) apply. **A highlight of such a limitation is resource leakage
+//! which results in them being permanently locked unless there is user-intervention.**
//! * As the lock file is separate from the actual resource, locking is merely a convention rather than being enforced.
-//! * The limitations of `gix-tempfile` apply.
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
+use gix_tempfile::handle::{Closed, Writable};
use std::path::PathBuf;
pub use gix_tempfile as tempfile;
-use gix_tempfile::handle::{Closed, Writable};
const DOT_LOCK_SUFFIX: &str = ".lock";