diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
commit | e02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch) | |
tree | fd60ebbbb5299e16e5fca8c773ddb74f764760db /vendor/gix-tempfile/src | |
parent | Adding debian version 1.73.0+dfsg1-1. (diff) | |
download | rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-tempfile/src')
-rw-r--r-- | vendor/gix-tempfile/src/forksafe.rs | 6 | ||||
-rw-r--r-- | vendor/gix-tempfile/src/handle.rs | 37 | ||||
-rw-r--r-- | vendor/gix-tempfile/src/lib.rs | 9 |
3 files changed, 33 insertions, 19 deletions
diff --git a/vendor/gix-tempfile/src/forksafe.rs b/vendor/gix-tempfile/src/forksafe.rs index 1da7b2b2c..46e9598eb 100644 --- a/vendor/gix-tempfile/src/forksafe.rs +++ b/vendor/gix-tempfile/src/forksafe.rs @@ -47,7 +47,11 @@ impl ForksafeTempfile { self } } - pub fn persist(mut self, path: impl AsRef<Path>) -> Result<Option<std::fs::File>, (std::io::Error, Self)> { + pub fn persist(self, path: impl AsRef<Path>) -> Result<Option<std::fs::File>, (std::io::Error, Self)> { + self.persist_inner(path.as_ref()) + } + + fn persist_inner(mut self, path: &Path) -> Result<Option<std::fs::File>, (std::io::Error, Self)> { match self.inner { TempfileOrTemppath::Tempfile(file) => match file.persist(path) { Ok(file) => Ok(Some(file)), diff --git a/vendor/gix-tempfile/src/handle.rs b/vendor/gix-tempfile/src/handle.rs index f20e237ee..036c6138b 100644 --- a/vendor/gix-tempfile/src/handle.rs +++ b/vendor/gix-tempfile/src/handle.rs @@ -22,13 +22,7 @@ pub(crate) enum Mode { /// Utilities impl Handle<()> { - fn at_path( - path: impl AsRef<Path>, - directory: ContainingDirectory, - cleanup: AutoRemove, - mode: Mode, - ) -> io::Result<usize> { - let path = path.as_ref(); + fn at_path(path: &Path, directory: ContainingDirectory, cleanup: AutoRemove, mode: Mode) -> io::Result<usize> { let tempfile = { let mut builder = tempfile::Builder::new(); let dot_ext_storage; @@ -50,12 +44,12 @@ impl Handle<()> { } fn new_writable_inner( - containing_directory: impl AsRef<Path>, + containing_directory: &Path, directory: ContainingDirectory, cleanup: AutoRemove, mode: Mode, ) -> io::Result<usize> { - let containing_directory = directory.resolve(containing_directory.as_ref())?; + let containing_directory = directory.resolve(containing_directory)?; let id = NEXT_MAP_INDEX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); expect_none(REGISTRY.insert( id, @@ -75,9 +69,14 @@ impl Handle<Closed> { /// /// Depending on the `directory` configuration, intermediate directories will be created, and depending on `cleanup` empty /// intermediate directories will be removed. + /// + /// ### Warning of potential leaks + /// + /// Without [signal handlers](crate::signal) installed, tempfiles will remain once a termination + /// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more. pub fn at(path: impl AsRef<Path>, directory: ContainingDirectory, cleanup: AutoRemove) -> io::Result<Self> { Ok(Handle { - id: Handle::<()>::at_path(path, directory, cleanup, Mode::Closed)?, + id: Handle::<()>::at_path(path.as_ref(), directory, cleanup, Mode::Closed)?, _marker: Default::default(), }) } @@ -88,7 +87,7 @@ impl Handle<Closed> { pub fn take(self) -> Option<TempPath> { let res = REGISTRY.remove(&self.id); std::mem::forget(self); - res.and_then(|(_k, v)| v.map(|v| v.into_temppath())) + res.and_then(|(_k, v)| v.map(ForksafeTempfile::into_temppath)) } } @@ -98,9 +97,14 @@ impl Handle<Writable> { /// /// Depending on the `directory` configuration, intermediate directories will be created, and depending on `cleanup` empty /// intermediate directories will be removed. + /// + /// ### Warning of potential leaks + /// + /// Without [signal handlers](crate::signal) installed, tempfiles will remain once a termination + /// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more. pub fn at(path: impl AsRef<Path>, directory: ContainingDirectory, cleanup: AutoRemove) -> io::Result<Self> { Ok(Handle { - id: Handle::<()>::at_path(path, directory, cleanup, Mode::Writable)?, + id: Handle::<()>::at_path(path.as_ref(), directory, cleanup, Mode::Writable)?, _marker: Default::default(), }) } @@ -108,13 +112,18 @@ impl Handle<Writable> { /// Create a registered tempfile within `containing_directory` with a name that won't clash, and clean it up as specified with `cleanup`. /// Control how to deal with intermediate directories with `directory`. /// The temporary file is opened and can be written to using the [`with_mut()`][Handle::with_mut()] method. + /// + /// ### Warning of potential leaks + /// + /// Without [signal handlers](crate::signal) installed, tempfiles will remain once a termination + /// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more. pub fn new( containing_directory: impl AsRef<Path>, directory: ContainingDirectory, cleanup: AutoRemove, ) -> io::Result<Self> { Ok(Handle { - id: Handle::<()>::new_writable_inner(containing_directory, directory, cleanup, Mode::Writable)?, + id: Handle::<()>::new_writable_inner(containing_directory.as_ref(), directory, cleanup, Mode::Writable)?, _marker: Default::default(), }) } @@ -187,7 +196,7 @@ mod io_impls { } fn flush(&mut self) -> io::Result<()> { - self.with_mut(|f| f.flush())? + self.with_mut(io::Write::flush)? } } diff --git a/vendor/gix-tempfile/src/lib.rs b/vendor/gix-tempfile/src/lib.rs index 8af5ad7a5..9af100f36 100644 --- a/vendor/gix-tempfile/src/lib.rs +++ b/vendor/gix-tempfile/src/lib.rs @@ -9,8 +9,9 @@ //! //! ### Initial Setup //! -//! As no handlers for `TERMination` are installed, it is required to call [`signal::setup()`] before creating the first tempfile. -//! This also allows to control how `git-tempfiles` integrates with other handlers under application control. +//! As no handlers for `TERMination` are installed, it is required to call [`signal::setup()`] before creating +//! the first tempfile. This also allows to control how this crate integrates with +//! other handlers under application control. //! //! As a general rule of thumb, use `Default::default()` as argument to emulate the default behaviour and //! abort the process after cleaning temporary files. Read more about options in [`signal::handler::Mode`]. @@ -23,7 +24,7 @@ //! * The application is performing a write operation on the tempfile when a signal arrives, preventing this tempfile to be removed, //! but not others. Any other operation dealing with the tempfile suffers from the same issue. //! -//! [signal-hook]: https://docs.rs/signal-hook +//! [`signal-hook`]: https://docs.rs/signal-hook //! //! ## Feature Flags #![cfg_attr( @@ -96,8 +97,8 @@ type HashMap<K, V> = hashmap::Concurrent<K, V>; pub use gix_fs::dir::{create as create_dir, remove as remove_dir}; -#[cfg(feature = "signals")] /// signal setup and reusable handlers. +#[cfg(feature = "signals")] pub mod signal; mod forksafe; |