From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix-tempfile/src/handle.rs | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'vendor/gix-tempfile/src/handle.rs') 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, - directory: ContainingDirectory, - cleanup: AutoRemove, - mode: Mode, - ) -> io::Result { - let path = path.as_ref(); + fn at_path(path: &Path, directory: ContainingDirectory, cleanup: AutoRemove, mode: Mode) -> io::Result { 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, + containing_directory: &Path, directory: ContainingDirectory, cleanup: AutoRemove, mode: Mode, ) -> io::Result { - 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 { /// /// 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, directory: ContainingDirectory, cleanup: AutoRemove) -> io::Result { 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 { pub fn take(self) -> Option { 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 { /// /// 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, directory: ContainingDirectory, cleanup: AutoRemove) -> io::Result { 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 { /// 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, directory: ContainingDirectory, cleanup: AutoRemove, ) -> io::Result { 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)? } } -- cgit v1.2.3