summaryrefslogtreecommitdiffstats
path: root/vendor/tempfile/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tempfile/src')
-rw-r--r--vendor/tempfile/src/dir.rs24
-rw-r--r--vendor/tempfile/src/file/imp/windows.rs3
-rw-r--r--vendor/tempfile/src/file/mod.rs96
-rw-r--r--vendor/tempfile/src/spooled.rs84
-rw-r--r--vendor/tempfile/src/util.rs9
5 files changed, 174 insertions, 42 deletions
diff --git a/vendor/tempfile/src/dir.rs b/vendor/tempfile/src/dir.rs
index 917e47ec2..483b6d807 100644
--- a/vendor/tempfile/src/dir.rs
+++ b/vendor/tempfile/src/dir.rs
@@ -45,16 +45,16 @@ use crate::Builder;
/// # }
/// # fn run() -> Result<(), io::Error> {
/// // Create a directory inside of `std::env::temp_dir()`
-/// let dir = tempdir()?;
+/// let tmp_dir = tempdir()?;
///
-/// let file_path = dir.path().join("my-temporary-note.txt");
-/// let mut file = File::create(file_path)?;
-/// writeln!(file, "Brian was here. Briefly.")?;
+/// let file_path = tmp_dir.path().join("my-temporary-note.txt");
+/// let mut tmp_file = File::create(file_path)?;
+/// writeln!(tmp_file, "Brian was here. Briefly.")?;
///
/// // `tmp_dir` goes out of scope, the directory as well as
/// // `tmp_file` will be deleted here.
-/// drop(file);
-/// dir.close()?;
+/// drop(tmp_file);
+/// tmp_dir.close()?;
/// # Ok(())
/// # }
/// ```
@@ -94,16 +94,16 @@ pub fn tempdir() -> io::Result<TempDir> {
/// # }
/// # fn run() -> Result<(), io::Error> {
/// // Create a directory inside of the current directory.
-/// let dir = tempdir_in(".")?;
+/// let tmp_dir = tempdir_in(".")?;
///
-/// let file_path = dir.path().join("my-temporary-note.txt");
-/// let mut file = File::create(file_path)?;
-/// writeln!(file, "Brian was here. Briefly.")?;
+/// let file_path = tmp_dir.path().join("my-temporary-note.txt");
+/// let mut tmp_file = File::create(file_path)?;
+/// writeln!(tmp_file, "Brian was here. Briefly.")?;
///
/// // `tmp_dir` goes out of scope, the directory as well as
/// // `tmp_file` will be deleted here.
-/// drop(file);
-/// dir.close()?;
+/// drop(tmp_file);
+/// tmp_dir.close()?;
/// # Ok(())
/// # }
/// ```
diff --git a/vendor/tempfile/src/file/imp/windows.rs b/vendor/tempfile/src/file/imp/windows.rs
index cb2673b5a..9df65f9e8 100644
--- a/vendor/tempfile/src/file/imp/windows.rs
+++ b/vendor/tempfile/src/file/imp/windows.rs
@@ -75,9 +75,6 @@ pub fn keep(path: &Path) -> io::Result<()> {
}
pub fn persist(old_path: &Path, new_path: &Path, overwrite: bool) -> io::Result<()> {
- // TODO: We should probably do this in one-shot using SetFileInformationByHandle but the API is
- // really painful.
-
unsafe {
let old_path_w = to_utf16(old_path);
let new_path_w = to_utf16(new_path);
diff --git a/vendor/tempfile/src/file/mod.rs b/vendor/tempfile/src/file/mod.rs
index 023acd26a..7be8dc8c2 100644
--- a/vendor/tempfile/src/file/mod.rs
+++ b/vendor/tempfile/src/file/mod.rs
@@ -916,12 +916,58 @@ impl<F: Read> Read for NamedTempFile<F> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.as_file_mut().read(buf).with_err_path(|| self.path())
}
+
+ fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
+ self.as_file_mut()
+ .read_vectored(bufs)
+ .with_err_path(|| self.path())
+ }
+
+ fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
+ self.as_file_mut()
+ .read_to_end(buf)
+ .with_err_path(|| self.path())
+ }
+
+ fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
+ self.as_file_mut()
+ .read_to_string(buf)
+ .with_err_path(|| self.path())
+ }
+
+ fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
+ self.as_file_mut()
+ .read_exact(buf)
+ .with_err_path(|| self.path())
+ }
}
impl Read for &NamedTempFile<File> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.as_file().read(buf).with_err_path(|| self.path())
}
+
+ fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
+ self.as_file()
+ .read_vectored(bufs)
+ .with_err_path(|| self.path())
+ }
+
+ fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
+ self.as_file()
+ .read_to_end(buf)
+ .with_err_path(|| self.path())
+ }
+
+ fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
+ self.as_file()
+ .read_to_string(buf)
+ .with_err_path(|| self.path())
+ }
+
+ fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
+ self.as_file().read_exact(buf).with_err_path(|| self.path())
+ }
}
impl<F: Write> Write for NamedTempFile<F> {
@@ -932,6 +978,24 @@ impl<F: Write> Write for NamedTempFile<F> {
fn flush(&mut self) -> io::Result<()> {
self.as_file_mut().flush().with_err_path(|| self.path())
}
+
+ fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
+ self.as_file_mut()
+ .write_vectored(bufs)
+ .with_err_path(|| self.path())
+ }
+
+ fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
+ self.as_file_mut()
+ .write_all(buf)
+ .with_err_path(|| self.path())
+ }
+
+ fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
+ self.as_file_mut()
+ .write_fmt(fmt)
+ .with_err_path(|| self.path())
+ }
}
impl Write for &NamedTempFile<File> {
@@ -942,6 +1006,20 @@ impl Write for &NamedTempFile<File> {
fn flush(&mut self) -> io::Result<()> {
self.as_file().flush().with_err_path(|| self.path())
}
+
+ fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
+ self.as_file()
+ .write_vectored(bufs)
+ .with_err_path(|| self.path())
+ }
+
+ fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
+ self.as_file().write_all(buf).with_err_path(|| self.path())
+ }
+
+ fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
+ self.as_file().write_fmt(fmt).with_err_path(|| self.path())
+ }
}
impl<F: Seek> Seek for NamedTempFile<F> {
@@ -956,6 +1034,13 @@ impl Seek for &NamedTempFile<File> {
}
}
+#[cfg(all(fd, unix))]
+impl<F: std::os::unix::io::AsFd> std::os::unix::io::AsFd for NamedTempFile<F> {
+ fn as_fd(&self) -> std::os::unix::io::BorrowedFd<'_> {
+ self.as_file().as_fd()
+ }
+}
+
#[cfg(unix)]
impl<F> std::os::unix::io::AsRawFd for NamedTempFile<F>
where
@@ -967,6 +1052,17 @@ where
}
}
+#[cfg(all(fd, windows))]
+impl<F> std::os::windows::io::AsHandle for NamedTempFile<F>
+where
+ F: std::os::windows::io::AsHandle,
+{
+ #[inline]
+ fn as_handle(&self) -> std::os::windows::io::BorrowedHandle<'_> {
+ self.as_file().as_handle()
+ }
+}
+
#[cfg(windows)]
impl<F> std::os::windows::io::AsRawHandle for NamedTempFile<F>
where
diff --git a/vendor/tempfile/src/spooled.rs b/vendor/tempfile/src/spooled.rs
index db14967ca..2c8eaa4e5 100644
--- a/vendor/tempfile/src/spooled.rs
+++ b/vendor/tempfile/src/spooled.rs
@@ -86,7 +86,7 @@ impl SpooledTempFile {
pub fn roll(&mut self) -> io::Result<()> {
if !self.is_rolled() {
let mut file = tempfile()?;
- if let SpooledData::InMemory(ref mut cursor) = self.inner {
+ if let SpooledData::InMemory(cursor) = &mut self.inner {
file.write_all(cursor.get_ref())?;
file.seek(SeekFrom::Start(cursor.position()))?;
}
@@ -99,12 +99,12 @@ impl SpooledTempFile {
if size as usize > self.max_size {
self.roll()?; // does nothing if already rolled over
}
- match self.inner {
- SpooledData::InMemory(ref mut cursor) => {
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => {
cursor.get_mut().resize(size as usize, 0);
Ok(())
}
- SpooledData::OnDisk(ref mut file) => file.set_len(size),
+ SpooledData::OnDisk(file) => file.set_len(size),
}
}
@@ -117,9 +117,37 @@ impl SpooledTempFile {
impl Read for SpooledTempFile {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- match self.inner {
- SpooledData::InMemory(ref mut cursor) => cursor.read(buf),
- SpooledData::OnDisk(ref mut file) => file.read(buf),
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.read(buf),
+ SpooledData::OnDisk(file) => file.read(buf),
+ }
+ }
+
+ fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.read_vectored(bufs),
+ SpooledData::OnDisk(file) => file.read_vectored(bufs),
+ }
+ }
+
+ fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.read_to_end(buf),
+ SpooledData::OnDisk(file) => file.read_to_end(buf),
+ }
+ }
+
+ fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.read_to_string(buf),
+ SpooledData::OnDisk(file) => file.read_to_string(buf),
+ }
+ }
+
+ fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.read_exact(buf),
+ SpooledData::OnDisk(file) => file.read_exact(buf),
}
}
}
@@ -127,35 +155,49 @@ impl Read for SpooledTempFile {
impl Write for SpooledTempFile {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
// roll over to file if necessary
- let mut rolling = false;
- if let SpooledData::InMemory(ref mut cursor) = self.inner {
- rolling = cursor.position() as usize + buf.len() > self.max_size;
- }
- if rolling {
+ if matches! {
+ &self.inner, SpooledData::InMemory(cursor)
+ if cursor.position() as usize + buf.len() > self.max_size
+ } {
self.roll()?;
}
// write the bytes
- match self.inner {
- SpooledData::InMemory(ref mut cursor) => cursor.write(buf),
- SpooledData::OnDisk(ref mut file) => file.write(buf),
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.write(buf),
+ SpooledData::OnDisk(file) => file.write(buf),
+ }
+ }
+
+ fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
+ if matches! {
+ &self.inner, SpooledData::InMemory(cursor)
+ // Borrowed from the rust standard library.
+ if cursor.position() as usize + bufs.iter()
+ .fold(0usize, |a, b| a.saturating_add(b.len())) > self.max_size
+ } {
+ self.roll()?;
+ }
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.write_vectored(bufs),
+ SpooledData::OnDisk(file) => file.write_vectored(bufs),
}
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
- match self.inner {
- SpooledData::InMemory(ref mut cursor) => cursor.flush(),
- SpooledData::OnDisk(ref mut file) => file.flush(),
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.flush(),
+ SpooledData::OnDisk(file) => file.flush(),
}
}
}
impl Seek for SpooledTempFile {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
- match self.inner {
- SpooledData::InMemory(ref mut cursor) => cursor.seek(pos),
- SpooledData::OnDisk(ref mut file) => file.seek(pos),
+ match &mut self.inner {
+ SpooledData::InMemory(cursor) => cursor.seek(pos),
+ SpooledData::OnDisk(file) => file.seek(pos),
}
}
}
diff --git a/vendor/tempfile/src/util.rs b/vendor/tempfile/src/util.rs
index c61082d50..d426ba3d7 100644
--- a/vendor/tempfile/src/util.rs
+++ b/vendor/tempfile/src/util.rs
@@ -15,16 +15,13 @@ fn tmpname(prefix: &OsStr, suffix: &OsStr, rand_len: usize) -> OsString {
buf
}
-pub fn create_helper<F, R>(
+pub fn create_helper<R>(
base: &Path,
prefix: &OsStr,
suffix: &OsStr,
random_len: usize,
- mut f: F,
-) -> io::Result<R>
-where
- F: FnMut(PathBuf) -> io::Result<R>,
-{
+ mut f: impl FnMut(PathBuf) -> io::Result<R>,
+) -> io::Result<R> {
let num_retries = if random_len != 0 {
crate::NUM_RETRIES
} else {