auto merge of #9802 : ben0x539/rust/mkdtemp-raii, r=alexcrichton
this incidentally stops `make check` from leaving directories in `/tmp` (Closes #9764)
This commit is contained in:
commit
93a08f49fa
@ -15,17 +15,63 @@ use std::os;
|
||||
use std::rand::Rng;
|
||||
use std::rand;
|
||||
|
||||
/// Attempts to make a temporary directory inside of `tmpdir` whose name will
|
||||
/// have the suffix `suffix`. If no directory can be created, None is returned.
|
||||
pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
|
||||
let mut r = rand::rng();
|
||||
for _ in range(0u, 1000) {
|
||||
let p = tmpdir.push(r.gen_ascii_str(16) + suffix);
|
||||
if os::make_dir(&p, 0x1c0) { // 700
|
||||
return Some(p);
|
||||
/// A wrapper for a path to temporary directory implementing automatic
|
||||
/// scope-pased deletion.
|
||||
pub struct TempDir {
|
||||
priv path: Option<Path>
|
||||
}
|
||||
|
||||
impl TempDir {
|
||||
/// Attempts to make a temporary directory inside of `tmpdir` whose name
|
||||
/// will have the suffix `suffix`. The directory will be automatically
|
||||
/// deleted once the returned wrapper is destroyed.
|
||||
///
|
||||
/// If no directory can be created, None is returned.
|
||||
pub fn new_in(tmpdir: &Path, suffix: &str) -> Option<TempDir> {
|
||||
if !tmpdir.is_absolute() {
|
||||
let abs_tmpdir = os::make_absolute(tmpdir);
|
||||
return TempDir::new_in(&abs_tmpdir, suffix);
|
||||
}
|
||||
|
||||
let mut r = rand::rng();
|
||||
for _ in range(0u, 1000) {
|
||||
let p = tmpdir.push(r.gen_ascii_str(16) + suffix);
|
||||
if os::make_dir(&p, 0x1c0) { // 700
|
||||
return Some(TempDir { path: Some(p) });
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Attempts to make a temporary directory inside of `os::tmpdir()` whose
|
||||
/// name will have the suffix `suffix`. The directory will be automatically
|
||||
/// deleted once the returned wrapper is destroyed.
|
||||
///
|
||||
/// If no directory can be created, None is returned.
|
||||
pub fn new(suffix: &str) -> Option<TempDir> {
|
||||
TempDir::new_in(&os::tmpdir(), suffix)
|
||||
}
|
||||
|
||||
/// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper.
|
||||
/// This discards the wrapper so that the automatic deletion of the
|
||||
/// temporary directory is prevented.
|
||||
pub fn unwrap(self) -> Path {
|
||||
let mut tmpdir = self;
|
||||
tmpdir.path.take_unwrap()
|
||||
}
|
||||
|
||||
/// Access the wrapped `std::path::Path` to the temporary directory.
|
||||
pub fn path<'a>(&'a self) -> &'a Path {
|
||||
self.path.get_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TempDir {
|
||||
fn drop(&mut self) {
|
||||
for path in self.path.iter() {
|
||||
os::remove_dir_recursive(path);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
// the tests for this module need to change the path using change_dir,
|
||||
|
@ -1148,8 +1148,7 @@ mod tests {
|
||||
use test::{TestOpts, run_test};
|
||||
|
||||
use std::comm::{stream, SharedChan};
|
||||
use tempfile;
|
||||
use std::os;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
pub fn do_not_run_ignored_tests() {
|
||||
@ -1392,9 +1391,8 @@ mod tests {
|
||||
|
||||
pub fn ratchet_test() {
|
||||
|
||||
let dpth = tempfile::mkdtemp(&os::tmpdir(),
|
||||
"test-ratchet").expect("missing test for ratchet");
|
||||
let pth = dpth.push("ratchet.json");
|
||||
let dpth = TempDir::new("test-ratchet").expect("missing test for ratchet");
|
||||
let pth = dpth.path().push("ratchet.json");
|
||||
|
||||
let mut m1 = MetricMap::new();
|
||||
m1.insert_metric("runtime", 1000.0, 2.0);
|
||||
@ -1432,7 +1430,5 @@ mod tests {
|
||||
assert_eq!(m4.len(), 2);
|
||||
assert_eq!(*(m4.find(&~"runtime").unwrap()), Metric { value: 1100.0, noise: 2.0 });
|
||||
assert_eq!(*(m4.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 });
|
||||
|
||||
os::remove_dir_recursive(&dpth);
|
||||
}
|
||||
}
|
||||
|
@ -239,9 +239,6 @@ impl PkgSrc {
|
||||
pub fn fetch_git(local: &Path, pkgid: &PkgId) -> Option<Path> {
|
||||
use conditions::git_checkout_failed::cond;
|
||||
|
||||
// We use a temporary directory because if the git clone fails,
|
||||
// it creates the target directory anyway and doesn't delete it
|
||||
|
||||
debug2!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}",
|
||||
pkgid.to_str(), pkgid.path.to_str(),
|
||||
os::getcwd().to_str(),
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
use std::{io, os, run, str};
|
||||
use std::run::{ProcessOutput, ProcessOptions, Process};
|
||||
use extra::tempfile;
|
||||
use extra::tempfile::TempDir;
|
||||
use version::*;
|
||||
use path_util::chmod_read_only;
|
||||
|
||||
@ -22,14 +22,6 @@ use path_util::chmod_read_only;
|
||||
/// directory (that the callee may use, for example, to check out remote sources into).
|
||||
/// Returns `CheckedOutSources` if the clone succeeded.
|
||||
pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult {
|
||||
use conditions::failed_to_create_temp_dir::cond;
|
||||
|
||||
let scratch_dir = tempfile::mkdtemp(&os::tmpdir(), "rustpkg");
|
||||
let clone_target = match scratch_dir {
|
||||
Some(d) => d.push("rustpkg_temp"),
|
||||
None => cond.raise(~"Failed to create temporary directory for fetching git sources")
|
||||
};
|
||||
|
||||
if os::path_exists(source) {
|
||||
debug2!("{} exists locally! Cloning it into {}",
|
||||
source.to_str(), target.to_str());
|
||||
@ -77,6 +69,14 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
|
||||
}
|
||||
CheckedOutSources
|
||||
} else {
|
||||
use conditions::failed_to_create_temp_dir::cond;
|
||||
|
||||
let scratch_dir = TempDir::new("rustpkg");
|
||||
let clone_target = match scratch_dir {
|
||||
Some(d) => d.unwrap().push("rustpkg_temp"),
|
||||
None => cond.raise(~"Failed to create temporary directory for fetching git sources")
|
||||
};
|
||||
|
||||
DirToUse(clone_target)
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@ extern mod std;
|
||||
|
||||
use extra::semver;
|
||||
use std::{char, os, result, run, str};
|
||||
use extra::tempfile::mkdtemp;
|
||||
use extra::tempfile::TempDir;
|
||||
use path_util::rust_path;
|
||||
|
||||
#[deriving(Clone)]
|
||||
@ -132,8 +132,9 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
|
||||
/// otherwise, `None`
|
||||
pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
|
||||
if is_url_like(remote_path) {
|
||||
let tmp_dir = mkdtemp(&os::tmpdir(),
|
||||
"test").expect("try_getting_version: couldn't create temp dir");
|
||||
let tmp_dir = TempDir::new("test");
|
||||
let tmp_dir = tmp_dir.expect("try_getting_version: couldn't create temp dir");
|
||||
let tmp_dir = tmp_dir.path();
|
||||
debug2!("(to get version) executing \\{git clone https://{} {}\\}",
|
||||
remote_path.to_str(),
|
||||
tmp_dir.to_str());
|
||||
|
@ -13,19 +13,11 @@
|
||||
extern mod extra;
|
||||
|
||||
use extra::glob::glob;
|
||||
use extra::tempfile;
|
||||
use extra::tempfile::TempDir;
|
||||
use std::unstable::finally::Finally;
|
||||
use std::{io, os, unstable};
|
||||
|
||||
pub fn main() {
|
||||
fn change_then_remove(p: &Path, f: &fn()) {
|
||||
assert!(os::change_dir(p));
|
||||
|
||||
do f.finally {
|
||||
os::remove_dir_recursive(p);
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_file(path: &str, directory: bool) {
|
||||
if directory {
|
||||
os::make_dir(&Path(path), 0xFFFF);
|
||||
@ -42,162 +34,161 @@ pub fn main() {
|
||||
glob(pattern).collect()
|
||||
}
|
||||
|
||||
let root = tempfile::mkdtemp(&os::tmpdir(), "glob-tests");
|
||||
let root = TempDir::new("glob-tests");
|
||||
let root = root.expect("Should have created a temp directory");
|
||||
assert!(os::change_dir(root.path()));
|
||||
|
||||
do change_then_remove(&root) {
|
||||
mk_file("aaa", true);
|
||||
mk_file("aaa/apple", true);
|
||||
mk_file("aaa/orange", true);
|
||||
mk_file("aaa/tomato", true);
|
||||
mk_file("aaa/tomato/tomato.txt", false);
|
||||
mk_file("aaa/tomato/tomoto.txt", false);
|
||||
mk_file("bbb", true);
|
||||
mk_file("bbb/specials", true);
|
||||
mk_file("bbb/specials/!", false);
|
||||
mk_file("aaa", true);
|
||||
mk_file("aaa/apple", true);
|
||||
mk_file("aaa/orange", true);
|
||||
mk_file("aaa/tomato", true);
|
||||
mk_file("aaa/tomato/tomato.txt", false);
|
||||
mk_file("aaa/tomato/tomoto.txt", false);
|
||||
mk_file("bbb", true);
|
||||
mk_file("bbb/specials", true);
|
||||
mk_file("bbb/specials/!", false);
|
||||
|
||||
// windows does not allow `*` or `?` characters to exist in filenames
|
||||
if os::consts::FAMILY != os::consts::windows::FAMILY {
|
||||
mk_file("bbb/specials/*", false);
|
||||
mk_file("bbb/specials/?", false);
|
||||
}
|
||||
// windows does not allow `*` or `?` characters to exist in filenames
|
||||
if os::consts::FAMILY != os::consts::windows::FAMILY {
|
||||
mk_file("bbb/specials/*", false);
|
||||
mk_file("bbb/specials/?", false);
|
||||
}
|
||||
|
||||
mk_file("bbb/specials/[", false);
|
||||
mk_file("bbb/specials/]", false);
|
||||
mk_file("ccc", true);
|
||||
mk_file("xyz", true);
|
||||
mk_file("xyz/x", false);
|
||||
mk_file("xyz/y", false);
|
||||
mk_file("xyz/z", false);
|
||||
mk_file("bbb/specials/[", false);
|
||||
mk_file("bbb/specials/]", false);
|
||||
mk_file("ccc", true);
|
||||
mk_file("xyz", true);
|
||||
mk_file("xyz/x", false);
|
||||
mk_file("xyz/y", false);
|
||||
mk_file("xyz/z", false);
|
||||
|
||||
assert_eq!(glob_vec(""), ~[]);
|
||||
assert_eq!(glob_vec("."), ~[]);
|
||||
assert_eq!(glob_vec(".."), ~[]);
|
||||
assert_eq!(glob_vec(""), ~[]);
|
||||
assert_eq!(glob_vec("."), ~[]);
|
||||
assert_eq!(glob_vec(".."), ~[]);
|
||||
|
||||
assert_eq!(glob_vec("aaa"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aaa/"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a"), ~[]);
|
||||
assert_eq!(glob_vec("aa"), ~[]);
|
||||
assert_eq!(glob_vec("aaaa"), ~[]);
|
||||
assert_eq!(glob_vec("aaa"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aaa/"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a"), ~[]);
|
||||
assert_eq!(glob_vec("aa"), ~[]);
|
||||
assert_eq!(glob_vec("aaaa"), ~[]);
|
||||
|
||||
assert_eq!(glob_vec("aaa/apple"), ~[abs_path("aaa/apple")]);
|
||||
assert_eq!(glob_vec("aaa/apple/nope"), ~[]);
|
||||
assert_eq!(glob_vec("aaa/apple"), ~[abs_path("aaa/apple")]);
|
||||
assert_eq!(glob_vec("aaa/apple/nope"), ~[]);
|
||||
|
||||
// windows should support both / and \ as directory separators
|
||||
if os::consts::FAMILY == os::consts::windows::FAMILY {
|
||||
assert_eq!(glob_vec("aaa\\apple"), ~[abs_path("aaa/apple")]);
|
||||
}
|
||||
// windows should support both / and \ as directory separators
|
||||
if os::consts::FAMILY == os::consts::windows::FAMILY {
|
||||
assert_eq!(glob_vec("aaa\\apple"), ~[abs_path("aaa/apple")]);
|
||||
}
|
||||
|
||||
assert_eq!(glob_vec("???/"), ~[
|
||||
abs_path("aaa"),
|
||||
abs_path("bbb"),
|
||||
abs_path("ccc"),
|
||||
abs_path("xyz")]);
|
||||
assert_eq!(glob_vec("???/"), ~[
|
||||
abs_path("aaa"),
|
||||
abs_path("bbb"),
|
||||
abs_path("ccc"),
|
||||
abs_path("xyz")]);
|
||||
|
||||
assert_eq!(glob_vec("aaa/tomato/tom?to.txt"), ~[
|
||||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")]);
|
||||
assert_eq!(glob_vec("aaa/tomato/tom?to.txt"), ~[
|
||||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")]);
|
||||
|
||||
assert_eq!(glob_vec("xyz/?"), ~[
|
||||
abs_path("xyz/x"),
|
||||
abs_path("xyz/y"),
|
||||
abs_path("xyz/z")]);
|
||||
assert_eq!(glob_vec("xyz/?"), ~[
|
||||
abs_path("xyz/x"),
|
||||
abs_path("xyz/y"),
|
||||
abs_path("xyz/z")]);
|
||||
|
||||
assert_eq!(glob_vec("a*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*a*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a*a"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aaa*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*aaa"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*aaa*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*a*a*a*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aaa*/"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*a*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a*a"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aaa*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*aaa"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*aaa*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("*a*a*a*"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aaa*/"), ~[abs_path("aaa")]);
|
||||
|
||||
assert_eq!(glob_vec("aaa/*"), ~[
|
||||
abs_path("aaa/apple"),
|
||||
abs_path("aaa/orange"),
|
||||
abs_path("aaa/tomato")]);
|
||||
assert_eq!(glob_vec("aaa/*"), ~[
|
||||
abs_path("aaa/apple"),
|
||||
abs_path("aaa/orange"),
|
||||
abs_path("aaa/tomato")]);
|
||||
|
||||
assert_eq!(glob_vec("aaa/*a*"), ~[
|
||||
abs_path("aaa/apple"),
|
||||
abs_path("aaa/orange"),
|
||||
abs_path("aaa/tomato")]);
|
||||
assert_eq!(glob_vec("aaa/*a*"), ~[
|
||||
abs_path("aaa/apple"),
|
||||
abs_path("aaa/orange"),
|
||||
abs_path("aaa/tomato")]);
|
||||
|
||||
assert_eq!(glob_vec("*/*/*.txt"), ~[
|
||||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")]);
|
||||
assert_eq!(glob_vec("*/*/*.txt"), ~[
|
||||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")]);
|
||||
|
||||
assert_eq!(glob_vec("*/*/t[aob]m?to[.]t[!y]t"), ~[
|
||||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")]);
|
||||
assert_eq!(glob_vec("*/*/t[aob]m?to[.]t[!y]t"), ~[
|
||||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")]);
|
||||
|
||||
assert_eq!(glob_vec("aa[a]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[abc]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a[bca]a"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[b]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[xyz]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[]]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[a]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[abc]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a[bca]a"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[b]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[xyz]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[]]"), ~[]);
|
||||
|
||||
assert_eq!(glob_vec("aa[!b]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[!bcd]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a[!bcd]a"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[!a]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[!abc]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[!b]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[!bcd]"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("a[!bcd]a"), ~[abs_path("aaa")]);
|
||||
assert_eq!(glob_vec("aa[!a]"), ~[]);
|
||||
assert_eq!(glob_vec("aa[!abc]"), ~[]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[[]"), ~[abs_path("bbb/specials/[")]);
|
||||
assert_eq!(glob_vec("bbb/specials/!"), ~[abs_path("bbb/specials/!")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[]]"), ~[abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[[]"), ~[abs_path("bbb/specials/[")]);
|
||||
assert_eq!(glob_vec("bbb/specials/!"), ~[abs_path("bbb/specials/!")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[]]"), ~[abs_path("bbb/specials/]")]);
|
||||
|
||||
if os::consts::FAMILY != os::consts::windows::FAMILY {
|
||||
assert_eq!(glob_vec("bbb/specials/[*]"), ~[abs_path("bbb/specials/*")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[?]"), ~[abs_path("bbb/specials/?")]);
|
||||
}
|
||||
if os::consts::FAMILY != os::consts::windows::FAMILY {
|
||||
assert_eq!(glob_vec("bbb/specials/[*]"), ~[abs_path("bbb/specials/*")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[?]"), ~[abs_path("bbb/specials/?")]);
|
||||
}
|
||||
|
||||
if os::consts::FAMILY == os::consts::windows::FAMILY {
|
||||
if os::consts::FAMILY == os::consts::windows::FAMILY {
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[![]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[![]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/]")]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[!]]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/[")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[!]]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/[")]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[!!]"), ~[
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[!!]"), ~[
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[![]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[![]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/]")]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[!]]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/[")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[!]]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/[")]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[!!]"), ~[
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[!!]"), ~[
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[!*]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[!*]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/?"),
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
|
||||
assert_eq!(glob_vec("bbb/specials/[!?]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
assert_eq!(glob_vec("bbb/specials/[!?]"), ~[
|
||||
abs_path("bbb/specials/!"),
|
||||
abs_path("bbb/specials/*"),
|
||||
abs_path("bbb/specials/["),
|
||||
abs_path("bbb/specials/]")]);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,12 @@
|
||||
// except according to those terms.
|
||||
|
||||
// This test can't be a unit test in std,
|
||||
// because it needs mkdtemp, which is in extra
|
||||
// because it needs TempDir, which is in extra
|
||||
|
||||
// xfail-fast
|
||||
extern mod extra;
|
||||
|
||||
use extra::tempfile::mkdtemp;
|
||||
use extra::tempfile::TempDir;
|
||||
use std::os;
|
||||
use std::libc;
|
||||
|
||||
@ -23,7 +23,8 @@ fn rename_directory() {
|
||||
unsafe {
|
||||
static U_RWX: i32 = (libc::S_IRUSR | libc::S_IWUSR | libc::S_IXUSR) as i32;
|
||||
|
||||
let tmpdir = mkdtemp(&os::tmpdir(), "rename_directory").expect("rename_directory failed");
|
||||
let tmpdir = TempDir::new("rename_directory").expect("rename_directory failed");
|
||||
let tmpdir = tmpdir.path();
|
||||
let old_path = tmpdir.push_many(["foo", "bar", "baz"]);
|
||||
assert!(os::mkdir_recursive(&old_path, U_RWX));
|
||||
let test_file = &old_path.push("temp.txt");
|
||||
|
@ -18,8 +18,8 @@ use std::io;
|
||||
use std::os;
|
||||
|
||||
pub fn main() {
|
||||
let dir = tempfile::mkdtemp(&Path("."), "").unwrap();
|
||||
let path = dir.push("file");
|
||||
let dir = tempfile::TempDir::new_in(&Path("."), "").unwrap();
|
||||
let path = dir.path().push("file");
|
||||
|
||||
{
|
||||
match io::file_writer(&path, [io::Create, io::Truncate]) {
|
||||
@ -34,7 +34,4 @@ pub fn main() {
|
||||
|
||||
assert!(path.exists());
|
||||
assert_eq!(path.get_size(), Some(1000));
|
||||
|
||||
os::remove_file(&path);
|
||||
os::remove_dir(&dir);
|
||||
}
|
||||
|
@ -20,14 +20,62 @@
|
||||
|
||||
extern mod extra;
|
||||
|
||||
use extra::tempfile::mkdtemp;
|
||||
use extra::tempfile::TempDir;
|
||||
use std::os;
|
||||
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
|
||||
use std::task;
|
||||
use std::cell::Cell;
|
||||
|
||||
fn test_mkdtemp() {
|
||||
let p = mkdtemp(&Path("."), "foobar").unwrap();
|
||||
os::remove_dir(&p);
|
||||
assert!(p.to_str().ends_with("foobar"));
|
||||
fn test_tempdir() {
|
||||
let path = {
|
||||
let p = TempDir::new_in(&Path("."), "foobar").unwrap();
|
||||
let p = p.path();
|
||||
assert!(p.to_str().ends_with("foobar"));
|
||||
p.clone()
|
||||
};
|
||||
assert!(!os::path_exists(&path));
|
||||
}
|
||||
|
||||
fn test_rm_tempdir() {
|
||||
let (rd, wr) = stream();
|
||||
let f: ~fn() = || {
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
wr.send(tmp.path().clone());
|
||||
fail2!("fail to unwind past `tmp`");
|
||||
};
|
||||
task::try(f);
|
||||
let path = rd.recv();
|
||||
assert!(!os::path_exists(&path));
|
||||
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
let path = tmp.path().clone();
|
||||
let cell = Cell::new(tmp);
|
||||
let f: ~fn() = || {
|
||||
let _tmp = cell.take();
|
||||
fail2!("fail to unwind past `tmp`");
|
||||
};
|
||||
task::try(f);
|
||||
assert!(!os::path_exists(&path));
|
||||
|
||||
let path;
|
||||
{
|
||||
let f: ~fn() -> TempDir = || {
|
||||
TempDir::new("test_rm_tempdir").unwrap()
|
||||
};
|
||||
let tmp = task::try(f).expect("test_rm_tmdir");
|
||||
path = tmp.path().clone();
|
||||
assert!(os::path_exists(&path));
|
||||
}
|
||||
assert!(!os::path_exists(&path));
|
||||
|
||||
let path;
|
||||
{
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
path = tmp.unwrap();
|
||||
}
|
||||
assert!(os::path_exists(&path));
|
||||
os::remove_dir_recursive(&path);
|
||||
assert!(!os::path_exists(&path));
|
||||
}
|
||||
|
||||
// Ideally these would be in std::os but then core would need
|
||||
@ -65,12 +113,13 @@ fn recursive_mkdir_rel_2() {
|
||||
assert!(os::path_is_dir(&path2.pop()));
|
||||
}
|
||||
|
||||
// Ideally this would be in core, but needs mkdtemp
|
||||
// Ideally this would be in core, but needs TempFile
|
||||
pub fn test_rmdir_recursive_ok() {
|
||||
let rwx = (S_IRUSR | S_IWUSR | S_IXUSR) as i32;
|
||||
|
||||
let tmpdir = mkdtemp(&os::tmpdir(), "test").expect("test_rmdir_recursive_ok: \
|
||||
couldn't create temp dir");
|
||||
let tmpdir = TempDir::new("test").expect("test_rmdir_recursive_ok: \
|
||||
couldn't create temp dir");
|
||||
let tmpdir = tmpdir.path();
|
||||
let root = tmpdir.push("foo");
|
||||
|
||||
debug2!("making {}", root.to_str());
|
||||
@ -85,14 +134,15 @@ pub fn test_rmdir_recursive_ok() {
|
||||
}
|
||||
|
||||
fn in_tmpdir(f: &fn()) {
|
||||
let tmpdir = mkdtemp(&os::tmpdir(), "test").expect("can't make tmpdir");
|
||||
assert!(os::change_dir(&tmpdir));
|
||||
let tmpdir = TempDir::new("test").expect("can't make tmpdir");
|
||||
assert!(os::change_dir(tmpdir.path()));
|
||||
|
||||
f();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
in_tmpdir(test_mkdtemp);
|
||||
in_tmpdir(test_tempdir);
|
||||
in_tmpdir(test_rm_tempdir);
|
||||
in_tmpdir(recursive_mkdir_rel);
|
||||
in_tmpdir(recursive_mkdir_dot);
|
||||
in_tmpdir(recursive_mkdir_rel_2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user