diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-tempfile/src/handle.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-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-tempfile/src/handle.rs')
-rw-r--r-- | vendor/gix-tempfile/src/handle.rs | 37 |
1 files changed, 23 insertions, 14 deletions
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)? } } |