summaryrefslogtreecommitdiffstats
path: root/vendor/tempfile/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/tempfile/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/tempfile/src')
-rw-r--r--vendor/tempfile/src/dir.rs60
-rw-r--r--vendor/tempfile/src/file/imp/unix.rs18
-rw-r--r--vendor/tempfile/src/file/mod.rs33
3 files changed, 104 insertions, 7 deletions
diff --git a/vendor/tempfile/src/dir.rs b/vendor/tempfile/src/dir.rs
index 483b6d807..1b79be445 100644
--- a/vendor/tempfile/src/dir.rs
+++ b/vendor/tempfile/src/dir.rs
@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ffi::OsStr;
use std::fs::remove_dir_all;
use std::mem;
use std::path::{self, Path, PathBuf};
@@ -264,6 +265,65 @@ impl TempDir {
Builder::new().tempdir_in(dir)
}
+ /// Attempts to make a temporary directory with the specified prefix inside of
+ /// `env::temp_dir()`. The directory and everything inside it will be automatically
+ /// deleted once the returned `TempDir` is destroyed.
+ ///
+ /// # Errors
+ ///
+ /// If the directory can not be created, `Err` is returned.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::fs::{self, File};
+ /// use std::io::Write;
+ /// use tempfile::TempDir;
+ ///
+ /// # use std::io;
+ /// # fn run() -> Result<(), io::Error> {
+ /// // Create a directory inside of the current directory
+ /// let tmp_dir = TempDir::with_prefix("foo-")?;
+ /// let tmp_name = tmp_dir.path().file_name().unwrap().to_str().unwrap();
+ /// assert!(tmp_name.starts_with("foo-"));
+ /// # Ok(())
+ /// # }
+ /// ```
+ pub fn with_prefix<S: AsRef<OsStr>>(prefix: S) -> io::Result<TempDir> {
+ Builder::new().prefix(&prefix).tempdir()
+ }
+
+ /// Attempts to make a temporary directory with the specified prefix inside
+ /// the specified directory. The directory and everything inside it will be
+ /// automatically deleted once the returned `TempDir` is destroyed.
+ ///
+ /// # Errors
+ ///
+ /// If the directory can not be created, `Err` is returned.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::fs::{self, File};
+ /// use std::io::Write;
+ /// use tempfile::TempDir;
+ ///
+ /// # use std::io;
+ /// # fn run() -> Result<(), io::Error> {
+ /// // Create a directory inside of the current directory
+ /// let tmp_dir = TempDir::with_prefix_in("foo-", ".")?;
+ /// let tmp_name = tmp_dir.path().file_name().unwrap().to_str().unwrap();
+ /// assert!(tmp_name.starts_with("foo-"));
+ /// # Ok(())
+ /// # }
+ /// ```
+ pub fn with_prefix_in<S: AsRef<OsStr>, P: AsRef<Path>>(
+ prefix: S,
+ dir: P,
+ ) -> io::Result<TempDir> {
+ Builder::new().prefix(&prefix).tempdir_in(dir)
+ }
+
/// Accesses the [`Path`] to the temporary directory.
///
/// [`Path`]: http://doc.rust-lang.org/std/path/struct.Path.html
diff --git a/vendor/tempfile/src/file/imp/unix.rs b/vendor/tempfile/src/file/imp/unix.rs
index fed4e02e7..79aba783e 100644
--- a/vendor/tempfile/src/file/imp/unix.rs
+++ b/vendor/tempfile/src/file/imp/unix.rs
@@ -14,7 +14,10 @@ use crate::util;
use std::path::Path;
#[cfg(not(target_os = "redox"))]
-use rustix::fs::{linkat, renameat, unlinkat, AtFlags, CWD};
+use {
+ rustix::fs::{rename, unlink},
+ std::fs::hard_link,
+};
pub fn create_named(path: &Path, open_options: &mut OpenOptions) -> io::Result<File> {
open_options.read(true).write(true).create_new(true);
@@ -103,13 +106,13 @@ pub fn reopen(_file: &File, _path: &Path) -> io::Result<File> {
#[cfg(not(target_os = "redox"))]
pub fn persist(old_path: &Path, new_path: &Path, overwrite: bool) -> io::Result<()> {
if overwrite {
- renameat(CWD, old_path, CWD, new_path)?;
+ rename(old_path, new_path)?;
} else {
// On Linux, use `renameat_with` to avoid overwriting an existing name,
// if the kernel and the filesystem support it.
#[cfg(any(target_os = "android", target_os = "linux"))]
{
- use rustix::fs::{renameat_with, RenameFlags};
+ use rustix::fs::{renameat_with, RenameFlags, CWD};
use rustix::io::Errno;
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
@@ -124,12 +127,13 @@ pub fn persist(old_path: &Path, new_path: &Path, overwrite: bool) -> io::Result<
}
}
- // Otherwise use `linkat` to create the new filesystem name, which
- // will fail if the name already exists, and then `unlinkat` to remove
+ // Otherwise use `hard_link` to create the new filesystem name, which
+ // will fail if the name already exists, and then `unlink` to remove
// the old name.
- linkat(CWD, old_path, CWD, new_path, AtFlags::empty())?;
+ hard_link(old_path, new_path)?;
+
// Ignore unlink errors. Can we do better?
- let _ = unlinkat(CWD, old_path, AtFlags::empty());
+ let _ = unlink(old_path);
}
Ok(())
}
diff --git a/vendor/tempfile/src/file/mod.rs b/vendor/tempfile/src/file/mod.rs
index d0aa1507a..aca44ced5 100644
--- a/vendor/tempfile/src/file/mod.rs
+++ b/vendor/tempfile/src/file/mod.rs
@@ -608,12 +608,45 @@ impl NamedTempFile<File> {
/// Create a new named temporary file in the specified directory.
///
+ /// This is equivalent to:
+ ///
+ /// ```ignore
+ /// Builder::new().prefix(&prefix).tempfile()
+ /// ```
+ ///
/// See [`NamedTempFile::new()`] for details.
///
/// [`NamedTempFile::new()`]: #method.new
pub fn new_in<P: AsRef<Path>>(dir: P) -> io::Result<NamedTempFile> {
Builder::new().tempfile_in(dir)
}
+
+ /// Create a new named temporary file with the specified filename prefix.
+ ///
+ /// See [`NamedTempFile::new()`] for details.
+ ///
+ /// [`NamedTempFile::new()`]: #method.new
+ pub fn with_prefix<S: AsRef<OsStr>>(prefix: S) -> io::Result<NamedTempFile> {
+ Builder::new().prefix(&prefix).tempfile()
+ }
+ /// Create a new named temporary file with the specified filename prefix,
+ /// in the specified directory.
+ ///
+ /// This is equivalent to:
+ ///
+ /// ```ignore
+ /// Builder::new().prefix(&prefix).tempfile_in(directory)
+ /// ```
+ ///
+ /// See [`NamedTempFile::new()`] for details.
+ ///
+ /// [`NamedTempFile::new()`]: #method.new
+ pub fn with_prefix_in<S: AsRef<OsStr>, P: AsRef<Path>>(
+ prefix: S,
+ dir: P,
+ ) -> io::Result<NamedTempFile> {
+ Builder::new().prefix(&prefix).tempfile_in(dir)
+ }
}
impl<F> NamedTempFile<F> {