Skip to content

Commit 4688033

Browse files
committed
clean up tempfile module and rm FIXME
This removes the FIXME suggesting that mkdtemp should rely on the default umask, because that would make it unusable for making a secure work area in a world writable directory (have to assume that other users have created files, directories, hard links, etc. in your directory). The POSIX mkdtemp function creates a directory with 700 permissions to avoid this problem.
1 parent 989667e commit 4688033

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/libstd/tempfile.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -19,26 +19,18 @@ use core::str;
1919

2020
pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
2121
let r = rand::Rng();
22-
let mut i = 0u;
23-
while (i < 1000u) {
24-
let p = tmpdir.push(r.gen_str(16u) +
25-
str::from_slice(suffix));
26-
if os::make_dir(&p, 0x1c0i32) { // FIXME: u+rwx (#2349)
22+
for 1000.times {
23+
let p = tmpdir.push(r.gen_str(16) + suffix);
24+
if os::make_dir(&p, 0x1c0) { // 700
2725
return Some(p);
2826
}
29-
i += 1u;
3027
}
31-
return None;
28+
None
3229
}
3330

3431
#[test]
3532
fn test_mkdtemp() {
36-
let r = mkdtemp(&Path("."), "foobar");
37-
match r {
38-
Some(ref p) => {
39-
os::remove_dir(p);
40-
assert(str::ends_with(p.to_str(), "foobar"));
41-
}
42-
_ => assert(false)
43-
}
33+
let p = mkdtemp(&Path("."), "foobar").unwrap();
34+
os::remove_dir(&p);
35+
assert str::ends_with(p.to_str(), "foobar");
4436
}

0 commit comments

Comments
 (0)