Skip to content

Commit a9f630e

Browse files
committed
Auto merge of #465 - asomers:cleanup, r=posborne
Avoid TempDir::into_path(), because it doesn't cleanup on Drop
2 parents 853a7db + ea14070 commit a9f630e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/unistd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
262262
/// use tempdir::TempDir;
263263
///
264264
/// fn main() {
265-
/// let mut tmp_dir = TempDir::new("test_mkdir").unwrap().into_path();
266-
/// tmp_dir.push("new_dir");
265+
/// let tmp_dir1 = TempDir::new("test_mkdir").unwrap();
266+
/// let tmp_dir2 = tmp_dir1.path().join("new_dir");
267267
///
268268
/// // create new directory and give read, write and execute rights to the owner
269-
/// match unistd::mkdir(&tmp_dir, stat::S_IRWXU) {
270-
/// Ok(_) => println!("created {:?}", tmp_dir),
269+
/// match unistd::mkdir(&tmp_dir2, stat::S_IRWXU) {
270+
/// Ok(_) => println!("created {:?}", tmp_dir2),
271271
/// Err(err) => println!("Error creating directory: {}", err),
272272
/// }
273273
/// }

test/test_unistd.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,21 @@ macro_rules! execve_test_factory(
143143

144144
#[test]
145145
fn test_getcwd() {
146-
let mut tmp_dir = TempDir::new("test_getcwd").unwrap().into_path();
147-
assert!(chdir(tmp_dir.as_path()).is_ok());
146+
let tmp_dir = TempDir::new("test_getcwd").unwrap();
147+
assert!(chdir(tmp_dir.path()).is_ok());
148148
assert_eq!(getcwd().unwrap(), current_dir().unwrap());
149149

150150
// make path 500 chars longer so that buffer doubling in getcwd kicks in.
151151
// Note: One path cannot be longer than 255 bytes (NAME_MAX)
152152
// whole path cannot be longer than PATH_MAX (usually 4096 on linux, 1024 on macos)
153+
let mut inner_tmp_dir = tmp_dir.path().to_path_buf();
153154
for _ in 0..5 {
154155
let newdir = iter::repeat("a").take(100).collect::<String>();
155-
tmp_dir.push(newdir);
156-
assert!(mkdir(tmp_dir.as_path(), stat::S_IRWXU).is_ok());
156+
//inner_tmp_dir = inner_tmp_dir.join(newdir).path();
157+
inner_tmp_dir.push(newdir);
158+
assert!(mkdir(inner_tmp_dir.as_path(), stat::S_IRWXU).is_ok());
157159
}
158-
assert!(chdir(tmp_dir.as_path()).is_ok());
160+
assert!(chdir(inner_tmp_dir.as_path()).is_ok());
159161
assert_eq!(getcwd().unwrap(), current_dir().unwrap());
160162
}
161163

0 commit comments

Comments
 (0)