From ea140702a5e82b337b790b8e7a37bdbe31ed73e9 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 13 Nov 2016 20:25:20 -0700 Subject: Avoid TempDir::into_path(), because it doesn't cleanup on Drop --- src/unistd.rs | 8 ++++---- test/test_unistd.rs | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/unistd.rs b/src/unistd.rs index e97bcdb9..68a22ea1 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -262,12 +262,12 @@ pub fn chdir(path: &P) -> Result<()> { /// use tempdir::TempDir; /// /// fn main() { -/// let mut tmp_dir = TempDir::new("test_mkdir").unwrap().into_path(); -/// tmp_dir.push("new_dir"); +/// let tmp_dir1 = TempDir::new("test_mkdir").unwrap(); +/// let tmp_dir2 = tmp_dir1.path().join("new_dir"); /// /// // create new directory and give read, write and execute rights to the owner -/// match unistd::mkdir(&tmp_dir, stat::S_IRWXU) { -/// Ok(_) => println!("created {:?}", tmp_dir), +/// match unistd::mkdir(&tmp_dir2, stat::S_IRWXU) { +/// Ok(_) => println!("created {:?}", tmp_dir2), /// Err(err) => println!("Error creating directory: {}", err), /// } /// } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 856693f6..d281f9b2 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -143,19 +143,21 @@ macro_rules! execve_test_factory( #[test] fn test_getcwd() { - let mut tmp_dir = TempDir::new("test_getcwd").unwrap().into_path(); - assert!(chdir(tmp_dir.as_path()).is_ok()); + let tmp_dir = TempDir::new("test_getcwd").unwrap(); + assert!(chdir(tmp_dir.path()).is_ok()); assert_eq!(getcwd().unwrap(), current_dir().unwrap()); // make path 500 chars longer so that buffer doubling in getcwd kicks in. // Note: One path cannot be longer than 255 bytes (NAME_MAX) // whole path cannot be longer than PATH_MAX (usually 4096 on linux, 1024 on macos) + let mut inner_tmp_dir = tmp_dir.path().to_path_buf(); for _ in 0..5 { let newdir = iter::repeat("a").take(100).collect::(); - tmp_dir.push(newdir); - assert!(mkdir(tmp_dir.as_path(), stat::S_IRWXU).is_ok()); + //inner_tmp_dir = inner_tmp_dir.join(newdir).path(); + inner_tmp_dir.push(newdir); + assert!(mkdir(inner_tmp_dir.as_path(), stat::S_IRWXU).is_ok()); } - assert!(chdir(tmp_dir.as_path()).is_ok()); + assert!(chdir(inner_tmp_dir.as_path()).is_ok()); assert_eq!(getcwd().unwrap(), current_dir().unwrap()); } -- cgit v1.2.3