Skip to content

Commit 042532f

Browse files
committed
---
yaml --- r: 55202 b: refs/heads/snap-stage3 c: bfccfdc h: refs/heads/master v: v3
1 parent 24ae961 commit 042532f

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 17ca13651a2bc6533413d80eb8941e5ddb20820e
4+
refs/heads/snap-stage3: bfccfdc78065752079a3863db19ca7148ade3e6f
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/os.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,36 @@ pub fn change_dir(p: &Path) -> bool {
818818
}
819819
}
820820
821+
/// Changes the current working directory to the specified
822+
/// path while acquiring a global lock, then calls `action`.
823+
/// If the change is successful, releases the lock and restores the
824+
/// CWD to what it was before, returning true.
825+
/// Returns false if the directory doesn't exist or if the directory change
826+
/// is otherwise unsuccessful.
827+
pub fn change_dir_locked(p: &Path, action: &fn()) -> bool {
828+
use unstable::global::global_data_clone_create;
829+
use unstable::{Exclusive, exclusive};
830+
831+
fn key(_: Exclusive<()>) { }
832+
833+
let result = unsafe {
834+
global_data_clone_create(key, || {
835+
~exclusive(())
836+
})
837+
};
838+
839+
do result.with_imm() |_| {
840+
let old_dir = os::getcwd();
841+
if change_dir(p) {
842+
action();
843+
change_dir(&old_dir)
844+
}
845+
else {
846+
false
847+
}
848+
}
849+
}
850+
821851
/// Copies a file from one location to another
822852
pub fn copy_file(from: &Path, to: &Path) -> bool {
823853
return do_copy_file(from, to);

branches/snap-stage3/src/libstd/tempfile.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ mod tests {
4242
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
4343
use core::os;
4444

45-
let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel");
46-
os::change_dir(&root);
47-
let path = Path("frob");
48-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
49-
assert!(os::path_is_dir(&path));
50-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
51-
assert!(os::path_is_dir(&path));
45+
let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel").
46+
expect("recursive_mkdir_rel");
47+
assert!(do os::change_dir_locked(&root) {
48+
let path = Path("frob");
49+
debug!("recursive_mkdir_rel: Making: %s in cwd %s [%?]", path.to_str(),
50+
os::getcwd().to_str(),
51+
os::path_exists(&path));
52+
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
53+
assert!(os::path_is_dir(&path));
54+
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
55+
assert!(os::path_is_dir(&path));
56+
});
5257
}
5358

5459
#[test]
@@ -67,18 +72,21 @@ mod tests {
6772
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
6873
use core::os;
6974

70-
let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel_2");
71-
os::change_dir(&root);
72-
let path = Path("./frob/baz");
73-
debug!("...Making: %s in cwd %s", path.to_str(), os::getcwd().to_str());
74-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
75-
assert!(os::path_is_dir(&path));
76-
assert!(os::path_is_dir(&path.pop()));
77-
let path2 = Path("quux/blat");
78-
debug!("Making: %s in cwd %s", path2.to_str(), os::getcwd().to_str());
79-
assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
80-
assert!(os::path_is_dir(&path2));
81-
assert!(os::path_is_dir(&path2.pop()));
75+
let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel_2").
76+
expect("recursive_mkdir_rel_2");
77+
assert!(do os::change_dir_locked(&root) {
78+
let path = Path("./frob/baz");
79+
debug!("recursive_mkdir_rel_2: Making: %s in cwd %s [%?]", path.to_str(),
80+
os::getcwd().to_str(), os::path_exists(&path));
81+
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
82+
assert!(os::path_is_dir(&path));
83+
assert!(os::path_is_dir(&path.pop()));
84+
let path2 = Path("quux/blat");
85+
debug!("recursive_mkdir_rel_2: Making: %s in cwd %s", path2.to_str(),
86+
os::getcwd().to_str());
87+
assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
88+
assert!(os::path_is_dir(&path2));
89+
assert!(os::path_is_dir(&path2.pop()));
90+
});
8291
}
83-
84-
}
92+
}

0 commit comments

Comments
 (0)