diff options
author | Homu <homu@barosl.com> | 2016-11-14 16:19:54 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-11-14 16:19:54 +0900 |
commit | a9f630ed00ec9d98dfdd0d84127c8f44ca92bcb9 (patch) | |
tree | ab48c9bbb619775cb7e94301a170b80b551976c1 | |
parent | 853a7db630af188509dd2be1c542eb8d498818b8 (diff) | |
parent | ea140702a5e82b337b790b8e7a37bdbe31ed73e9 (diff) | |
download | nix-a9f630ed00ec9d98dfdd0d84127c8f44ca92bcb9.zip |
Auto merge of #465 - asomers:cleanup, r=posborne
Avoid TempDir::into_path(), because it doesn't cleanup on Drop
-rw-r--r-- | src/unistd.rs | 8 | ||||
-rw-r--r-- | 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<P: ?Sized + NixPath>(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::<String>(); - 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()); } |