summaryrefslogtreecommitdiffstats
path: root/vendor/tempfile
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tempfile')
-rw-r--r--vendor/tempfile/.cargo-checksum.json2
-rw-r--r--vendor/tempfile/CHANGELOG.md10
-rw-r--r--vendor/tempfile/Cargo.toml2
-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
-rw-r--r--vendor/tempfile/tests/namedtempfile.rs7
-rw-r--r--vendor/tempfile/tests/spooled.rs32
-rw-r--r--vendor/tempfile/tests/tempdir.rs139
9 files changed, 166 insertions, 137 deletions
diff --git a/vendor/tempfile/.cargo-checksum.json b/vendor/tempfile/.cargo-checksum.json
index 7646d633a..67b780b7b 100644
--- a/vendor/tempfile/.cargo-checksum.json
+++ b/vendor/tempfile/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CHANGELOG.md":"c635005c3d61efb9223ce7bbdd7412a1e8fe79b6bf10a13e654d0b10afe36137","Cargo.toml":"8b7e3458c3908ccd068584d098c4e6bd74de0f0a43851c14dfc6cc021ab1430c","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"8b427f5bc501764575e52ba4f9d95673cf8f6d80a86d0d06599852e1a9a20a36","README.md":"972f1c35ec653943e067fd2c3d09e78f593b2e9e1eafd5b9668bf3653513de3e","src/dir.rs":"b555ff1d4ace32c5ce9deba77113b95969145bba16e43a88efe22d8f3ab049e5","src/error.rs":"cc7d8eace0fff11cb342158d2885d5637bfb14b24ef30755e808554772039c5f","src/file/imp/mod.rs":"f6da9fcd93f11889670a251fdd8231b5f4614e5a971b7b183f52b44af68568d5","src/file/imp/other.rs":"501cd1b444a5821127ea831fc8018706148f2d9f47c478f502b069963a42a2c7","src/file/imp/unix.rs":"3e7dbc57a9663a815b5cc484c2fdb3a4321be3851ecedc4b9c8e918a3e958c47","src/file/imp/windows.rs":"fa4211087c36290064de9a41b5e533e4e8c24a10fb8f8908835a67e00555c06e","src/file/mod.rs":"4a9f13afabe1718a20a168d07160a000b23f043edc4c8966b349b8a9fa23cd98","src/lib.rs":"6303e7470c680ad785f32eb717de2e512b88c2c5da0e1684e3704471fabd7398","src/spooled.rs":"de848218bb7c0733d9c46e337564137673c95f5a6cf9f6bb28baf218b2503247","src/util.rs":"63737b9180cb769c1fcac56f1fa928221ae41a8917872d3e878d0a915e877710","tests/namedtempfile.rs":"a37c82908ed5df89cd2800c55abadf631d04caa55f09c966c8d1fd7a559a0ba6","tests/spooled.rs":"29e797d486d867cb6ac46d4cf126eb5868a069a4070c3f50ffa02fbb0b887934","tests/tempdir.rs":"abf08594f9d9ddc6c417de413bf63f9026150378af319d857e5ac8578f3fb665","tests/tempfile.rs":"9a2f8142151a6aa2fd047aa3749f9982ece4b080a3ace0d3c58d6bdb3f883c81"},"package":"5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998"} \ No newline at end of file
+{"files":{"CHANGELOG.md":"14cb935001b72d1da431865d0e618b58ca962cc17c8be6bcd9cf4e1699f58b7d","Cargo.toml":"285d4565218bd4a8e5d36cb9b12ece4b8bb9c91d3357e75708acb0ca2f414b49","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"8b427f5bc501764575e52ba4f9d95673cf8f6d80a86d0d06599852e1a9a20a36","README.md":"972f1c35ec653943e067fd2c3d09e78f593b2e9e1eafd5b9668bf3653513de3e","src/dir.rs":"3b515f42feb934ba83ba56d506116e5e932c6b863b764fd61d26994eff28700a","src/error.rs":"cc7d8eace0fff11cb342158d2885d5637bfb14b24ef30755e808554772039c5f","src/file/imp/mod.rs":"f6da9fcd93f11889670a251fdd8231b5f4614e5a971b7b183f52b44af68568d5","src/file/imp/other.rs":"501cd1b444a5821127ea831fc8018706148f2d9f47c478f502b069963a42a2c7","src/file/imp/unix.rs":"0fa63a8b831947fdc7307e889d129adef6f47b19965b963a5e25d70cb3106e62","src/file/imp/windows.rs":"fa4211087c36290064de9a41b5e533e4e8c24a10fb8f8908835a67e00555c06e","src/file/mod.rs":"f417e0e8637116e50de201581b1dfe8feb8dee30f71c5bb9dbcd95603094cb49","src/lib.rs":"6303e7470c680ad785f32eb717de2e512b88c2c5da0e1684e3704471fabd7398","src/spooled.rs":"de848218bb7c0733d9c46e337564137673c95f5a6cf9f6bb28baf218b2503247","src/util.rs":"63737b9180cb769c1fcac56f1fa928221ae41a8917872d3e878d0a915e877710","tests/namedtempfile.rs":"87dd6a8bba2fdd77418ec2b50b8aec5e26d05a2f780182b4e9ff464b3404d47c","tests/spooled.rs":"a97e96404dc5136421ac027b965070c0d5b44c93d06d456e12dc85f81755d064","tests/tempdir.rs":"f5a86f56df6bb60aa5dfa136ce75f8d0f29c2e87546dccfe1fb680d209be525e","tests/tempfile.rs":"9a2f8142151a6aa2fd047aa3749f9982ece4b080a3ace0d3c58d6bdb3f883c81"},"package":"cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"} \ No newline at end of file
diff --git a/vendor/tempfile/CHANGELOG.md b/vendor/tempfile/CHANGELOG.md
index c9e4c9bc2..a3576e025 100644
--- a/vendor/tempfile/CHANGELOG.md
+++ b/vendor/tempfile/CHANGELOG.md
@@ -1,5 +1,15 @@
# Changelog
+## 3.8.0
+
+- Added `with_prefix` and `with_prefix_in` to `TempDir` and `NamedTempFile` to make it easier to create temporary files/directories with nice prefixes.
+- Misc cleanups.
+
+## 3.7.1
+
+- Tempfile builds on haiku again.
+- Under the hood, we've switched from the unlinkat/linkat syscalls to the regular unlink/link syscalls where possible.
+
## 3.7.0
BREAKING: This release updates the MSRV to 1.63. This isn't an API-breaking change (so no major
diff --git a/vendor/tempfile/Cargo.toml b/vendor/tempfile/Cargo.toml
index 88d46ebd5..42349a1ba 100644
--- a/vendor/tempfile/Cargo.toml
+++ b/vendor/tempfile/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.63"
name = "tempfile"
-version = "3.7.0"
+version = "3.8.0"
authors = [
"Steven Allen <steven@stebalien.com>",
"The Rust Project Developers",
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> {
diff --git a/vendor/tempfile/tests/namedtempfile.rs b/vendor/tempfile/tests/namedtempfile.rs
index 54396c3ac..4b940b6b8 100644
--- a/vendor/tempfile/tests/namedtempfile.rs
+++ b/vendor/tempfile/tests/namedtempfile.rs
@@ -12,6 +12,13 @@ fn exists<P: AsRef<Path>>(path: P) -> bool {
}
#[test]
+fn test_prefix() {
+ let tmpfile = NamedTempFile::with_prefix("prefix").unwrap();
+ let name = tmpfile.path().file_name().unwrap().to_str().unwrap();
+ assert!(name.starts_with("prefix"));
+}
+
+#[test]
fn test_basic() {
let mut tmpfile = NamedTempFile::new().unwrap();
write!(tmpfile, "abcde").unwrap();
diff --git a/vendor/tempfile/tests/spooled.rs b/vendor/tempfile/tests/spooled.rs
index 288d1e6ee..a3bcc03d8 100644
--- a/vendor/tempfile/tests/spooled.rs
+++ b/vendor/tempfile/tests/spooled.rs
@@ -10,7 +10,7 @@ fn test_automatic_rollover() {
let mut buf = Vec::new();
assert!(!t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 0);
+ assert_eq!(t.stream_position().unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
buf.clear();
@@ -24,7 +24,7 @@ fn test_automatic_rollover() {
assert_eq!(t.write(b"fghijklmno").unwrap(), 10);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 15);
+ assert_eq!(t.stream_position().unwrap(), 15);
assert!(t.is_rolled());
}
@@ -32,13 +32,13 @@ fn test_automatic_rollover() {
fn test_explicit_rollover() {
let mut t = SpooledTempFile::new(100);
assert_eq!(t.write(b"abcdefghijklmnopqrstuvwxyz").unwrap(), 26);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
+ assert_eq!(t.stream_position().unwrap(), 26);
assert!(!t.is_rolled());
// roll over explicitly
assert!(t.roll().is_ok());
assert!(t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
+ assert_eq!(t.stream_position().unwrap(), 26);
let mut buf = Vec::new();
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
@@ -48,7 +48,7 @@ fn test_explicit_rollover() {
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 26);
assert_eq!(buf.as_slice(), b"abcdefghijklmnopqrstuvwxyz");
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
+ assert_eq!(t.stream_position().unwrap(), 26);
}
// called by test_seek_{buffer, file}
@@ -56,7 +56,7 @@ fn test_explicit_rollover() {
fn test_seek(t: &mut SpooledTempFile) {
assert_eq!(t.write(b"abcdefghijklmnopqrstuvwxyz").unwrap(), 26);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.seek(SeekFrom::Current(-1)).unwrap(), 25);
assert_eq!(t.seek(SeekFrom::Current(1)).unwrap(), 26);
assert_eq!(t.seek(SeekFrom::Current(1)).unwrap(), 27);
@@ -110,7 +110,7 @@ fn test_seek_read(t: &mut SpooledTempFile) {
buf.clear();
// now we're at the end again
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
buf.clear();
@@ -122,7 +122,7 @@ fn test_seek_read(t: &mut SpooledTempFile) {
assert_eq!(buf, *b"fghij");
// read again from current spot
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
+ assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert!(t.read_exact(&mut buf).is_ok());
assert_eq!(buf, *b"klmno");
@@ -190,11 +190,11 @@ fn test_overwrite_and_extend_rollover() {
assert_eq!(t.write(b"abcdefghijklmno").unwrap(), 15);
assert!(!t.is_rolled());
assert_eq!(t.seek(SeekFrom::End(-5)).unwrap(), 10);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
+ assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert!(!t.is_rolled());
assert_eq!(t.write(b"0123456789)!@#$%^&*(").unwrap(), 20);
assert!(t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 30); // tell()
+ assert_eq!(t.stream_position().unwrap(), 30); // tell()
let mut buf = Vec::new();
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 30);
@@ -247,11 +247,11 @@ fn test_set_len(t: &mut SpooledTempFile) {
assert!(t.set_len(10).is_ok());
// position should not have moved
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
buf.clear();
// read whole thing
@@ -262,7 +262,7 @@ fn test_set_len(t: &mut SpooledTempFile) {
// set_len to expand beyond the end
assert!(t.set_len(40).is_ok());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
+ assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 40);
assert_eq!(
@@ -290,17 +290,17 @@ fn test_set_len_rollover() {
let mut t = spooled_tempfile(10);
assert_eq!(t.write(b"abcde").unwrap(), 5);
assert!(!t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
+ assert_eq!(t.stream_position().unwrap(), 5); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 5);
assert_eq!(buf.as_slice(), b"abcde");
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
+ assert_eq!(t.stream_position().unwrap(), 5); // tell()
buf.clear();
assert!(t.set_len(20).is_ok());
assert!(t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
+ assert_eq!(t.stream_position().unwrap(), 5); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 20);
assert_eq!(buf.as_slice(), b"abcde\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
diff --git a/vendor/tempfile/tests/tempdir.rs b/vendor/tempfile/tests/tempdir.rs
index de9723328..8ca7984ac 100644
--- a/vendor/tempfile/tests/tempdir.rs
+++ b/vendor/tempfile/tests/tempdir.rs
@@ -18,32 +18,9 @@ use std::thread;
use tempfile::{Builder, TempDir};
-macro_rules! t {
- ($e:expr) => {
- match $e {
- Ok(n) => n,
- Err(e) => panic!("error: {}", e),
- }
- };
-}
-
-trait PathExt {
- fn exists(&self) -> bool;
- fn is_dir(&self) -> bool;
-}
-
-impl PathExt for Path {
- fn exists(&self) -> bool {
- fs::metadata(self).is_ok()
- }
- fn is_dir(&self) -> bool {
- fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
- }
-}
-
fn test_tempdir() {
let path = {
- let p = t!(Builder::new().prefix("foobar").tempdir_in(&Path::new(".")));
+ let p = Builder::new().prefix("foobar").tempdir_in(".").unwrap();
let p = p.path();
assert!(p.to_str().unwrap().contains("foobar"));
p.to_path_buf()
@@ -51,7 +28,12 @@ fn test_tempdir() {
assert!(!path.exists());
}
-#[test]
+fn test_prefix() {
+ let tmpfile = TempDir::with_prefix_in("prefix", ".").unwrap();
+ let name = tmpfile.path().file_name().unwrap().to_str().unwrap();
+ assert!(name.starts_with("prefix"));
+}
+
fn test_customnamed() {
let tmpfile = Builder::new()
.prefix("prefix")
@@ -68,7 +50,7 @@ fn test_customnamed() {
fn test_rm_tempdir() {
let (tx, rx) = channel();
let f = move || {
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
tx.send(tmp.path().to_path_buf()).unwrap();
panic!("panic to unwind past `tmp`");
};
@@ -76,7 +58,7 @@ fn test_rm_tempdir() {
let path = rx.recv().unwrap();
assert!(!path.exists());
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
let path = tmp.path().to_path_buf();
let f = move || {
let _tmp = tmp;
@@ -87,7 +69,7 @@ fn test_rm_tempdir() {
let path;
{
- let f = move || t!(TempDir::new());
+ let f = move || TempDir::new().unwrap();
let tmp = thread::spawn(f).join().unwrap();
path = tmp.path().to_path_buf();
@@ -97,31 +79,31 @@ fn test_rm_tempdir() {
let path;
{
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
path = tmp.into_path();
}
assert!(path.exists());
- t!(fs::remove_dir_all(&path));
+ fs::remove_dir_all(&path).unwrap();
assert!(!path.exists());
}
fn test_rm_tempdir_close() {
let (tx, rx) = channel();
let f = move || {
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
tx.send(tmp.path().to_path_buf()).unwrap();
- t!(tmp.close());
+ tmp.close().unwrap();
panic!("panic when unwinding past `tmp`");
};
let _ = thread::spawn(f).join();
let path = rx.recv().unwrap();
assert!(!path.exists());
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
let path = tmp.path().to_path_buf();
let f = move || {
let tmp = tmp;
- t!(tmp.close());
+ tmp.close().unwrap();
panic!("panic when unwinding past `tmp`");
};
let _ = thread::spawn(f).join();
@@ -129,96 +111,31 @@ fn test_rm_tempdir_close() {
let path;
{
- let f = move || t!(TempDir::new());
+ let f = move || TempDir::new().unwrap();
let tmp = thread::spawn(f).join().unwrap();
path = tmp.path().to_path_buf();
assert!(path.exists());
- t!(tmp.close());
+ tmp.close().unwrap();
}
assert!(!path.exists());
let path;
{
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
path = tmp.into_path();
}
assert!(path.exists());
- t!(fs::remove_dir_all(&path));
+ fs::remove_dir_all(&path).unwrap();
assert!(!path.exists());
}
-// Ideally these would be in std::os but then core would need
-// to depend on std
-fn recursive_mkdir_rel() {
- let path = Path::new("frob");
- let cwd = env::current_dir().unwrap();
- println!(
- "recursive_mkdir_rel: Making: {} in cwd {} [{}]",
- path.display(),
- cwd.display(),
- path.exists()
- );
- t!(fs::create_dir(&path));
- assert!(path.is_dir());
- t!(fs::create_dir_all(&path));
- assert!(path.is_dir());
-}
-
-fn recursive_mkdir_dot() {
- let dot = Path::new(".");
- t!(fs::create_dir_all(&dot));
- let dotdot = Path::new("..");
- t!(fs::create_dir_all(&dotdot));
-}
-
-fn recursive_mkdir_rel_2() {
- let path = Path::new("./frob/baz");
- let cwd = env::current_dir().unwrap();
- println!(
- "recursive_mkdir_rel_2: Making: {} in cwd {} [{}]",
- path.display(),
- cwd.display(),
- path.exists()
- );
- t!(fs::create_dir_all(&path));
- assert!(path.is_dir());
- assert!(path.parent().unwrap().is_dir());
- let path2 = Path::new("quux/blat");
- println!(
- "recursive_mkdir_rel_2: Making: {} in cwd {}",
- path2.display(),
- cwd.display()
- );
- t!(fs::create_dir("quux"));
- t!(fs::create_dir_all(&path2));
- assert!(path2.is_dir());
- assert!(path2.parent().unwrap().is_dir());
-}
-
-// Ideally this would be in core, but needs TempFile
-pub fn test_remove_dir_all_ok() {
- let tmpdir = t!(TempDir::new());
- let tmpdir = tmpdir.path();
- let root = tmpdir.join("foo");
-
- println!("making {}", root.display());
- t!(fs::create_dir(&root));
- t!(fs::create_dir(&root.join("foo")));
- t!(fs::create_dir(&root.join("foo").join("bar")));
- t!(fs::create_dir(&root.join("foo").join("bar").join("blat")));
- t!(fs::remove_dir_all(&root));
- assert!(!root.exists());
- assert!(!root.join("bar").exists());
- assert!(!root.join("bar").join("blat").exists());
-}
-
-pub fn dont_double_panic() {
+fn dont_double_panic() {
let r: Result<(), _> = thread::spawn(move || {
let tmpdir = TempDir::new().unwrap();
// Remove the temporary directory so that TempDir sees
// an error on drop
- t!(fs::remove_dir(tmpdir.path()));
+ fs::remove_dir(tmpdir.path()).unwrap();
// Panic. If TempDir panics *again* due to the rmdir
// error then the process will abort.
panic!();
@@ -231,14 +148,14 @@ fn in_tmpdir<F>(f: F)
where
F: FnOnce(),
{
- let tmpdir = t!(TempDir::new());
+ let tmpdir = TempDir::new().unwrap();
assert!(env::set_current_dir(tmpdir.path()).is_ok());
f();
}
-pub fn pass_as_asref_path() {
- let tempdir = t!(TempDir::new());
+fn pass_as_asref_path() {
+ let tempdir = TempDir::new().unwrap();
takes_asref_path(&tempdir);
fn takes_asref_path<T: AsRef<Path>>(path: T) {
@@ -250,12 +167,10 @@ pub fn pass_as_asref_path() {
#[test]
fn main() {
in_tmpdir(test_tempdir);
+ in_tmpdir(test_prefix);
+ in_tmpdir(test_customnamed);
in_tmpdir(test_rm_tempdir);
in_tmpdir(test_rm_tempdir_close);
- in_tmpdir(recursive_mkdir_rel);
- in_tmpdir(recursive_mkdir_dot);
- in_tmpdir(recursive_mkdir_rel_2);
- in_tmpdir(test_remove_dir_all_ok);
in_tmpdir(dont_double_panic);
in_tmpdir(pass_as_asref_path);
}