From 73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Thu, 26 Sep 2013 17:21:59 -0700 Subject: path2: Replace the path module outright Remove the old path. Rename path2 to path. Update all clients for the new path. Also make some miscellaneous changes to the Path APIs to help the adoption process. --- src/libextra/fileinput.rs | 12 +++--- src/libextra/glob.rs | 83 ++++++++++++++++++++++++++------------- src/libextra/tempfile.rs | 2 +- src/libextra/terminfo/searcher.rs | 42 ++++++++++++-------- src/libextra/test.rs | 12 +++--- src/libextra/workcache.rs | 17 +++++--- 6 files changed, 104 insertions(+), 64 deletions(-) (limited to 'src/libextra') diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index bf3fe4b39b2..08d1222ff46 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -362,7 +362,7 @@ pub fn make_path_option_vec(vec: &[~str], stdin_hyphen : bool) -> ~[Option if stdin_hyphen && "-" == *str { None } else { - Some(Path(*str)) + Some(Path::from_str(*str)) } }).collect() } @@ -435,14 +435,14 @@ mod test { fn test_make_path_option_vec() { let strs = [~"some/path", ~"some/other/path"]; - let paths = ~[Some(Path("some/path")), - Some(Path("some/other/path"))]; + let paths = ~[Some(Path::from_str("some/path")), + Some(Path::from_str("some/other/path"))]; assert_eq!(make_path_option_vec(strs, true), paths.clone()); assert_eq!(make_path_option_vec(strs, false), paths); assert_eq!(make_path_option_vec([~"-"], true), ~[None]); - assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path("-"))]); + assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path::from_str("-"))]); } #[test] @@ -567,9 +567,9 @@ mod test { #[test] fn test_no_trailing_newline() { let f1 = - Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")); + Some(Path::from_str("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")); let f2 = - Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp")); + Some(Path::from_str("tmp/lib-fileinput-test-no-trailing-newline-2.tmp")); { let mut wr = file::open(f1.get_ref(), io::CreateOrTruncate, diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index 112ea142189..e398f41c467 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -35,7 +35,7 @@ pub struct GlobIterator { priv root: Path, priv dir_patterns: ~[Pattern], priv options: MatchOptions, - priv todo: ~[Path] + priv todo: ~[(Path,uint)] } /** @@ -80,18 +80,32 @@ pub fn glob(pattern: &str) -> GlobIterator { * Paths are yielded in alphabetical order, as absolute paths. */ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { + #[cfg(windows)] + use is_sep = std::path::windows::is_sep2; + #[cfg(not(windows))] + fn is_sep(c: char) -> bool { c <= '\x7F' && ::std::path::posix::is_sep(&(c as u8)) } + #[cfg(windows)] + fn check_windows_verbatim(p: &Path) -> bool { p.is_verbatim() } + #[cfg(not(windows))] + fn check_windows_verbatim(_: &Path) -> bool { false } + + // calculate root this way to handle volume-relative Windows paths correctly + let mut root = os::getcwd(); + let pat_root = Path::from_str(pattern).root_path(); + if pat_root.is_some() { + if check_windows_verbatim(pat_root.get_ref()) { + // XXX: How do we want to handle verbatim paths? I'm inclined to return nothing, + // since we can't very well find all UNC shares with a 1-letter server name. + return GlobIterator { root: root, dir_patterns: ~[], options: options, todo: ~[] }; + } + root.push_path(pat_root.get_ref()); + } - // note that this relies on the glob meta characters not - // having any special meaning in actual pathnames - let path = Path(pattern); - let dir_patterns = path.components.map(|s| Pattern::new(*s)); + let root_len = pat_root.map_move_default(0u, |p| p.as_vec().len()); + let dir_patterns = pattern.slice_from(root_len.min(&pattern.len())) + .split_terminator_iter(is_sep).map(|s| Pattern::new(s)).to_owned_vec(); - let root = if path.is_absolute() { - Path {components: ~[], .. path} // preserve windows path host/device - } else { - os::getcwd() - }; - let todo = list_dir_sorted(&root); + let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec(); GlobIterator { root: root, @@ -109,18 +123,24 @@ impl Iterator for GlobIterator { return None; } - let path = self.todo.pop(); - let pattern_index = path.components.len() - self.root.components.len() - 1; - let ref pattern = self.dir_patterns[pattern_index]; - - if pattern.matches_with(*path.components.last(), self.options) { + let (path,idx) = self.todo.pop(); + let ref pattern = self.dir_patterns[idx]; - if pattern_index == self.dir_patterns.len() - 1 { + if pattern.matches_with(match path.filename_str() { + // this ugly match needs to go here to avoid a borrowck error + None => { + // FIXME (#9639): How do we handle non-utf8 filenames? Ignore them for now + // Ideally we'd still match them against a * + loop; + } + Some(x) => x + }, self.options) { + if idx == self.dir_patterns.len() - 1 { // it is not possible for a pattern to match a directory *AND* its children // so we don't need to check the children return Some(path); } else { - self.todo.push_all(list_dir_sorted(&path)); + self.todo.extend(&mut list_dir_sorted(&path).move_iter().map(|x|(x,idx+1))); } } } @@ -130,7 +150,7 @@ impl Iterator for GlobIterator { fn list_dir_sorted(path: &Path) -> ~[Path] { let mut children = os::list_dir_path(path); - sort::quick_sort(children, |p1, p2| p2.components.last() <= p1.components.last()); + sort::quick_sort(children, |p1, p2| p2.filename().unwrap() <= p1.filename().unwrap()); children } @@ -285,7 +305,10 @@ impl Pattern { * using the default match options (i.e. `MatchOptions::new()`). */ pub fn matches_path(&self, path: &Path) -> bool { - self.matches(path.to_str()) + // FIXME (#9639): This needs to handle non-utf8 paths + do path.as_str().map_move_default(false) |s| { + self.matches(s) + } } /** @@ -300,7 +323,10 @@ impl Pattern { * using the specified match options. */ pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool { - self.matches_with(path.to_str(), options) + // FIXME (#9639): This needs to handle non-utf8 paths + do path.as_str().map_move_default(false) |s| { + self.matches_with(s, options) + } } fn matches_from(&self, @@ -436,7 +462,7 @@ fn in_char_specifiers(specifiers: &[CharSpecifier], c: char, options: MatchOptio /// A helper function to determine if two chars are (possibly case-insensitively) equal. fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool { - if cfg!(windows) && path::windows::is_sep(a) && path::windows::is_sep(b) { + if cfg!(windows) && path::windows::is_sep2(a) && path::windows::is_sep2(b) { true } else if !case_sensitive && a.is_ascii() && b.is_ascii() { // FIXME: work with non-ascii chars properly (issue #1347) @@ -449,9 +475,9 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool { /// A helper function to determine if a char is a path separator on the current platform. fn is_sep(c: char) -> bool { if cfg!(windows) { - path::windows::is_sep(c) + path::windows::is_sep2(c) } else { - path::posix::is_sep(c) + c <= '\x7F' && path::posix::is_sep(&(c as u8)) } } @@ -522,8 +548,9 @@ mod test { assert!(glob("//").next().is_none()); // check windows absolute paths with host/device components - let root_with_device = (Path {components: ~[], .. os::getcwd()}).to_str() + "*"; - assert!(glob(root_with_device).next().is_some()); + let root_with_device = os::getcwd().root_path().unwrap().join_str("*"); + // FIXME (#9639): This needs to handle non-utf8 paths + assert!(glob(root_with_device.as_str().unwrap()).next().is_some()); } #[test] @@ -745,9 +772,9 @@ mod test { #[test] fn test_matches_path() { - // on windows, (Path("a/b").to_str() == "a\\b"), so this + // on windows, (Path::from_str("a/b").as_str().unwrap() == "a\\b"), so this // tests that / and \ are considered equivalent on windows - assert!(Pattern::new("a/b").matches_path(&Path("a/b"))); + assert!(Pattern::new("a/b").matches_path(&Path::from_str("a/b"))); } } diff --git a/src/libextra/tempfile.rs b/src/libextra/tempfile.rs index 60084faad98..12263188787 100644 --- a/src/libextra/tempfile.rs +++ b/src/libextra/tempfile.rs @@ -35,7 +35,7 @@ impl TempDir { let mut r = rand::rng(); for _ in range(0u, 1000) { - let p = tmpdir.push(r.gen_ascii_str(16) + suffix); + let p = tmpdir.join_str(r.gen_ascii_str(16) + suffix); if os::make_dir(&p, 0x1c0) { // 700 return Some(TempDir { path: Some(p) }); } diff --git a/src/libextra/terminfo/searcher.rs b/src/libextra/terminfo/searcher.rs index 5c7efdb298f..cd4e487d70f 100644 --- a/src/libextra/terminfo/searcher.rs +++ b/src/libextra/terminfo/searcher.rs @@ -14,10 +14,9 @@ use std::{os, str}; use std::os::getenv; use std::io::{file_reader, Reader}; -use path = std::path::Path; /// Return path to database entry for `term` -pub fn get_dbpath_for_term(term: &str) -> Option<~path> { +pub fn get_dbpath_for_term(term: &str) -> Option<~Path> { if term.len() == 0 { return None; } @@ -29,25 +28,26 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> { // Find search directory match getenv("TERMINFO") { - Some(dir) => dirs_to_search.push(path(dir)), + Some(dir) => dirs_to_search.push(Path::from_str(dir)), None => { if homedir.is_some() { - dirs_to_search.push(homedir.unwrap().push(".terminfo")); // ncurses compatability + // ncurses compatability; + dirs_to_search.push(homedir.unwrap().join_str(".terminfo")) } match getenv("TERMINFO_DIRS") { Some(dirs) => for i in dirs.split_iter(':') { if i == "" { - dirs_to_search.push(path("/usr/share/terminfo")); + dirs_to_search.push(Path::from_str("/usr/share/terminfo")); } else { - dirs_to_search.push(path(i.to_owned())); + dirs_to_search.push(Path::from_str(i.to_owned())); } }, // Found nothing, use the default paths // /usr/share/terminfo is the de facto location, but it seems // Ubuntu puts it in /lib/terminfo None => { - dirs_to_search.push(path("/usr/share/terminfo")); - dirs_to_search.push(path("/lib/terminfo")); + dirs_to_search.push(Path::from_str("/usr/share/terminfo")); + dirs_to_search.push(Path::from_str("/lib/terminfo")); } } } @@ -55,14 +55,18 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> { // Look for the terminal in all of the search directories for p in dirs_to_search.iter() { - let newp = ~p.push_many(&[str::from_char(first_char), term.to_owned()]); - if os::path_exists(p) && os::path_exists(newp) { - return Some(newp); - } - // on some installations the dir is named after the hex of the char (e.g. OS X) - let newp = ~p.push_many(&[format!("{:x}", first_char as uint), term.to_owned()]); - if os::path_exists(p) && os::path_exists(newp) { - return Some(newp); + if os::path_exists(p) { + let f = str::from_char(first_char); + let newp = p.join_many_str([f.as_slice(), term]); + if os::path_exists(&newp) { + return Some(~newp); + } + // on some installations the dir is named after the hex of the char (e.g. OS X) + let f = format!("{:x}", first_char as uint); + let newp = p.join_many_str([f.as_slice(), term]); + if os::path_exists(&newp) { + return Some(~newp); + } } } None @@ -82,7 +86,11 @@ fn test_get_dbpath_for_term() { // woefully inadequate test coverage // note: current tests won't work with non-standard terminfo hierarchies (e.g. OS X's) use std::os::{setenv, unsetenv}; - fn x(t: &str) -> ~str { get_dbpath_for_term(t).expect("no terminfo entry found").to_str() }; + // FIXME (#9639): This needs to handle non-utf8 paths + fn x(t: &str) -> ~str { + let p = get_dbpath_for_term(t).expect("no terminfo entry found"); + p.as_str().unwrap().to_owned() + }; assert!(x("screen") == ~"/usr/share/terminfo/s/screen"); assert!(get_dbpath_for_term("") == None); setenv("TERMINFO_DIRS", ":"); diff --git a/src/libextra/test.rs b/src/libextra/test.rs index a352a2e4678..20690283dd5 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -271,20 +271,20 @@ pub fn parse_opts(args: &[~str]) -> Option { let run_ignored = matches.opt_present("ignored"); let logfile = matches.opt_str("logfile"); - let logfile = logfile.map(|s| Path(s)); + let logfile = logfile.map(|s| Path::from_str(s)); let run_benchmarks = matches.opt_present("bench"); let run_tests = ! run_benchmarks || matches.opt_present("test"); let ratchet_metrics = matches.opt_str("ratchet-metrics"); - let ratchet_metrics = ratchet_metrics.map(|s| Path(s)); + let ratchet_metrics = ratchet_metrics.map(|s| Path::from_str(s)); let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent"); let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::(s).unwrap()); let save_metrics = matches.opt_str("save-metrics"); - let save_metrics = save_metrics.map(|s| Path(s)); + let save_metrics = save_metrics.map(|s| Path::from_str(s)); let test_shard = matches.opt_str("test-shard"); let test_shard = opt_shard(test_shard); @@ -547,7 +547,7 @@ impl ConsoleTestState { let ratchet_success = match *ratchet_metrics { None => true, Some(ref pth) => { - self.out.write_str(format!("\nusing metrics ratchet: {}\n", pth.to_str())); + self.out.write_str(format!("\nusing metrics ratchet: {}\n", pth.display())); match ratchet_pct { None => (), Some(pct) => @@ -659,7 +659,7 @@ pub fn run_tests_console(opts: &TestOpts, None => (), Some(ref pth) => { st.metrics.save(pth); - st.out.write_str(format!("\nmetrics saved to: {}", pth.to_str())); + st.out.write_str(format!("\nmetrics saved to: {}", pth.display())); } } return st.write_run_finish(&opts.ratchet_metrics, opts.ratchet_noise_percent); @@ -1440,7 +1440,7 @@ mod tests { pub fn ratchet_test() { let dpth = TempDir::new("test-ratchet").expect("missing test for ratchet"); - let pth = dpth.path().push("ratchet.json"); + let pth = dpth.path().join_str("ratchet.json"); let mut m1 = MetricMap::new(); m1.insert_metric("runtime", 1000.0, 2.0); diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 32a2d83d814..ea943cdb01b 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -184,11 +184,11 @@ impl Database { let f = io::file_reader(&self.db_filename); match f { Err(e) => fail2!("Couldn't load workcache database {}: {}", - self.db_filename.to_str(), e.to_str()), + self.db_filename.display(), e.to_str()), Ok(r) => match json::from_reader(r) { Err(e) => fail2!("Couldn't parse workcache database (from file {}): {}", - self.db_filename.to_str(), e.to_str()), + self.db_filename.display(), e.to_str()), Ok(r) => { let mut decoder = json::Decoder(r); self.db_cache = Decodable::decode(&mut decoder); @@ -498,7 +498,7 @@ fn test() { // Create a path to a new file 'filename' in the directory in which // this test is running. fn make_path(filename: ~str) -> Path { - let pth = os::self_exe_path().expect("workcache::test failed").pop().push(filename); + let pth = os::self_exe_path().expect("workcache::test failed").with_filename_str(filename); if os::path_exists(&pth) { os::remove_file(&pth); } @@ -522,15 +522,20 @@ fn test() { let subcx = cx.clone(); let pth = pth.clone(); - prep.declare_input("file", pth.to_str(), digest_file(&pth)); + // FIXME (#9639): This needs to handle non-utf8 paths + prep.declare_input("file", pth.as_str().unwrap(), digest_file(&pth)); do prep.exec |_exe| { let out = make_path(~"foo.o"); - run::process_status("gcc", [pth.to_str(), ~"-o", out.to_str()]); + // FIXME (#9639): This needs to handle non-utf8 paths + run::process_status("gcc", [pth.as_str().unwrap().to_owned(), + ~"-o", + out.as_str().unwrap().to_owned()]); let _proof_of_concept = subcx.prep("subfn"); // Could run sub-rules inside here. - out.to_str() + // FIXME (#9639): This needs to handle non-utf8 paths + out.as_str().unwrap().to_owned() } }; -- cgit 1.4.1-3-g733a5 From e65d33e9ed3057a6afeaea9bf68519eb758f51ab Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Wed, 2 Oct 2013 20:26:28 -0700 Subject: path2: Update for loop -> continue --- src/libextra/glob.rs | 2 +- src/libstd/path/posix.rs | 2 +- src/libstd/path/windows.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libextra') diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index e398f41c467..51a4718394e 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -131,7 +131,7 @@ impl Iterator for GlobIterator { None => { // FIXME (#9639): How do we handle non-utf8 filenames? Ignore them for now // Ideally we'd still match them against a * - loop; + continue; } Some(x) => x }, self.options) { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index fb0069bbe01..b0b6d1ceea0 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -253,7 +253,7 @@ impl GenericPath for Path { loop { match (ita.next(), itb.next()) { (None, _) => break, - (Some(a), Some(b)) if a == b => { loop }, + (Some(a), Some(b)) if a == b => { continue }, (Some(a), _) if a == bytes!("..") => { // if ita contains only .. components, it's an ancestor return ita.all(|x| x == bytes!("..")); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 6dd7954de80..620b7c375ff 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -548,7 +548,7 @@ impl GenericPath for Path { loop { match (ita.next(), itb.next()) { (None, _) => break, - (Some(a), Some(b)) if a == b => { loop }, + (Some(a), Some(b)) if a == b => { continue }, (Some(a), _) if a == ".." => { // if ita contains only .. components, it's an ancestor return ita.all(|x| x == ".."); -- cgit 1.4.1-3-g733a5 From d6d9b926836b1f1c2b8b3fe4ab35dc63bec7ffcd Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sat, 5 Oct 2013 19:49:32 -0700 Subject: path2: Adjust the API to remove all the _str mutation methods Add a new trait BytesContainer that is implemented for both byte vectors and strings. Convert Path::from_vec and ::from_str to one function, Path::new(). Remove all the _str-suffixed mutation methods (push, join, with_*, set_*) and modify the non-suffixed versions to use BytesContainer. --- src/compiletest/compiletest.rs | 12 +- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 32 +- src/libextra/fileinput.rs | 16 +- src/libextra/glob.rs | 8 +- src/libextra/tempfile.rs | 2 +- src/libextra/terminfo/searcher.rs | 16 +- src/libextra/test.rs | 8 +- src/libextra/workcache.rs | 2 +- src/librustc/back/link.rs | 8 +- src/librustc/back/rpath.rs | 22 +- src/librustc/driver/driver.rs | 18 +- src/librustc/metadata/creader.rs | 4 +- src/librustc/metadata/filesearch.rs | 22 +- src/librustc/rustc.rs | 6 +- src/librustdoc/html/render.rs | 30 +- src/librustdoc/plugins.rs | 2 +- src/librustdoc/rustdoc.rs | 14 +- src/librusti/rusti.rs | 6 +- src/librustpkg/api.rs | 10 +- src/librustpkg/context.rs | 2 +- src/librustpkg/installed_packages.rs | 8 +- src/librustpkg/package_id.rs | 6 +- src/librustpkg/package_source.rs | 17 +- src/librustpkg/path_util.rs | 20 +- src/librustpkg/rustpkg.rs | 18 +- src/librustpkg/source_control.rs | 8 +- src/librustpkg/target.rs | 2 +- src/librustpkg/tests.rs | 374 ++++++------ src/librustpkg/util.rs | 8 +- src/librustpkg/version.rs | 4 +- src/librustpkg/workspace.rs | 4 +- src/libstd/io.rs | 24 +- src/libstd/os.rs | 62 +- src/libstd/path/mod.rs | 469 +++++++------- src/libstd/path/posix.rs | 618 +++++++++---------- src/libstd/path/windows.rs | 848 ++++++++++++-------------- src/libstd/rt/io/file.rs | 28 +- src/libstd/rt/io/support.rs | 2 +- src/libstd/rt/uv/file.rs | 12 +- src/libstd/rt/uv/uvio.rs | 13 +- src/libstd/run.rs | 4 +- src/libstd/unstable/dynamic_lib.rs | 2 +- src/libsyntax/ext/source_util.rs | 8 +- src/libsyntax/parse/parser.rs | 10 +- src/test/bench/core-std.rs | 4 +- src/test/bench/shootout-fasta.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/run-pass/glob-std.rs | 6 +- src/test/run-pass/issue-3424.rs | 2 +- src/test/run-pass/rename-directory.rs | 12 +- src/test/run-pass/stat.rs | 4 +- src/test/run-pass/tempfile.rs | 24 +- 53 files changed, 1384 insertions(+), 1485 deletions(-) (limited to 'src/libextra') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index cc99f0d67d2..362d2ba749d 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -102,15 +102,15 @@ pub fn parse_config(args: ~[~str]) -> config { } fn opt_path(m: &getopts::Matches, nm: &str) -> Path { - Path::from_str(m.opt_str(nm).unwrap()) + Path::new(m.opt_str(nm).unwrap()) } config { compile_lib_path: matches.opt_str("compile-lib-path").unwrap(), run_lib_path: matches.opt_str("run-lib-path").unwrap(), rustc_path: opt_path(matches, "rustc-path"), - clang_path: matches.opt_str("clang-path").map(|s| Path::from_str(s)), - llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::from_str(s)), + clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)), + llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)), src_base: opt_path(matches, "src-base"), build_base: opt_path(matches, "build-base"), aux_base: opt_path(matches, "aux-base"), @@ -123,10 +123,10 @@ pub fn parse_config(args: ~[~str]) -> config { } else { None }, - logfile: matches.opt_str("logfile").map(|s| Path::from_str(s)), - save_metrics: matches.opt_str("save-metrics").map(|s| Path::from_str(s)), + logfile: matches.opt_str("logfile").map(|s| Path::new(s)), + save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)), ratchet_metrics: - matches.opt_str("ratchet-metrics").map(|s| Path::from_str(s)), + matches.opt_str("ratchet-metrics").map(|s| Path::new(s)), ratchet_noise_percent: matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::(s)), runtool: matches.opt_str("runtool"), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index bf68371c7d2..9cd3d3683cd 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -161,7 +161,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> { fn parse_pp_exact(line: &str, testfile: &Path) -> Option { match parse_name_value_directive(line, ~"pp-exact") { - Some(s) => Some(Path::from_str(s)), + Some(s) => Some(Path::new(s)), None => { if parse_name_directive(line, "pp-exact") { testfile.file_path() diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index e1c4c34a5f4..b5b81f7b810 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -62,7 +62,7 @@ pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) { // We're going to be dumping a lot of info. Start on a new line. io::stdout().write_str("\n\n"); } - let testfile = Path::from_str(testfile); + let testfile = Path::new(testfile); debug2!("running {}", testfile.display()); let props = load_props(&testfile); debug2!("loaded props"); @@ -594,7 +594,7 @@ fn compose_and_run_compiler( let extra_link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()]; for rel_ab in props.aux_builds.iter() { - let abs_ab = config.aux_base.join_str(*rel_ab); + let abs_ab = config.aux_base.join(rel_ab.as_slice()); let aux_args = make_compile_args(config, props, ~[~"--lib"] + extra_link_args, |a,b| make_lib_name(a, b, testfile), &abs_ab); @@ -662,7 +662,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path { fn make_exe_name(config: &config, testfile: &Path) -> Path { let mut f = output_base_name(config, testfile); - f.add_extension_str(os::EXE_EXTENSION); + f.add_extension(os::EXE_EXTENSION); f } @@ -742,23 +742,23 @@ fn dump_output_file(config: &config, testfile: &Path, } fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path { - output_base_name(config, testfile).with_extension_str(extension) + output_base_name(config, testfile).with_extension(extension) } fn aux_output_dir_name(config: &config, testfile: &Path) -> Path { let mut f = output_base_name(config, testfile); - f.add_extension_str("libaux"); + f.add_extension("libaux"); f } fn output_testname(testfile: &Path) -> Path { - Path::from_vec(testfile.filestem().unwrap()) + Path::new(testfile.filestem().unwrap()) } fn output_base_name(config: &config, testfile: &Path) -> Path { config.build_base .join_path(&output_testname(testfile)) - .with_extension_str(config.stage_id) + .with_extension(config.stage_id.as_slice()) } fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) { @@ -916,7 +916,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) { // codegen tests (vs. clang) fn make_o_name(config: &config, testfile: &Path) -> Path { - output_base_name(config, testfile).with_extension_str("o") + output_base_name(config, testfile).with_extension("o") } fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path { @@ -942,9 +942,9 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps, fn compile_cc_with_clang_and_save_bitcode(config: &config, _props: &TestProps, testfile: &Path) -> ProcRes { - let bitcodefile = output_base_name(config, testfile).with_extension_str("bc"); + let bitcodefile = output_base_name(config, testfile).with_extension("bc"); let bitcodefile = append_suffix_to_stem(&bitcodefile, "clang"); - let testcc = testfile.with_extension_str("cc"); + let testcc = testfile.with_extension("cc"); let ProcArgs = ProcArgs { // FIXME (#9639): This needs to handle non-utf8 paths prog: config.clang_path.get_ref().as_str().unwrap().to_owned(), @@ -959,10 +959,10 @@ fn compile_cc_with_clang_and_save_bitcode(config: &config, _props: &TestProps, fn extract_function_from_bitcode(config: &config, _props: &TestProps, fname: &str, testfile: &Path, suffix: &str) -> ProcRes { - let bitcodefile = output_base_name(config, testfile).with_extension_str("bc"); + let bitcodefile = output_base_name(config, testfile).with_extension("bc"); let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix); let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract"); - let prog = config.llvm_bin_path.get_ref().join_str("llvm-extract"); + let prog = config.llvm_bin_path.get_ref().join("llvm-extract"); let ProcArgs = ProcArgs { // FIXME (#9639): This needs to handle non-utf8 paths prog: prog.as_str().unwrap().to_owned(), @@ -975,11 +975,11 @@ fn extract_function_from_bitcode(config: &config, _props: &TestProps, fn disassemble_extract(config: &config, _props: &TestProps, testfile: &Path, suffix: &str) -> ProcRes { - let bitcodefile = output_base_name(config, testfile).with_extension_str("bc"); + let bitcodefile = output_base_name(config, testfile).with_extension("bc"); let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix); let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract"); - let extracted_ll = extracted_bc.with_extension_str("ll"); - let prog = config.llvm_bin_path.get_ref().join_str("llvm-dis"); + let extracted_ll = extracted_bc.with_extension("ll"); + let prog = config.llvm_bin_path.get_ref().join("llvm-dis"); let ProcArgs = ProcArgs { // FIXME (#9639): This needs to handle non-utf8 paths prog: prog.as_str().unwrap().to_owned(), @@ -991,7 +991,7 @@ fn disassemble_extract(config: &config, _props: &TestProps, fn count_extracted_lines(p: &Path) -> uint { - let x = io::read_whole_file_str(&p.with_extension_str("ll")).unwrap(); + let x = io::read_whole_file_str(&p.with_extension("ll")).unwrap(); x.line_iter().len() } diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index 08d1222ff46..8f176d5ccea 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -358,11 +358,11 @@ instance. `stdin_hyphen` controls whether `-` represents `stdin` or a literal `-`. */ pub fn make_path_option_vec(vec: &[~str], stdin_hyphen : bool) -> ~[Option] { - vec.iter().map(|str| { - if stdin_hyphen && "-" == *str { + vec.iter().map(|s| { + if stdin_hyphen && "-" == *s { None } else { - Some(Path::from_str(*str)) + Some(Path::new(s.as_slice())) } }).collect() } @@ -435,14 +435,14 @@ mod test { fn test_make_path_option_vec() { let strs = [~"some/path", ~"some/other/path"]; - let paths = ~[Some(Path::from_str("some/path")), - Some(Path::from_str("some/other/path"))]; + let paths = ~[Some(Path::new("some/path")), + Some(Path::new("some/other/path"))]; assert_eq!(make_path_option_vec(strs, true), paths.clone()); assert_eq!(make_path_option_vec(strs, false), paths); assert_eq!(make_path_option_vec([~"-"], true), ~[None]); - assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path::from_str("-"))]); + assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path::new("-"))]); } #[test] @@ -567,9 +567,9 @@ mod test { #[test] fn test_no_trailing_newline() { let f1 = - Some(Path::from_str("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")); + Some(Path::new("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")); let f2 = - Some(Path::from_str("tmp/lib-fileinput-test-no-trailing-newline-2.tmp")); + Some(Path::new("tmp/lib-fileinput-test-no-trailing-newline-2.tmp")); { let mut wr = file::open(f1.get_ref(), io::CreateOrTruncate, diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index 51a4718394e..1a6c8e08e3b 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -91,7 +91,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { // calculate root this way to handle volume-relative Windows paths correctly let mut root = os::getcwd(); - let pat_root = Path::from_str(pattern).root_path(); + let pat_root = Path::new(pattern).root_path(); if pat_root.is_some() { if check_windows_verbatim(pat_root.get_ref()) { // XXX: How do we want to handle verbatim paths? I'm inclined to return nothing, @@ -548,7 +548,7 @@ mod test { assert!(glob("//").next().is_none()); // check windows absolute paths with host/device components - let root_with_device = os::getcwd().root_path().unwrap().join_str("*"); + let root_with_device = os::getcwd().root_path().unwrap().join("*"); // FIXME (#9639): This needs to handle non-utf8 paths assert!(glob(root_with_device.as_str().unwrap()).next().is_some()); } @@ -772,9 +772,9 @@ mod test { #[test] fn test_matches_path() { - // on windows, (Path::from_str("a/b").as_str().unwrap() == "a\\b"), so this + // on windows, (Path::new("a/b").as_str().unwrap() == "a\\b"), so this // tests that / and \ are considered equivalent on windows - assert!(Pattern::new("a/b").matches_path(&Path::from_str("a/b"))); + assert!(Pattern::new("a/b").matches_path(&Path::new("a/b"))); } } diff --git a/src/libextra/tempfile.rs b/src/libextra/tempfile.rs index 12263188787..d8fa130916a 100644 --- a/src/libextra/tempfile.rs +++ b/src/libextra/tempfile.rs @@ -35,7 +35,7 @@ impl TempDir { let mut r = rand::rng(); for _ in range(0u, 1000) { - let p = tmpdir.join_str(r.gen_ascii_str(16) + suffix); + let p = tmpdir.join(r.gen_ascii_str(16) + suffix); if os::make_dir(&p, 0x1c0) { // 700 return Some(TempDir { path: Some(p) }); } diff --git a/src/libextra/terminfo/searcher.rs b/src/libextra/terminfo/searcher.rs index cd4e487d70f..ea7d20e096d 100644 --- a/src/libextra/terminfo/searcher.rs +++ b/src/libextra/terminfo/searcher.rs @@ -28,26 +28,26 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> { // Find search directory match getenv("TERMINFO") { - Some(dir) => dirs_to_search.push(Path::from_str(dir)), + Some(dir) => dirs_to_search.push(Path::new(dir)), None => { if homedir.is_some() { // ncurses compatability; - dirs_to_search.push(homedir.unwrap().join_str(".terminfo")) + dirs_to_search.push(homedir.unwrap().join(".terminfo")) } match getenv("TERMINFO_DIRS") { Some(dirs) => for i in dirs.split_iter(':') { if i == "" { - dirs_to_search.push(Path::from_str("/usr/share/terminfo")); + dirs_to_search.push(Path::new("/usr/share/terminfo")); } else { - dirs_to_search.push(Path::from_str(i.to_owned())); + dirs_to_search.push(Path::new(i.to_owned())); } }, // Found nothing, use the default paths // /usr/share/terminfo is the de facto location, but it seems // Ubuntu puts it in /lib/terminfo None => { - dirs_to_search.push(Path::from_str("/usr/share/terminfo")); - dirs_to_search.push(Path::from_str("/lib/terminfo")); + dirs_to_search.push(Path::new("/usr/share/terminfo")); + dirs_to_search.push(Path::new("/lib/terminfo")); } } } @@ -57,13 +57,13 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> { for p in dirs_to_search.iter() { if os::path_exists(p) { let f = str::from_char(first_char); - let newp = p.join_many_str([f.as_slice(), term]); + let newp = p.join_many([f.as_slice(), term]); if os::path_exists(&newp) { return Some(~newp); } // on some installations the dir is named after the hex of the char (e.g. OS X) let f = format!("{:x}", first_char as uint); - let newp = p.join_many_str([f.as_slice(), term]); + let newp = p.join_many([f.as_slice(), term]); if os::path_exists(&newp) { return Some(~newp); } diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 20690283dd5..21fa9ed7574 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -271,20 +271,20 @@ pub fn parse_opts(args: &[~str]) -> Option { let run_ignored = matches.opt_present("ignored"); let logfile = matches.opt_str("logfile"); - let logfile = logfile.map(|s| Path::from_str(s)); + let logfile = logfile.map(|s| Path::new(s)); let run_benchmarks = matches.opt_present("bench"); let run_tests = ! run_benchmarks || matches.opt_present("test"); let ratchet_metrics = matches.opt_str("ratchet-metrics"); - let ratchet_metrics = ratchet_metrics.map(|s| Path::from_str(s)); + let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s)); let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent"); let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::(s).unwrap()); let save_metrics = matches.opt_str("save-metrics"); - let save_metrics = save_metrics.map(|s| Path::from_str(s)); + let save_metrics = save_metrics.map(|s| Path::new(s)); let test_shard = matches.opt_str("test-shard"); let test_shard = opt_shard(test_shard); @@ -1440,7 +1440,7 @@ mod tests { pub fn ratchet_test() { let dpth = TempDir::new("test-ratchet").expect("missing test for ratchet"); - let pth = dpth.path().join_str("ratchet.json"); + let pth = dpth.path().join("ratchet.json"); let mut m1 = MetricMap::new(); m1.insert_metric("runtime", 1000.0, 2.0); diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index ea943cdb01b..26309cf3b37 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -498,7 +498,7 @@ fn test() { // Create a path to a new file 'filename' in the directory in which // this test is running. fn make_path(filename: ~str) -> Path { - let pth = os::self_exe_path().expect("workcache::test failed").with_filename_str(filename); + let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename); if os::path_exists(&pth) { os::remove_file(&pth); } diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index d5cd78f54f7..404efa25ff3 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -249,7 +249,7 @@ pub mod write { llvm::LLVMInitializeMipsAsmParser(); if sess.opts.save_temps { - do output.with_extension_str("no-opt.bc").with_c_str |buf| { + do output.with_extension("no-opt.bc").with_c_str |buf| { llvm::LLVMWriteBitcodeToFile(llmod, buf); } } @@ -317,7 +317,7 @@ pub mod write { llvm::LLVMDisposePassManager(mpm); if sess.opts.save_temps { - do output.with_extension_str("bc").with_c_str |buf| { + do output.with_extension("bc").with_c_str |buf| { llvm::LLVMWriteBitcodeToFile(llmod, buf); } } @@ -921,7 +921,7 @@ pub fn link_binary(sess: Session, let out_dirname = out_filename.dir_path(); debug2!("dirname(out_filename): {}", out_dirname.display()); - out_filename.with_filename_str(long_libname) + out_filename.with_filename(long_libname) } else { out_filename.clone() }; @@ -977,7 +977,7 @@ pub fn link_args(sess: Session, let output = if *sess.building_library { let long_libname = output_dll_filename(sess.targ_cfg.os, lm); - out_filename.with_filename_str(long_libname) + out_filename.with_filename(long_libname) } else { out_filename.clone() }; diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index b3fb6be686d..b7ae9c1ecb5 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -46,7 +46,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path { let r = filesearch::relative_target_lib_path(sess.opts.target_triple); let mut p = sess.filesearch.sysroot().join_path(&r); - p.push_str(os::dll_filename("rustrt")); + p.push(os::dll_filename("rustrt")); p } @@ -147,7 +147,7 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> ~str { let install_prefix = env!("CFG_PREFIX"); let tlib = filesearch::relative_target_lib_path(target_triple); - let mut path = Path::from_str(install_prefix); + let mut path = Path::new(install_prefix); path.push_path(&tlib); let path = os::make_absolute(&path); // FIXME (#9639): This needs to handle non-utf8 paths @@ -186,8 +186,8 @@ mod test { #[test] fn test_prefix_rpath() { let res = get_install_prefix_rpath("triple"); - let mut d = Path::from_str(env!("CFG_PREFIX")); - d.push_str("lib/rustc/triple/lib"); + let mut d = Path::new(env!("CFG_PREFIX")); + d.push("lib/rustc/triple/lib"); debug2!("test_prefix_path: {} vs. {}", res.to_str(), d.display()); @@ -200,7 +200,7 @@ mod test { #[test] fn test_prefix_rpath_abs() { let res = get_install_prefix_rpath("triple"); - assert!(Path::from_str(res).is_absolute()); + assert!(Path::new(res).is_absolute()); } #[test] @@ -224,7 +224,7 @@ mod test { fn test_rpath_relative() { let o = session::OsLinux; let res = get_rpath_relative_to_output(o, - &Path::from_str("bin/rustc"), &Path::from_str("lib/libstd.so")); + &Path::new("bin/rustc"), &Path::new("lib/libstd.so")); assert_eq!(res.as_slice(), "$ORIGIN/../lib"); } @@ -233,7 +233,7 @@ mod test { fn test_rpath_relative() { let o = session::OsFreebsd; let res = get_rpath_relative_to_output(o, - &Path::from_str("bin/rustc"), &Path::from_str("lib/libstd.so")); + &Path::new("bin/rustc"), &Path::new("lib/libstd.so")); assert_eq!(res.as_slice(), "$ORIGIN/../lib"); } @@ -242,15 +242,15 @@ mod test { fn test_rpath_relative() { let o = session::OsMacos; let res = get_rpath_relative_to_output(o, - &Path::from_str("bin/rustc"), - &Path::from_str("lib/libstd.so")); + &Path::new("bin/rustc"), + &Path::new("lib/libstd.so")); assert_eq!(res.as_slice(), "@executable_path/../lib"); } #[test] fn test_get_absolute_rpath() { - let res = get_absolute_rpath(&Path::from_str("lib/libstd.so")); - let lib = os::make_absolute(&Path::from_str("lib")); + let res = get_absolute_rpath(&Path::new("lib/libstd.so")); + let lib = os::make_absolute(&Path::new("lib")); debug2!("test_get_absolute_rpath: {} vs. {}", res.to_str(), lib.display()); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index fc5ff163d74..f85b0dbcdc3 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -353,7 +353,7 @@ pub fn phase_5_run_llvm_passes(sess: Session, (sess.opts.output_type == link::output_type_object || sess.opts.output_type == link::output_type_exe) { let output_type = link::output_type_assembly; - let asm_filename = outputs.obj_filename.with_extension_str("s"); + let asm_filename = outputs.obj_filename.with_extension("s"); time(sess.time_passes(), "LLVM passes", (), |_| link::write::run_passes(sess, @@ -722,7 +722,7 @@ pub fn build_session_options(binary: @str, } else if matches.opt_present("emit-llvm") { link::output_type_bitcode } else { link::output_type_exe }; - let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::from_str(m)); + let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::new(m)); let target = matches.opt_str("target").unwrap_or(host_triple()); let target_cpu = matches.opt_str("target-cpu").unwrap_or(~"generic"); let target_feature = matches.opt_str("target-feature").unwrap_or(~""); @@ -755,7 +755,7 @@ pub fn build_session_options(binary: @str, let statik = debugging_opts & session::statik != 0; - let addl_lib_search_paths = matches.opt_strs("L").map(|s| Path::from_str(*s)); + let addl_lib_search_paths = matches.opt_strs("L").map(|s| Path::new(s.as_slice())); let linker = matches.opt_str("linker"); let linker_args = matches.opt_strs("link-args").flat_map( |a| { a.split_iter(' ').map(|arg| arg.to_owned()).collect() @@ -1005,15 +1005,15 @@ pub fn build_output_filenames(input: &input, } if *sess.building_library { - out_path = dirpath.join_str(os::dll_filename(stem)); + out_path = dirpath.join(os::dll_filename(stem)); obj_path = { - let mut p = dirpath.join_str(stem); - p.set_extension_str(obj_suffix); + let mut p = dirpath.join(stem); + p.set_extension(obj_suffix); p }; } else { - out_path = dirpath.join_str(stem); - obj_path = out_path.with_extension_str(obj_suffix); + out_path = dirpath.join(stem); + obj_path = out_path.with_extension(obj_suffix); } } @@ -1022,7 +1022,7 @@ pub fn build_output_filenames(input: &input, obj_path = if stop_after_codegen { out_file.clone() } else { - out_file.with_extension_str(obj_suffix) + out_file.with_extension(obj_suffix) }; if *sess.building_library { diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 8ece290293b..9700f68383a 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -143,7 +143,7 @@ fn visit_view_item(e: @mut Env, i: &ast::view_item) { let meta_items = match path_opt { None => meta_items.clone(), Some((p, _path_str_style)) => { - let p_path = Path::from_str(p); + let p_path = Path::new(p); match p_path.filestem_str() { None|Some("") => e.diag.span_bug(i.span, "Bad package path in `extern mod` item"), @@ -275,7 +275,7 @@ fn resolve_crate(e: @mut Env, }; let (lident, ldata) = loader::load_library_crate(&load_ctxt); - let cfilename = Path::from_str(lident); + let cfilename = Path::new(lident); let cdata = ldata; let attrs = decoder::get_crate_attributes(cdata); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 4e3daa7c185..6335df47d73 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -138,11 +138,11 @@ pub fn search(filesearch: @FileSearch, pick: pick) { pub fn relative_target_lib_path(target_triple: &str) -> Path { let dir = libdir(); - let mut p = Path::from_str(dir); + let mut p = Path::new(dir.as_slice()); assert!(p.is_relative()); - p.push_str("rustc"); - p.push_str(target_triple); - p.push_str(dir); + p.push("rustc"); + p.push(target_triple); + p.push(dir); p } @@ -153,8 +153,8 @@ fn make_target_lib_path(sysroot: &Path, fn make_rustpkg_target_lib_path(dir: &Path, target_triple: &str) -> Path { - let mut p = dir.join_str(libdir()); - p.push_str(target_triple); + let mut p = dir.join(libdir()); + p.push(target_triple); p } @@ -192,13 +192,13 @@ pub fn rust_path() -> ~[Path] { Some(env_path) => { let env_path_components: ~[&str] = env_path.split_str_iter(PATH_ENTRY_SEPARATOR).collect(); - env_path_components.map(|&s| Path::from_str(s)) + env_path_components.map(|&s| Path::new(s)) } None => ~[] }; let cwd = os::getcwd(); // now add in default entries - let cwd_dot_rust = cwd.join_str(".rust"); + let cwd_dot_rust = cwd.join(".rust"); if !env_rust_path.contains(&cwd_dot_rust) { env_rust_path.push(cwd_dot_rust); } @@ -206,14 +206,14 @@ pub fn rust_path() -> ~[Path] { env_rust_path.push(cwd.clone()); } do cwd.each_parent() |p| { - if !env_rust_path.contains(&p.join_str(".rust")) { + if !env_rust_path.contains(&p.join(".rust")) { push_if_exists(&mut env_rust_path, p); } true }; let h = os::homedir(); for h in h.iter() { - if !env_rust_path.contains(&h.join_str(".rust")) { + if !env_rust_path.contains(&h.join(".rust")) { push_if_exists(&mut env_rust_path, h); } } @@ -223,7 +223,7 @@ pub fn rust_path() -> ~[Path] { /// Adds p/.rust into vec, only if it exists fn push_if_exists(vec: &mut ~[Path], p: &Path) { - let maybe_dir = p.join_str(".rust"); + let maybe_dir = p.join(".rust"); if os::path_exists(&maybe_dir) { vec.push(maybe_dir); } diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 460ac45cdba..1d9f37a2e87 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -250,7 +250,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { let src = str::from_utf8(io::stdin().read_whole_stream()); str_input(src.to_managed()) } else { - file_input(Path::from_str(ifile)) + file_input(Path::new(ifile)) } } _ => early_error(demitter, "multiple input filenames provided") @@ -258,8 +258,8 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { let sopts = build_session_options(binary, matches, demitter); let sess = build_session(sopts, demitter); - let odir = matches.opt_str("out-dir").map(|o| Path::from_str(o)); - let ofile = matches.opt_str("o").map(|o| Path::from_str(o)); + let odir = matches.opt_str("out-dir").map(|o| Path::new(o)); + let ofile = matches.opt_str("o").map(|o| Path::new(o)); let cfg = build_configuration(sess); let pretty = do matches.opt_default("pretty", "normal").map |a| { parse_pretty(sess, a) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9347a1775d4..7ed424136be 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -255,16 +255,16 @@ pub fn run(mut crate: clean::Crate, dst: Path) { crate = cache.fold_crate(crate); // Add all the static files - let mut dst = cx.dst.join_str(crate.name); + let mut dst = cx.dst.join(crate.name.as_slice()); mkdir(&dst); - write(dst.join_str("jquery.js"), include_str!("static/jquery-2.0.3.min.js")); - write(dst.join_str("main.js"), include_str!("static/main.js")); - write(dst.join_str("main.css"), include_str!("static/main.css")); - write(dst.join_str("normalize.css"), include_str!("static/normalize.css")); + write(dst.join("jquery.js"), include_str!("static/jquery-2.0.3.min.js")); + write(dst.join("main.js"), include_str!("static/main.js")); + write(dst.join("main.css"), include_str!("static/main.css")); + write(dst.join("normalize.css"), include_str!("static/normalize.css")); // Publish the search index { - dst.push_str("search-index.js"); + dst.push("search-index.js"); let mut w = BufferedWriter::new(dst.open_writer(io::CreateOrTruncate)); let w = &mut w as &mut io::Writer; write!(w, "var searchIndex = ["); @@ -292,9 +292,9 @@ pub fn run(mut crate: clean::Crate, dst: Path) { // Render all source files (this may turn into a giant no-op) { info2!("emitting source files"); - let dst = cx.dst.join_str("src"); + let dst = cx.dst.join("src"); mkdir(&dst); - let dst = dst.join_str(crate.name); + let dst = dst.join(crate.name.as_slice()); mkdir(&dst); let mut folder = SourceCollector { dst: dst, @@ -338,7 +338,7 @@ fn mkdir(path: &Path) { /// static HTML tree. // FIXME (#9639): The closure should deal with &[u8] instead of &str fn clean_srcpath(src: &[u8], f: &fn(&str)) { - let p = Path::from_vec(src); + let p = Path::new(src); if p.as_vec() != bytes!(".") { for c in p.str_component_iter().map(|x|x.unwrap()) { if ".." == c { @@ -354,7 +354,7 @@ fn clean_srcpath(src: &[u8], f: &fn(&str)) { /// rendering in to the specified source destination. fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation { // See if there's documentation generated into the local directory - let local_location = dst.join_str(e.name); + let local_location = dst.join(e.name.as_slice()); if local_location.is_dir() { return Local; } @@ -413,7 +413,7 @@ impl<'self> DocFolder for SourceCollector<'self> { impl<'self> SourceCollector<'self> { /// Renders the given filename into its corresponding HTML source file. fn emit_source(&mut self, filename: &str) -> bool { - let p = Path::from_str(filename); + let p = Path::new(filename); // Read the contents of the file let mut contents = ~[]; @@ -445,7 +445,7 @@ impl<'self> SourceCollector<'self> { let mut cur = self.dst.clone(); let mut root_path = ~"../../"; do clean_srcpath(p.dirname()) |component| { - cur.push_str(component); + cur.push(component); mkdir(&cur); root_path.push_str("../"); } @@ -661,7 +661,7 @@ impl Context { fail2!("what {:?}", self); } let prev = self.dst.clone(); - self.dst.push_str(s); + self.dst.push(s.as_slice()); self.root_path.push_str("../"); self.current.push(s); @@ -808,7 +808,7 @@ impl Context { let item = Cell::new(item); do self.recurse(name) |this| { let item = item.take(); - let dst = this.dst.join_str("index.html"); + let dst = this.dst.join("index.html"); let writer = dst.open_writer(io::CreateOrTruncate); render(writer.unwrap(), this, &item, false); @@ -826,7 +826,7 @@ impl Context { // Things which don't have names (like impls) don't get special // pages dedicated to them. _ if item.name.is_some() => { - let dst = self.dst.join_str(item_path(&item)); + let dst = self.dst.join(item_path(&item)); let writer = dst.open_writer(io::CreateOrTruncate); render(writer.unwrap(), self, &item, true); } diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 12128402f74..4efc68a2655 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -41,7 +41,7 @@ impl PluginManager { /// platform. On windows, it turns into name.dll, on OS X, name.dylib, and /// elsewhere, libname.so. pub fn load_plugin(&mut self, name: ~str) { - let x = self.prefix.join_str(libname(name)); + let x = self.prefix.join(libname(name)); let lib_result = dl::DynamicLibrary::open(Some(&x)); let lib = lib_result.unwrap(); let plugin = unsafe { lib.symbol("rustdoc_plugin_entrypoint") }.unwrap(); diff --git a/src/librustdoc/rustdoc.rs b/src/librustdoc/rustdoc.rs index 470ae7f9dfe..6684410b587 100644 --- a/src/librustdoc/rustdoc.rs +++ b/src/librustdoc/rustdoc.rs @@ -134,13 +134,13 @@ pub fn main_args(args: &[~str]) -> int { info2!("going to format"); let started = time::precise_time_ns(); - let output = matches.opt_str("o").map(|s| Path::from_str(s)); + let output = matches.opt_str("o").map(|s| Path::new(s)); match matches.opt_str("w") { Some(~"html") | None => { - html::render::run(crate, output.unwrap_or(Path::from_str("doc"))) + html::render::run(crate, output.unwrap_or(Path::new("doc"))) } Some(~"json") => { - json_output(crate, res, output.unwrap_or(Path::from_str("doc.json"))) + json_output(crate, res, output.unwrap_or(Path::new("doc.json"))) } Some(s) => { println!("unknown output format: {}", s); @@ -188,8 +188,8 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { let mut plugins = matches.opt_strs("plugins"); // First, parse the crate and extract all relevant information. - let libs = Cell::new(matches.opt_strs("L").map(|s| Path::from_str(*s))); - let cr = Cell::new(Path::from_str(cratefile)); + let libs = Cell::new(matches.opt_strs("L").map(|s| Path::new(s.as_slice()))); + let cr = Cell::new(Path::new(cratefile)); info2!("starting to run rustc"); let crate = do std::task::try { let cr = cr.take(); @@ -230,7 +230,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { // Load all plugins/passes into a PluginManager let path = matches.opt_str("plugin-path").unwrap_or(~"/tmp/rustdoc_ng/plugins"); - let mut pm = plugins::PluginManager::new(Path::from_str(path)); + let mut pm = plugins::PluginManager::new(Path::new(path)); for pass in passes.iter() { let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) { Some(i) => PASSES[i].n1(), @@ -254,7 +254,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { /// This input format purely deserializes the json output file. No passes are /// run over the deserialized output. fn json_input(input: &str) -> Result { - let input = match ::std::io::file_reader(&Path::from_str(input)) { + let input = match ::std::io::file_reader(&Path::new(input)) { Ok(i) => i, Err(s) => return Err(s), }; diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index b511d17ec77..c025d9b10dd 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -142,7 +142,7 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str], let options = @session::options { crate_type: session::unknown_crate, binary: binary, - addl_lib_search_paths: @mut lib_search_paths.map(|p| Path::from_str(*p)), + addl_lib_search_paths: @mut lib_search_paths.map(|p| Path::new(p.as_slice())), jit: true, .. (*session::basic_options()).clone() }; @@ -328,7 +328,7 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option { } } match do task::try { - let src_path = Path::from_str(src_filename); + let src_path = Path::new(src_filename.as_slice()); let binary = binary.to_managed(); let options = @session::options { binary: binary, @@ -441,7 +441,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer, } } for crate in loaded_crates.iter() { - let crate_path = Path::from_str(*crate); + let crate_path = Path::new(crate.as_slice()); // FIXME (#9639): This needs to handle non-utf8 paths let crate_dir = crate_path.dirname_str().unwrap(); repl.program.record_extern(format!("extern mod {};", *crate)); diff --git a/src/librustpkg/api.rs b/src/librustpkg/api.rs index 6e0908d2a4f..02a96402229 100644 --- a/src/librustpkg/api.rs +++ b/src/librustpkg/api.rs @@ -43,17 +43,17 @@ pub fn new_default_context(c: workcache::Context, p: Path) -> BuildContext { } fn file_is_fresh(path: &str, in_hash: &str) -> bool { - let path = Path::from_str(path); + let path = Path::new(path); os::path_exists(&path) && in_hash == digest_file_with_date(&path) } fn binary_is_fresh(path: &str, in_hash: &str) -> bool { - let path = Path::from_str(path); + let path = Path::new(path); os::path_exists(&path) && in_hash == digest_only_date(&path) } pub fn new_workcache_context(p: &Path) -> workcache::Context { - let db_file = p.join_str("rustpkg_db.json"); // ??? probably wrong + let db_file = p.join("rustpkg_db.json"); // ??? probably wrong debug2!("Workcache database file: {}", db_file.display()); let db = RWArc::new(Database::new(db_file)); let lg = RWArc::new(Logger::new()); @@ -73,7 +73,7 @@ pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version, source_workspace: root.clone(), build_in_destination: false, destination_workspace: root.clone(), - start_dir: root.join_many_str(["src", name.as_slice()]), + start_dir: root.join_many(["src", name.as_slice()]), id: PkgId{ version: version, ..PkgId::new(name)}, // n.b. This assumes the package only has one crate libs: ~[mk_crate(lib)], @@ -91,7 +91,7 @@ pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version, source_workspace: root.clone(), build_in_destination: false, destination_workspace: root.clone(), - start_dir: root.join_many_str(["src", name.as_slice()]), + start_dir: root.join_many(["src", name.as_slice()]), id: PkgId{ version: version, ..PkgId::new(name)}, libs: ~[], // n.b. This assumes the package only has one crate diff --git a/src/librustpkg/context.rs b/src/librustpkg/context.rs index 41b04c389ae..554019133b2 100644 --- a/src/librustpkg/context.rs +++ b/src/librustpkg/context.rs @@ -156,7 +156,7 @@ impl Context { pub fn in_target(sysroot: &Path) -> bool { debug2!("Checking whether {} is in target", sysroot.display()); let mut p = sysroot.dir_path(); - p.set_filename_str("rustc"); + p.set_filename("rustc"); os::path_is_dir(&p) } diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index 995f484a4e6..485cbfef2f6 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -17,7 +17,7 @@ use std::os; pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool { let workspaces = rust_path(); for p in workspaces.iter() { - let binfiles = os::list_dir(&p.join_str("bin")); + let binfiles = os::list_dir(&p.join("bin")); for exec in binfiles.iter() { // FIXME (#9639): This needs to handle non-utf8 paths match exec.filestem_str() { @@ -29,17 +29,17 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool { } } } - let libfiles = os::list_dir(&p.join_str("lib")); + let libfiles = os::list_dir(&p.join("lib")); for lib in libfiles.iter() { debug2!("Full name: {}", lib.display()); match has_library(lib) { Some(basename) => { - let parent = p.join_str("lib"); + let parent = p.join("lib"); debug2!("parent = {}, child = {}", parent.display(), lib.display()); let rel_p = lib.path_relative_from(&parent).unwrap(); debug2!("Rel: {}", rel_p.display()); - let rel_path = rel_p.join_str(basename); + let rel_path = rel_p.join(basename); do rel_path.with_display_str |s| { debug2!("Rel name: {}", s); f(&PkgId::new(s)); diff --git a/src/librustpkg/package_id.rs b/src/librustpkg/package_id.rs index bd22f1da913..38b922ec05d 100644 --- a/src/librustpkg/package_id.rs +++ b/src/librustpkg/package_id.rs @@ -59,7 +59,7 @@ impl PkgId { } }; - let path = Path::from_str(s); + let path = Path::new(s); if !path.is_relative() { return cond.raise((path, ~"absolute pkgid")); } @@ -137,8 +137,8 @@ impl Iterator<(Path, Path)> for Prefixes { let last = self.components.pop(); self.remaining.unshift(last); // converting to str and then back is a little unfortunate - Some((Path::from_str(self.components.connect("/")), - Path::from_str(self.remaining.connect("/")))) + Some((Path::new(self.components.connect("/")), + Path::new(self.remaining.connect("/")))) } } } diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index a924694cca5..4e0db8cac4f 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -94,20 +94,20 @@ impl PkgSrc { } else { // We search for sources under both src/ and build/ , because build/ is where // automatically-checked-out sources go. - let mut result = source_workspace.join_str("src"); + let mut result = source_workspace.join("src"); result.push_path(&id.path.dir_path()); - result.push_str(format!("{}-{}", id.short_name, id.version.to_str())); + result.push(format!("{}-{}", id.short_name, id.version.to_str())); to_try.push(result); - let mut result = source_workspace.join_str("src"); + let mut result = source_workspace.join("src"); result.push_path(&id.path); to_try.push(result); - let mut result = build_dir.join_str("src"); + let mut result = build_dir.join("src"); result.push_path(&id.path.dir_path()); result.push_str(format!("{}-{}", id.short_name, id.version.to_str())); to_try.push(result.clone()); output_names.push(result); - let mut other_result = build_dir.join_str("src"); + let mut other_result = build_dir.join("src"); other_result.push_path(&id.path); to_try.push(other_result.clone()); output_names.push(other_result); @@ -129,7 +129,7 @@ impl PkgSrc { // That is, is this a package ID that points into the middle of a workspace? for (prefix, suffix) in id.prefixes_iter() { let package_id = PkgId::new(prefix.as_str().unwrap()); - let path = build_dir.join_path(&package_id.path); + let path = build_dir.join(&package_id.path); debug2!("in loop: checking if {} is a directory", path.display()); if os::path_is_dir(&path) { let ps = PkgSrc::new(source_workspace, @@ -260,6 +260,7 @@ impl PkgSrc { return None; } + // FIXME (#9639): This needs to handle non-utf8 paths let url = format!("https://{}", pkgid.path.as_str().unwrap()); debug2!("Fetching package: git clone {} {} [version={}]", url, clone_target.display(), pkgid.version.to_str()); @@ -289,7 +290,7 @@ impl PkgSrc { // If a file named "pkg.rs" in the start directory exists, // return the path for it. Otherwise, None pub fn package_script_option(&self) -> Option { - let maybe_path = self.start_dir.join_str("pkg.rs"); + let maybe_path = self.start_dir.join("pkg.rs"); debug2!("package_script_option: checking whether {} exists", maybe_path.display()); if os::path_exists(&maybe_path) { Some(maybe_path) @@ -309,7 +310,7 @@ impl PkgSrc { it.nth(prefix-1); // skip elements } assert!(it.peek().is_some()); - let mut sub = Path::from_str("."); + let mut sub = Path::new("."); for c in it { sub.push(c); } diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 34b387fc9a7..0f5f1470b6f 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -53,7 +53,7 @@ pub fn make_dir_rwx_recursive(p: &Path) -> bool { os::mkdir_recursive(p, U_RWX) /// True if there's a directory in with /// pkgid's short name pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool { - workspace_contains_package_id_(pkgid, workspace, |p| p.join_str("src")).is_some() + workspace_contains_package_id_(pkgid, workspace, |p| p.join("src")).is_some() } pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, @@ -98,16 +98,16 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, /// Return the target-specific build subdirectory, pushed onto `base`; /// doesn't check that it exists or create it pub fn target_build_dir(workspace: &Path) -> Path { - let mut dir = workspace.join_str("build"); - dir.push_str(host_triple()); + let mut dir = workspace.join("build"); + dir.push(host_triple()); dir } /// Return the target-specific lib subdirectory, pushed onto `base`; /// doesn't check that it exists or create it fn target_lib_dir(workspace: &Path) -> Path { - let mut dir = workspace.join_str("lib"); - dir.push_str(host_triple()); + let mut dir = workspace.join("lib"); + dir.push(host_triple()); dir } @@ -115,7 +115,7 @@ fn target_lib_dir(workspace: &Path) -> Path { /// doesn't check that it exists or create it /// note: this isn't target-specific fn target_bin_dir(workspace: &Path) -> Path { - workspace.join_str("bin") + workspace.join("bin") } /// Figure out what the executable name for in 's build @@ -205,7 +205,7 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target, // rustc doesn't use target-specific subdirectories pub fn system_library(sysroot: &Path, lib_name: &str) -> Option { - library_in(lib_name, &NoVersion, &sysroot.join_str("lib")) + library_in(lib_name, &NoVersion, &sysroot.join("lib")) } fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option { @@ -377,9 +377,9 @@ pub fn mk_output_path(what: OutputType, where: Target, dir.display()); let mut output_path = match what { // this code is duplicated from elsewhere; fix this - Lib => dir.join_str(os::dll_filename(short_name_with_version)), + Lib => dir.join(os::dll_filename(short_name_with_version)), // executable names *aren't* versioned - _ => dir.join_str(format!("{}{}{}", pkg_id.short_name, + _ => dir.join(format!("{}{}{}", pkg_id.short_name, match what { Test => "test", Bench => "bench", @@ -416,7 +416,7 @@ pub fn uninstall_package_from(workspace: &Path, pkgid: &PkgId) { fn dir_has_file(dir: &Path, file: &str) -> bool { assert!(dir.is_absolute()); - os::path_exists(&dir.join_str(file)) + os::path_exists(&dir.join(file)) } pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option { diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index 47a65753cc9..5ef8948c377 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -146,7 +146,7 @@ impl<'self> PkgScript<'self> { let crate = util::ready_crate(sess, self.crate.take_unwrap()); debug2!("Building output filenames with script name {}", driver::source_name(&driver::file_input(self.input.clone()))); - let exe = self.build_dir.join_str("pkg" + util::exe_suffix()); + let exe = self.build_dir.join("pkg" + util::exe_suffix()); util::compile_crate_from_input(&self.input, exec, Nothing, @@ -422,7 +422,7 @@ impl CtxMethods for BuildContext { // If workspace isn't in the RUST_PATH, and it's a git repo, // then clone it into the first entry in RUST_PATH, and repeat if !in_rust_path(&workspace) && is_git_dir(&workspace.join_path(&pkgid.path)) { - let mut out_dir = default_workspace().join_str("src"); + let mut out_dir = default_workspace().join("src"); out_dir.push_path(&pkgid.path); let git_result = source_control::safe_git_clone(&workspace.join_path(&pkgid.path), &pkgid.version, @@ -488,7 +488,7 @@ impl CtxMethods for BuildContext { // Find crates inside the workspace &Everything => pkg_src.find_crates(), // Find only tests - &Tests => pkg_src.find_crates_with_filter(|s| { is_test(&Path::from_str(s)) }), + &Tests => pkg_src.find_crates_with_filter(|s| { is_test(&Path::new(s)) }), // Don't infer any crates -- just build the one that was requested &JustOne(ref p) => { // We expect that p is relative to the package source's start directory, @@ -562,7 +562,7 @@ impl CtxMethods for BuildContext { let result = self.install_no_build(pkg_src.build_workspace(), &pkg_src.destination_workspace, - &id).map(|s| Path::from_str(*s)); + &id).map(|s| Path::new(*s)); debug2!("install: id = {}, about to call discover_outputs, {:?}", id.to_str(), result.map(|p| p.to_display_str())); installed_files = installed_files + result; @@ -669,10 +669,10 @@ impl CtxMethods for BuildContext { } fn init(&self) { - os::mkdir_recursive(&Path::from_str("src"), U_RWX); - os::mkdir_recursive(&Path::from_str("lib"), U_RWX); - os::mkdir_recursive(&Path::from_str("bin"), U_RWX); - os::mkdir_recursive(&Path::from_str("build"), U_RWX); + os::mkdir_recursive(&Path::new("src"), U_RWX); + os::mkdir_recursive(&Path::new("lib"), U_RWX); + os::mkdir_recursive(&Path::new("bin"), U_RWX); + os::mkdir_recursive(&Path::new("build"), U_RWX); } fn uninstall(&self, _id: &str, _vers: Option<~str>) { @@ -852,7 +852,7 @@ pub fn main_args(args: &[~str]) -> int { let mut remaining_args: ~[~str] = remaining_args.map(|s| (*s).clone()).collect(); remaining_args.shift(); let sroot = match supplied_sysroot { - Some(getopts::Val(s)) => Path::from_str(s), + Some(getopts::Val(s)) => Path::new(s), _ => filesearch::get_or_default_sysroot() }; diff --git a/src/librustpkg/source_control.rs b/src/librustpkg/source_control.rs index b910c079205..2fc925a8a6a 100644 --- a/src/librustpkg/source_control.rs +++ b/src/librustpkg/source_control.rs @@ -43,7 +43,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult else { match v { &ExactRevision(ref s) => { - let git_dir = target.join_str(".git"); + let git_dir = target.join(".git"); debug2!("`Running: git --work-tree={} --git-dir={} checkout {}", *s, target.display(), git_dir.display()); // FIXME (#9639: This needs to handle non-utf8 paths @@ -64,7 +64,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult // Check that no version was specified. There's no reason to not handle the // case where a version was requested, but I haven't implemented it. assert!(*v == NoVersion); - let git_dir = target.join_str(".git"); + let git_dir = target.join(".git"); debug2!("Running: git --work-tree={} --git-dir={} pull --no-edit {}", target.display(), git_dir.display(), source.display()); // FIXME (#9639: This needs to handle non-utf8 paths @@ -80,7 +80,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult let scratch_dir = TempDir::new("rustpkg"); let clone_target = match scratch_dir { - Some(d) => d.unwrap().join_str("rustpkg_temp"), + Some(d) => d.unwrap().join("rustpkg_temp"), None => cond.raise(~"Failed to create temporary directory for fetching git sources") }; @@ -136,5 +136,5 @@ fn process_output_in_cwd(prog: &str, args: &[~str], cwd: &Path) -> ProcessOutput } pub fn is_git_dir(p: &Path) -> bool { - os::path_is_dir(&p.join_str(".git")) + os::path_is_dir(&p.join(".git")) } diff --git a/src/librustpkg/target.rs b/src/librustpkg/target.rs index 9f371a86535..b21641a5e53 100644 --- a/src/librustpkg/target.rs +++ b/src/librustpkg/target.rs @@ -56,7 +56,7 @@ fn file_is(p: &Path, stem: &str) -> bool { } pub fn lib_name_of(p: &Path) -> Path { - p.join_str("lib.rs") + p.join("lib.rs") } pub static lib_crate_filename: &'static str = "lib.rs"; diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index de7ad9dc06b..cb40c3c0090 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -41,7 +41,7 @@ use util::datestamp; fn fake_ctxt(sysroot: Path, workspace: &Path) -> BuildContext { let context = workcache::Context::new( - RWArc::new(Database::new(workspace.join_str("rustpkg_db.json"))), + RWArc::new(Database::new(workspace.join("rustpkg_db.json"))), RWArc::new(Logger::new()), Arc::new(TreeMap::new())); BuildContext { @@ -59,7 +59,7 @@ fn fake_ctxt(sysroot: Path, workspace: &Path) -> BuildContext { fn fake_pkg() -> PkgId { let sn = ~"bogus"; PkgId { - path: Path::from_str(sn), + path: Path::new(sn.as_slice()), short_name: sn, version: NoVersion } @@ -67,7 +67,7 @@ fn fake_pkg() -> PkgId { fn git_repo_pkg() -> PkgId { PkgId { - path: Path::from_str("mockgithub.com/catamorphism/test-pkg"), + path: Path::new("mockgithub.com/catamorphism/test-pkg"), short_name: ~"test-pkg", version: NoVersion } @@ -75,7 +75,7 @@ fn git_repo_pkg() -> PkgId { fn git_repo_pkg_with_tag(a_tag: ~str) -> PkgId { PkgId { - path: Path::from_str("mockgithub.com/catamorphism/test-pkg"), + path: Path::new("mockgithub.com/catamorphism/test-pkg"), short_name: ~"test-pkg", version: Tagged(a_tag) } @@ -102,18 +102,18 @@ fn mk_empty_workspace(short_name: &Path, version: &Version, tag: &str) -> TempDi fn mk_workspace(workspace: &Path, short_name: &Path, version: &Version) -> Path { // include version number in directory name // FIXME (#9639): This needs to handle non-utf8 paths - let package_dir = workspace.join_many_str([~"src", format!("{}-{}", - short_name.as_str().unwrap(), version.to_str())]); + let package_dir = workspace.join_many([~"src", format!("{}-{}", + short_name.as_str().unwrap(), version.to_str())]); assert!(os::mkdir_recursive(&package_dir, U_RWX)); package_dir } fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) { let workspace_dir = mk_empty_workspace(short_name, version, "temp_workspace"); - let package_dir = workspace_dir.path().join_many_str([~"src", - format!("{}-{}", - short_name.to_str(), - version.to_str())]); + let package_dir = workspace_dir.path().join_many([~"src", + format!("{}-{}", + short_name.to_str(), + version.to_str())]); debug2!("Created {} and does it exist? {:?}", package_dir.display(), os::path_is_dir(&package_dir)); @@ -124,13 +124,13 @@ fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) { os::path_is_dir(&package_dir)); // Create main, lib, test, and bench files - writeFile(&package_dir.join_str("main.rs"), + writeFile(&package_dir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&package_dir.join_str("lib.rs"), + writeFile(&package_dir.join("lib.rs"), "pub fn f() { let _x = (); }"); - writeFile(&package_dir.join_str("test.rs"), + writeFile(&package_dir.join("test.rs"), "#[test] pub fn f() { (); }"); - writeFile(&package_dir.join_str("bench.rs"), + writeFile(&package_dir.join("bench.rs"), "#[bench] pub fn f() { (); }"); (workspace_dir, package_dir) } @@ -163,7 +163,7 @@ fn init_git_repo(p: &Path) -> TempDir { run_git([~"init"], None, &work_dir_for_opts, format!("Couldn't initialize git repository in {}", work_dir.display())); // Add stuff to the dir so that git tag succeeds - writeFile(&work_dir.join_str("README"), ""); + writeFile(&work_dir.join("README"), ""); run_git([~"add", ~"README"], None, &work_dir_for_opts, format!("Couldn't add in {}", work_dir.display())); git_commit(&work_dir_for_opts, ~"whatever"); @@ -232,13 +232,13 @@ fn test_sysroot() -> Path { // Returns the path to rustpkg fn rustpkg_exec() -> Path { // Ugh - let first_try = test_sysroot().join_many_str( + let first_try = test_sysroot().join_many( [~"lib", ~"rustc", host_triple(), ~"bin", ~"rustpkg"]); if is_executable(&first_try) { first_try } else { - let second_try = test_sysroot().join_many_str(["bin", "rustpkg"]); + let second_try = test_sysroot().join_many(["bin", "rustpkg"]); if is_executable(&second_try) { second_try } @@ -328,7 +328,7 @@ fn create_local_package(pkgid: &PkgId) -> TempDir { fn create_local_package_in(pkgid: &PkgId, pkgdir: &Path) -> Path { - let package_dir = pkgdir.join_many_str([~"src", pkgid.to_str()]); + let package_dir = pkgdir.join_many([~"src", pkgid.to_str()]); // Create main, lib, test, and bench files assert!(os::mkdir_recursive(&package_dir, U_RWX)); @@ -336,13 +336,13 @@ fn create_local_package_in(pkgid: &PkgId, pkgdir: &Path) -> Path { os::path_is_dir(&package_dir)); // Create main, lib, test, and bench files - writeFile(&package_dir.join_str("main.rs"), + writeFile(&package_dir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&package_dir.join_str("lib.rs"), + writeFile(&package_dir.join("lib.rs"), "pub fn f() { let _x = (); }"); - writeFile(&package_dir.join_str("test.rs"), + writeFile(&package_dir.join("test.rs"), "#[test] pub fn f() { (); }"); - writeFile(&package_dir.join_str("bench.rs"), + writeFile(&package_dir.join("bench.rs"), "#[bench] pub fn f() { (); }"); package_dir } @@ -356,11 +356,11 @@ fn create_local_package_with_dep(pkgid: &PkgId, subord_pkgid: &PkgId) -> TempDir let package_dir = create_local_package(pkgid); create_local_package_in(subord_pkgid, package_dir.path()); // Write a main.rs file into pkgid that references subord_pkgid - writeFile(&package_dir.path().join_many_str([~"src", pkgid.to_str(), ~"main.rs"]), + writeFile(&package_dir.path().join_many([~"src", pkgid.to_str(), ~"main.rs"]), format!("extern mod {};\nfn main() \\{\\}", subord_pkgid.short_name)); // Write a lib.rs file into subord_pkgid that has something in it - writeFile(&package_dir.path().join_many_str([~"src", subord_pkgid.to_str(), ~"lib.rs"]), + writeFile(&package_dir.path().join_many([~"src", subord_pkgid.to_str(), ~"lib.rs"]), "pub fn f() {}"); package_dir } @@ -452,7 +452,7 @@ fn llvm_bitcode_file_exists(repo: &Path, short_name: &str) -> bool { } fn file_exists(repo: &Path, short_name: &str, extension: &str) -> bool { - os::path_exists(&target_build_dir(repo).join_many_str([short_name.to_owned(), + os::path_exists(&target_build_dir(repo).join_many([short_name.to_owned(), format!("{}.{}", short_name, extension)])) } @@ -497,7 +497,7 @@ fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path { debug2!("lib_output_file_name: given {} and short name {}", workspace.display(), short_name); - library_in_workspace(&Path::from_str(short_name), + library_in_workspace(&Path::new(short_name), short_name, Build, workspace, @@ -506,13 +506,13 @@ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path { } fn output_file_name(workspace: &Path, short_name: ~str) -> Path { - target_build_dir(workspace).join_str(short_name).join_str(format!("{}{}", short_name, - os::EXE_SUFFIX)) + target_build_dir(workspace).join(short_name.as_slice()).join(format!("{}{}", short_name, + os::EXE_SUFFIX)) } fn touch_source_file(workspace: &Path, pkgid: &PkgId) { use conditions::bad_path::cond; - let pkg_src_dir = workspace.join_many_str([~"src", pkgid.to_str()]); + let pkg_src_dir = workspace.join_many([~"src", pkgid.to_str()]); let contents = os::list_dir_path(&pkg_src_dir); for p in contents.iter() { if p.extension_str() == Some("rs") { @@ -528,9 +528,9 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) { /// Add a comment at the end fn frob_source_file(workspace: &Path, pkgid: &PkgId, filename: &str) { use conditions::bad_path::cond; - let pkg_src_dir = workspace.join_many_str([~"src", pkgid.to_str()]); + let pkg_src_dir = workspace.join_many([~"src", pkgid.to_str()]); let mut maybe_p = None; - let maybe_file = pkg_src_dir.join_str(filename); + let maybe_file = pkg_src_dir.join(filename); debug2!("Trying to frob {} -- {}", pkg_src_dir.display(), filename); if os::path_exists(&maybe_file) { maybe_p = Some(maybe_file); @@ -552,7 +552,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId, filename: &str) { #[test] fn test_make_dir_rwx() { let temp = &os::tmpdir(); - let dir = temp.join_str("quux"); + let dir = temp.join("quux"); assert!(!os::path_exists(&dir) || os::remove_dir_recursive(&dir)); debug2!("Trying to make {}", dir.display()); @@ -630,16 +630,16 @@ fn test_install_git() { let repo = init_git_repo(&temp_pkg_id.path); let repo = repo.path(); debug2!("repo = {}", repo.display()); - let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test-pkg"]); + let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); debug2!("repo_subdir = {}", repo_subdir.display()); - writeFile(&repo_subdir.join_str("main.rs"), + writeFile(&repo_subdir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&repo_subdir.join_str("lib.rs"), + writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); - writeFile(&repo_subdir.join_str("test.rs"), + writeFile(&repo_subdir.join("test.rs"), "#[test] pub fn f() { (); }"); - writeFile(&repo_subdir.join_str("bench.rs"), + writeFile(&repo_subdir.join("bench.rs"), "#[bench] pub fn f() { (); }"); add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files @@ -648,7 +648,7 @@ fn test_install_git() { // should have test, bench, lib, and main // FIXME (#9639): This needs to handle non-utf8 paths command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); - let ws = repo.join_str(".rust"); + let ws = repo.join(".rust"); // Check that all files exist debug2!("Checking for files in {}", ws.display()); let exec = target_executable_in_workspace(&temp_pkg_id, &ws); @@ -705,12 +705,12 @@ fn test_package_ids_must_be_relative_path_like() { } do cond.trap(|(p, e)| { - let abs = os::make_absolute(&Path::from_str("foo/bar/quux")); + let abs = os::make_absolute(&Path::new("foo/bar/quux")); assert_eq!(p, abs); assert!("absolute pkgid" == e); whatever.clone() }).inside { - let zp = os::make_absolute(&Path::from_str("foo/bar/quux")); + let zp = os::make_absolute(&Path::new("foo/bar/quux")); // FIXME (#9639): This needs to handle non-utf8 paths let z = PkgId::new(zp.as_str().unwrap()); assert_eq!(~"foo-0.1", z.to_str()); @@ -721,17 +721,17 @@ fn test_package_ids_must_be_relative_path_like() { #[test] fn test_package_version() { let local_path = "mockgithub.com/catamorphism/test_pkg_version"; - let repo = init_git_repo(&Path::from_str(local_path)); + let repo = init_git_repo(&Path::new(local_path)); let repo = repo.path(); - let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test_pkg_version"]); + let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]); debug2!("Writing files in: {}", repo_subdir.display()); - writeFile(&repo_subdir.join_str("main.rs"), + writeFile(&repo_subdir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&repo_subdir.join_str("lib.rs"), + writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); - writeFile(&repo_subdir.join_str("test.rs"), + writeFile(&repo_subdir.join("test.rs"), "#[test] pub fn f() { (); }"); - writeFile(&repo_subdir.join_str("bench.rs"), + writeFile(&repo_subdir.join("bench.rs"), "#[bench] pub fn f() { (); }"); add_git_tag(&repo_subdir, ~"0.4"); @@ -740,7 +740,7 @@ fn test_package_version() { // This should look at the prefix, clone into a workspace, then build. command_line_test([~"install", ~"mockgithub.com/catamorphism/test_pkg_version"], repo); - let ws = repo.join_str(".rust"); + let ws = repo.join(".rust"); // we can still match on the filename to make sure it contains the 0.4 version assert!(match built_library_in_workspace(&temp_pkg_id, &ws) { @@ -751,36 +751,36 @@ fn test_package_version() { None => false }); assert!(built_executable_in_workspace(&temp_pkg_id, &ws) - == Some(target_build_dir(&ws).join_many_str(["mockgithub.com", - "catamorphism", - "test_pkg_version", - "test_pkg_version"]))); + == Some(target_build_dir(&ws).join_many(["mockgithub.com", + "catamorphism", + "test_pkg_version", + "test_pkg_version"]))); } #[test] fn test_package_request_version() { let local_path = "mockgithub.com/catamorphism/test_pkg_version"; - let repo = init_git_repo(&Path::from_str(local_path)); + let repo = init_git_repo(&Path::new(local_path)); let repo = repo.path(); - let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test_pkg_version"]); + let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]); debug2!("Writing files in: {}", repo_subdir.display()); - writeFile(&repo_subdir.join_str("main.rs"), + writeFile(&repo_subdir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&repo_subdir.join_str("lib.rs"), + writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); - writeFile(&repo_subdir.join_str("test.rs"), + writeFile(&repo_subdir.join("test.rs"), "#[test] pub fn f() { (); }"); - writeFile(&repo_subdir.join_str("bench.rs"), + writeFile(&repo_subdir.join("bench.rs"), "#[bench] pub fn f() { (); }"); - writeFile(&repo_subdir.join_str("version-0.3-file.txt"), "hi"); + writeFile(&repo_subdir.join("version-0.3-file.txt"), "hi"); add_git_tag(&repo_subdir, ~"0.3"); - writeFile(&repo_subdir.join_str("version-0.4-file.txt"), "hello"); + writeFile(&repo_subdir.join("version-0.4-file.txt"), "hello"); add_git_tag(&repo_subdir, ~"0.4"); command_line_test([~"install", format!("{}\\#0.3", local_path)], repo); - assert!(match installed_library_in_workspace(&Path::from_str("test_pkg_version"), - &repo.join_str(".rust")) { + assert!(match installed_library_in_workspace(&Path::new("test_pkg_version"), + &repo.join(".rust")) { Some(p) => { debug2!("installed: {}", p.display()); let suffix = format!("0.3{}", os::consts::DLL_SUFFIX); @@ -789,15 +789,15 @@ fn test_package_request_version() { None => false }); let temp_pkg_id = PkgId::new("mockgithub.com/catamorphism/test_pkg_version#0.3"); - assert!(target_executable_in_workspace(&temp_pkg_id, &repo.join_str(".rust")) - == repo.join_many_str([".rust", "bin", "test_pkg_version"])); + assert!(target_executable_in_workspace(&temp_pkg_id, &repo.join(".rust")) + == repo.join_many([".rust", "bin", "test_pkg_version"])); - let mut dir = target_build_dir(&repo.join_str(".rust")); - dir.push_path(&Path::from_str("src/mockgithub.com/catamorphism/test_pkg_version-0.3")); + let mut dir = target_build_dir(&repo.join(".rust")); + dir.push_path(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3")); debug2!("dir = {}", dir.display()); assert!(os::path_is_dir(&dir)); - assert!(os::path_exists(&dir.join_str("version-0.3-file.txt"))); - assert!(!os::path_exists(&dir.join_str("version-0.4-file.txt"))); + assert!(os::path_exists(&dir.join("version-0.3-file.txt"))); + assert!(!os::path_exists(&dir.join("version-0.4-file.txt"))); } #[test] @@ -810,23 +810,23 @@ fn rustpkg_install_url_2() { #[test] fn rustpkg_library_target() { - let foo_repo = init_git_repo(&Path::from_str("foo")); + let foo_repo = init_git_repo(&Path::new("foo")); let foo_repo = foo_repo.path(); - let package_dir = foo_repo.join_str("foo"); + let package_dir = foo_repo.join("foo"); debug2!("Writing files in: {}", package_dir.display()); - writeFile(&package_dir.join_str("main.rs"), + writeFile(&package_dir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&package_dir.join_str("lib.rs"), + writeFile(&package_dir.join("lib.rs"), "pub fn f() { let _x = (); }"); - writeFile(&package_dir.join_str("test.rs"), + writeFile(&package_dir.join("test.rs"), "#[test] pub fn f() { (); }"); - writeFile(&package_dir.join_str("bench.rs"), + writeFile(&package_dir.join("bench.rs"), "#[bench] pub fn f() { (); }"); add_git_tag(&package_dir, ~"1.0"); command_line_test([~"install", ~"foo"], foo_repo); - assert_lib_exists(&foo_repo.join_str(".rust"), &Path::from_str("foo"), ExactRevision(~"1.0")); + assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), ExactRevision(~"1.0")); } #[test] @@ -844,26 +844,25 @@ fn package_script_with_default_build() { debug2!("dir = {}", dir.display()); let mut source = test_sysroot().dir_path(); source.pop(); source.pop(); - source.push_many_str( - ["src", "librustpkg", "testsuite", "pass", "src", "fancy-lib", "pkg.rs"]); + source.push_many(["src", "librustpkg", "testsuite", "pass", "src", "fancy-lib", "pkg.rs"]); debug2!("package_script_with_default_build: {}", source.display()); if !os::copy_file(&source, - &dir.join_many_str(["src", "fancy-lib-0.1", "pkg.rs"])) { + &dir.join_many(["src", "fancy-lib-0.1", "pkg.rs"])) { fail2!("Couldn't copy file"); } command_line_test([~"install", ~"fancy-lib"], dir); - assert_lib_exists(dir, &Path::from_str("fancy-lib"), NoVersion); - assert!(os::path_exists(&target_build_dir(dir).join_many_str(["fancy-lib", "generated.rs"]))); + assert_lib_exists(dir, &Path::new("fancy-lib"), NoVersion); + assert!(os::path_exists(&target_build_dir(dir).join_many(["fancy-lib", "generated.rs"]))); } #[test] fn rustpkg_build_no_arg() { let tmp = TempDir::new("rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed"); - let tmp = tmp.path().join_str(".rust"); - let package_dir = tmp.join_many_str(["src", "foo"]); + let tmp = tmp.path().join(".rust"); + let package_dir = tmp.join_many(["src", "foo"]); assert!(os::mkdir_recursive(&package_dir, U_RWX)); - writeFile(&package_dir.join_str("main.rs"), + writeFile(&package_dir.join("main.rs"), "fn main() { let _x = (); }"); debug2!("build_no_arg: dir = {}", package_dir.display()); command_line_test([~"build"], &package_dir); @@ -873,24 +872,24 @@ fn rustpkg_build_no_arg() { #[test] fn rustpkg_install_no_arg() { let tmp = TempDir::new("rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed"); - let tmp = tmp.path().join_str(".rust"); - let package_dir = tmp.join_many_str(["src", "foo"]); + let tmp = tmp.path().join(".rust"); + let package_dir = tmp.join_many(["src", "foo"]); assert!(os::mkdir_recursive(&package_dir, U_RWX)); - writeFile(&package_dir.join_str("lib.rs"), + writeFile(&package_dir.join("lib.rs"), "fn main() { let _x = (); }"); debug2!("install_no_arg: dir = {}", package_dir.display()); command_line_test([~"install"], &package_dir); - assert_lib_exists(&tmp, &Path::from_str("foo"), NoVersion); + assert_lib_exists(&tmp, &Path::new("foo"), NoVersion); } #[test] fn rustpkg_clean_no_arg() { let tmp = TempDir::new("rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed"); - let tmp = tmp.path().join_str(".rust"); - let package_dir = tmp.join_many_str(["src", "foo"]); + let tmp = tmp.path().join(".rust"); + let package_dir = tmp.join_many(["src", "foo"]); assert!(os::mkdir_recursive(&package_dir, U_RWX)); - writeFile(&package_dir.join_str("main.rs"), + writeFile(&package_dir.join("main.rs"), "fn main() { let _x = (); }"); debug2!("clean_no_arg: dir = {}", package_dir.display()); command_line_test([~"build"], &package_dir); @@ -903,9 +902,9 @@ fn rustpkg_clean_no_arg() { #[test] fn rust_path_test() { let dir_for_path = TempDir::new("more_rust").expect("rust_path_test failed"); - let dir = mk_workspace(dir_for_path.path(), &Path::from_str("foo"), &NoVersion); + let dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion); debug2!("dir = {}", dir.display()); - writeFile(&dir.join_str("main.rs"), "fn main() { let _x = (); }"); + writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }"); let cwd = os::getcwd(); debug2!("cwd = {}", cwd.display()); @@ -921,16 +920,16 @@ fn rust_path_test() { #[ignore] // FIXME(#9184) tests can't change the cwd (other tests are sad then) fn rust_path_contents() { let dir = TempDir::new("rust_path").expect("rust_path_contents failed"); - let abc = &dir.path().join_many_str(["A", "B", "C"]); - assert!(os::mkdir_recursive(&abc.join_str(".rust"), U_RWX)); + let abc = &dir.path().join_many(["A", "B", "C"]); + assert!(os::mkdir_recursive(&abc.join(".rust"), U_RWX)); assert!(os::mkdir_recursive(&abc.with_filename(".rust"), U_RWX)); assert!(os::mkdir_recursive(&abc.dir_path().with_filename(".rust"), U_RWX)); assert!(os::change_dir(abc)); let p = rust_path(); - let cwd = os::getcwd().join_str(".rust"); - let parent = cwd.dir_path().with_filename_str(".rust"); - let grandparent = cwd.dir_path().dir_path().with_filename_str(".rust"); + let cwd = os::getcwd().join(".rust"); + let parent = cwd.dir_path().with_filename(".rust"); + let grandparent = cwd.dir_path().dir_path().with_filename(".rust"); assert!(p.contains(&cwd)); assert!(p.contains(&parent)); assert!(p.contains(&grandparent)); @@ -943,9 +942,9 @@ fn rust_path_contents() { fn rust_path_parse() { os::setenv("RUST_PATH", "/a/b/c:/d/e/f:/g/h/i"); let paths = rust_path(); - assert!(paths.contains(&Path::from_str("/g/h/i"))); - assert!(paths.contains(&Path::from_str("/d/e/f"))); - assert!(paths.contains(&Path::from_str("/a/b/c"))); + assert!(paths.contains(&Path::new("/g/h/i"))); + assert!(paths.contains(&Path::new("/d/e/f"))); + assert!(paths.contains(&Path::new("/a/b/c"))); os::unsetenv("RUST_PATH"); } @@ -1144,23 +1143,21 @@ fn test_non_numeric_tag() { let temp_pkg_id = git_repo_pkg(); let repo = init_git_repo(&temp_pkg_id.path); let repo = repo.path(); - let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test-pkg"]); - writeFile(&repo_subdir.join_str("foo"), "foo"); - writeFile(&repo_subdir.join_str("lib.rs"), + let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); + writeFile(&repo_subdir.join("foo"), "foo"); + writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); add_git_tag(&repo_subdir, ~"testbranch"); - writeFile(&repo_subdir.join_str("testbranch_only"), "hello"); + writeFile(&repo_subdir.join("testbranch_only"), "hello"); add_git_tag(&repo_subdir, ~"another_tag"); - writeFile(&repo_subdir.join_str("not_on_testbranch_only"), "bye bye"); + writeFile(&repo_subdir.join("not_on_testbranch_only"), "bye bye"); add_all_and_commit(&repo_subdir); // FIXME (#9639): This needs to handle non-utf8 paths command_line_test([~"install", format!("{}\\#testbranch", temp_pkg_id.path.as_str().unwrap())], repo); - let file1 = repo.join_many_str(["mockgithub.com", "catamorphism", - "test-pkg", "testbranch_only"]); - let file2 = repo.join_many_str(["mockgithub.com", "catamorphism", "test-pkg", - "master_only"]); + let file1 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "testbranch_only"]); + let file2 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "master_only"]); assert!(os::path_exists(&file1)); assert!(!os::path_exists(&file2)); } @@ -1169,13 +1166,12 @@ fn test_non_numeric_tag() { fn test_extern_mod() { let dir = TempDir::new("test_extern_mod").expect("test_extern_mod"); let dir = dir.path(); - let main_file = dir.join_str("main.rs"); + let main_file = dir.join("main.rs"); let lib_depend_dir = TempDir::new("foo").expect("test_extern_mod"); let lib_depend_dir = lib_depend_dir.path(); - let aux_dir = lib_depend_dir.join_many_str(["src", "mockgithub.com", "catamorphism", - "test_pkg"]); + let aux_dir = lib_depend_dir.join_many(["src", "mockgithub.com", "catamorphism", "test_pkg"]); assert!(os::mkdir_recursive(&aux_dir, U_RWX)); - let aux_pkg_file = aux_dir.join_str("lib.rs"); + let aux_pkg_file = aux_dir.join("lib.rs"); writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n"); assert!(os::path_exists(&aux_pkg_file)); @@ -1186,12 +1182,12 @@ fn test_extern_mod() { command_line_test([~"install", ~"mockgithub.com/catamorphism/test_pkg"], lib_depend_dir); - let exec_file = dir.join_str("out"); + let exec_file = dir.join("out"); // Be sure to extend the existing environment // FIXME (#9639): This needs to handle non-utf8 paths let env = Some([(~"RUST_PATH", lib_depend_dir.as_str().unwrap().to_owned())] + os::env()); let rustpkg_exec = rustpkg_exec(); - let rustc = rustpkg_exec.with_filename_str("rustc"); + let rustc = rustpkg_exec.with_filename("rustc"); let test_sys = test_sysroot(); // FIXME (#9639): This needs to handle non-utf8 paths @@ -1219,12 +1215,12 @@ fn test_extern_mod() { fn test_extern_mod_simpler() { let dir = TempDir::new("test_extern_mod_simpler").expect("test_extern_mod_simpler"); let dir = dir.path(); - let main_file = dir.join_str("main.rs"); + let main_file = dir.join("main.rs"); let lib_depend_dir = TempDir::new("foo").expect("test_extern_mod_simpler"); let lib_depend_dir = lib_depend_dir.path(); - let aux_dir = lib_depend_dir.join_many_str(["src", "rust-awesomeness"]); + let aux_dir = lib_depend_dir.join_many(["src", "rust-awesomeness"]); assert!(os::mkdir_recursive(&aux_dir, U_RWX)); - let aux_pkg_file = aux_dir.join_str("lib.rs"); + let aux_pkg_file = aux_dir.join("lib.rs"); writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n"); assert!(os::path_exists(&aux_pkg_file)); @@ -1235,12 +1231,12 @@ fn test_extern_mod_simpler() { command_line_test([~"install", ~"rust-awesomeness"], lib_depend_dir); - let exec_file = dir.join_str("out"); + let exec_file = dir.join("out"); // Be sure to extend the existing environment // FIXME (#9639): This needs to handle non-utf8 paths let env = Some([(~"RUST_PATH", lib_depend_dir.as_str().unwrap().to_owned())] + os::env()); let rustpkg_exec = rustpkg_exec(); - let rustc = rustpkg_exec.with_filename_str("rustc"); + let rustc = rustpkg_exec.with_filename("rustc"); let test_sys = test_sysroot(); debug2!("RUST_PATH={} {} {} \n --sysroot {} -o {}", lib_depend_dir.display(), @@ -1275,11 +1271,11 @@ fn test_import_rustpkg() { let p_id = PkgId::new("foo"); let workspace = create_local_package(&p_id); let workspace = workspace.path(); - writeFile(&workspace.join_many_str(["src", "foo-0.1", "pkg.rs"]), + writeFile(&workspace.join_many(["src", "foo-0.1", "pkg.rs"]), "extern mod rustpkg; fn main() {}"); command_line_test([~"build", ~"foo"], workspace); debug2!("workspace = {}", workspace.display()); - assert!(os::path_exists(&target_build_dir(workspace).join_str("foo").join_str(format!("pkg{}", + assert!(os::path_exists(&target_build_dir(workspace).join("foo").join(format!("pkg{}", os::EXE_SUFFIX)))); } @@ -1288,11 +1284,11 @@ fn test_macro_pkg_script() { let p_id = PkgId::new("foo"); let workspace = create_local_package(&p_id); let workspace = workspace.path(); - writeFile(&workspace.join_many_str(["src", "foo-0.1", "pkg.rs"]), + writeFile(&workspace.join_many(["src", "foo-0.1", "pkg.rs"]), "extern mod rustpkg; fn main() { debug2!(\"Hi\"); }"); command_line_test([~"build", ~"foo"], workspace); debug2!("workspace = {}", workspace.display()); - assert!(os::path_exists(&target_build_dir(workspace).join_str("foo").join_str(format!("pkg{}", + assert!(os::path_exists(&target_build_dir(workspace).join("foo").join(format!("pkg{}", os::EXE_SUFFIX)))); } @@ -1302,8 +1298,8 @@ fn multiple_workspaces() { // Copy the exact same package into directory B and install it // Set the RUST_PATH to A:B // Make a third package that uses foo, make sure we can build/install it - let (a_loc, _pkg_dir) = mk_temp_workspace(&Path::from_str("foo"), &NoVersion); - let (b_loc, _pkg_dir) = mk_temp_workspace(&Path::from_str("foo"), &NoVersion); + let (a_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion); + let (b_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion); let (a_loc, b_loc) = (a_loc.path(), b_loc.path()); debug2!("Trying to install foo in {}", a_loc.display()); command_line_test([~"install", ~"foo"], a_loc); @@ -1328,7 +1324,7 @@ fn rust_path_hack_test(hack_flag: bool) { let p_id = PkgId::new("foo"); let workspace = create_local_package(&p_id); let workspace = workspace.path(); - let dest_workspace = mk_empty_workspace(&Path::from_str("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); let rust_path = Some(~[(~"RUST_PATH", format!("{}:{}", @@ -1336,11 +1332,11 @@ fn rust_path_hack_test(hack_flag: bool) { foo_path.as_str().unwrap()))]); command_line_test_with_env(~[~"install"] + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } + ~[~"foo"], dest_workspace, rust_path); - assert_lib_exists(dest_workspace, &Path::from_str("foo"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion); assert_executable_exists(dest_workspace, "foo"); assert_built_library_exists(dest_workspace, "foo"); assert_built_executable_exists(dest_workspace, "foo"); - assert!(!lib_exists(workspace, &Path::from_str("foo"), NoVersion)); + assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion)); assert!(!executable_exists(workspace, "foo")); assert!(!built_library_exists(workspace, "foo")); assert!(!built_executable_exists(workspace, "foo")); @@ -1369,19 +1365,19 @@ fn test_rust_path_can_contain_package_dirs_without_flag() { fn rust_path_hack_cwd() { // Same as rust_path_hack_test, but the CWD is the dir to build out of let cwd = TempDir::new("foo").expect("rust_path_hack_cwd"); - let cwd = cwd.path().join_str("foo"); + let cwd = cwd.path().join("foo"); assert!(os::mkdir_recursive(&cwd, U_RWX)); - writeFile(&cwd.join_str("lib.rs"), "pub fn f() { }"); + writeFile(&cwd.join("lib.rs"), "pub fn f() { }"); - let dest_workspace = mk_empty_workspace(&Path::from_str("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path); debug2!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::from_str("foo"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion); assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&cwd, &Path::from_str("foo"), NoVersion)); + assert!(!lib_exists(&cwd, &Path::new("foo"), NoVersion)); assert!(!built_library_exists(&cwd, "foo")); } @@ -1389,20 +1385,20 @@ fn rust_path_hack_cwd() { fn rust_path_hack_multi_path() { // Same as rust_path_hack_test, but with a more complex package ID let cwd = TempDir::new("pkg_files").expect("rust_path_hack_cwd"); - let subdir = cwd.path().join_many_str(["foo", "bar", "quux"]); + let subdir = cwd.path().join_many(["foo", "bar", "quux"]); assert!(os::mkdir_recursive(&subdir, U_RWX)); - writeFile(&subdir.join_str("lib.rs"), "pub fn f() { }"); + writeFile(&subdir.join("lib.rs"), "pub fn f() { }"); let name = ~"foo/bar/quux"; - let dest_workspace = mk_empty_workspace(&Path::from_str("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path); debug2!("Checking that {} exists in {}", name, dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::from_str("quux"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("quux"), NoVersion); assert_built_library_exists(dest_workspace, name); - assert!(!lib_exists(&subdir, &Path::from_str("quux"), NoVersion)); + assert!(!lib_exists(&subdir, &Path::new("quux"), NoVersion)); assert!(!built_library_exists(&subdir, name)); } @@ -1411,19 +1407,19 @@ fn rust_path_hack_install_no_arg() { // Same as rust_path_hack_cwd, but making rustpkg infer the pkg id let cwd = TempDir::new("pkg_files").expect("rust_path_hack_install_no_arg"); let cwd = cwd.path(); - let source_dir = cwd.join_str("foo"); + let source_dir = cwd.join("foo"); assert!(make_dir_rwx(&source_dir)); - writeFile(&source_dir.join_str("lib.rs"), "pub fn f() { }"); + writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); - let dest_workspace = mk_empty_workspace(&Path::from_str("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path); debug2!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::from_str("foo"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion); assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&source_dir, &Path::from_str("foo"), NoVersion)); + assert!(!lib_exists(&source_dir, &Path::new("foo"), NoVersion)); assert!(!built_library_exists(cwd, "foo")); } @@ -1431,11 +1427,11 @@ fn rust_path_hack_install_no_arg() { fn rust_path_hack_build_no_arg() { // Same as rust_path_hack_install_no_arg, but building instead of installing let cwd = TempDir::new("pkg_files").expect("rust_path_hack_build_no_arg"); - let source_dir = cwd.path().join_str("foo"); + let source_dir = cwd.path().join("foo"); assert!(make_dir_rwx(&source_dir)); - writeFile(&source_dir.join_str("lib.rs"), "pub fn f() { }"); + writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); - let dest_workspace = mk_empty_workspace(&Path::from_str("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); @@ -1449,9 +1445,9 @@ fn rust_path_hack_build_no_arg() { fn rust_path_install_target() { let dir_for_path = TempDir::new( "source_workspace").expect("rust_path_install_target failed"); - let mut dir = mk_workspace(dir_for_path.path(), &Path::from_str("foo"), &NoVersion); + let mut dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion); debug2!("dir = {}", dir.display()); - writeFile(&dir.join_str("main.rs"), "fn main() { let _x = (); }"); + writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }"); let dir_to_install_to = TempDir::new( "dest_workspace").expect("rust_path_install_target failed"); let dir_to_install_to = dir_to_install_to.path(); @@ -1561,7 +1557,7 @@ fn notrans_flag_fail() { workspace, None, BAD_FLAG_CODE); assert!(!built_executable_exists(workspace, "foo")); assert!(!object_file_exists(workspace, "foo")); - assert!(!lib_exists(workspace, &Path::from_str("foo"), NoVersion)); + assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion)); } } @@ -1605,7 +1601,7 @@ fn test_cfg_build() { let workspace = create_local_package(&p_id); let workspace = workspace.path(); // If the cfg flag gets messed up, this won't compile - writeFile(&workspace.join_many_str(["src", "foo-0.1", "main.rs"]), + writeFile(&workspace.join_many(["src", "foo-0.1", "main.rs"]), "#[cfg(quux)] fn main() {}"); let test_sys = test_sysroot(); // FIXME (#9639): This needs to handle non-utf8 paths @@ -1623,7 +1619,7 @@ fn test_cfg_fail() { let p_id = PkgId::new("foo"); let workspace = create_local_package(&p_id); let workspace = workspace.path(); - writeFile(&workspace.join_many_str(["src", "foo-0.1", "main.rs"]), + writeFile(&workspace.join_many(["src", "foo-0.1", "main.rs"]), "#[cfg(quux)] fn main() {}"); let test_sys = test_sysroot(); // FIXME (#9639): This needs to handle non-utf8 paths @@ -1780,23 +1776,23 @@ fn pkgid_pointing_to_subdir() { // rustpkg should recognize that and treat the part after some_repo/ as a subdir let workspace = TempDir::new("parent_repo").expect("Couldn't create temp dir"); let workspace = workspace.path(); - assert!(os::mkdir_recursive(&workspace.join_many_str(["src", "mockgithub.com", - "mozilla", "some_repo"]), U_RWX)); + assert!(os::mkdir_recursive(&workspace.join_many(["src", "mockgithub.com", + "mozilla", "some_repo"]), U_RWX)); - let foo_dir = workspace.join_many_str(["src", "mockgithub.com", "mozilla", "some_repo", - "extras", "foo"]); - let bar_dir = workspace.join_many_str(["src", "mockgithub.com", "mozilla", "some_repo", - "extras", "bar"]); + let foo_dir = workspace.join_many(["src", "mockgithub.com", "mozilla", "some_repo", + "extras", "foo"]); + let bar_dir = workspace.join_many(["src", "mockgithub.com", "mozilla", "some_repo", + "extras", "bar"]); assert!(os::mkdir_recursive(&foo_dir, U_RWX)); assert!(os::mkdir_recursive(&bar_dir, U_RWX)); - writeFile(&foo_dir.join_str("lib.rs"), "pub fn f() {}"); - writeFile(&bar_dir.join_str("lib.rs"), "pub fn g() {}"); + writeFile(&foo_dir.join("lib.rs"), "pub fn f() {}"); + writeFile(&bar_dir.join("lib.rs"), "pub fn g() {}"); debug2!("Creating a file in {}", workspace.display()); - let testpkg_dir = workspace.join_many_str(["src", "testpkg-0.1"]); + let testpkg_dir = workspace.join_many(["src", "testpkg-0.1"]); assert!(os::mkdir_recursive(&testpkg_dir, U_RWX)); - writeFile(&testpkg_dir.join_str("main.rs"), + writeFile(&testpkg_dir.join("main.rs"), "extern mod foo = \"mockgithub.com/mozilla/some_repo/extras/foo\";\n extern mod bar = \"mockgithub.com/mozilla/some_repo/extras/bar\";\n use foo::f; use bar::g; \n @@ -1813,13 +1809,13 @@ fn test_recursive_deps() { let c_id = PkgId::new("c"); let b_workspace = create_local_package_with_dep(&b_id, &c_id); let b_workspace = b_workspace.path(); - writeFile(&b_workspace.join_many_str(["src", "c-0.1", "lib.rs"])), + writeFile(&b_workspace.join_many(["src", "c-0.1", "lib.rs"])), "pub fn g() {}"); let a_workspace = create_local_package(&a_id); let a_workspace = a_workspace.path(); - writeFile(&a_workspace.join_many_str(["src", "a-0.1", "main.rs"]), + writeFile(&a_workspace.join_many(["src", "a-0.1", "main.rs"]), "extern mod b; use b::f; fn main() { f(); }"); - writeFile(&b_workspace.join_many_str(["src", "b-0.1", "lib.rs"]), + writeFile(&b_workspace.join_many(["src", "b-0.1", "lib.rs"]), "extern mod c; use c::g; pub fn f() { g(); }"); // FIXME (#9639): This needs to handle non-utf8 paths let environment = Some(~[(~"RUST_PATH", b_workspace.as_str().unwrap().to_owned())]); @@ -1827,9 +1823,9 @@ fn test_recursive_deps() { command_line_test_with_env([~"install", ~"a"], a_workspace, environment); - assert_lib_exists(a_workspace, &Path::from_str("a"), NoVersion); - assert_lib_exists(b_workspace, &Path::from_str("b"), NoVersion); - assert_lib_exists(b_workspace, &Path::from_str("c"), NoVersion); + assert_lib_exists(a_workspace, &Path::new("a"), NoVersion); + assert_lib_exists(b_workspace, &Path::new("b"), NoVersion); + assert_lib_exists(b_workspace, &Path::new("c"), NoVersion); } #[test] @@ -1837,7 +1833,7 @@ fn test_install_to_rust_path() { let p_id = PkgId::new("foo"); let second_workspace = create_local_package(&p_id); let second_workspace = second_workspace.path(); - let first_workspace = mk_empty_workspace(&Path::from_str("p"), &NoVersion, "dest"); + let first_workspace = mk_empty_workspace(&Path::new("p"), &NoVersion, "dest"); let first_workspace = first_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", @@ -1869,7 +1865,7 @@ fn test_target_specific_build_dir() { workspace); assert!(os::path_is_dir(&target_build_dir(workspace))); assert!(built_executable_exists(workspace, "foo")); - assert!(os::list_dir(&workspace.join_str("build")).len() == 1); + assert!(os::list_dir(&workspace.join("build")).len() == 1); } #[test] @@ -1883,10 +1879,10 @@ fn test_target_specific_install_dir() { ~"install", ~"foo"], workspace); - assert!(os::path_is_dir(&workspace.join_many_str(["lib", host_triple()]))); - assert_lib_exists(workspace, &Path::from_str("foo"), NoVersion); - assert!(os::list_dir(&workspace.join_str("lib")).len() == 1); - assert!(os::path_is_dir(&workspace.join_str("bin"))); + assert!(os::path_is_dir(&workspace.join_many(["lib", host_triple()]))); + assert_lib_exists(workspace, &Path::new("foo"), NoVersion); + assert!(os::list_dir(&workspace.join("lib")).len() == 1); + assert!(os::path_is_dir(&workspace.join("bin"))); assert_executable_exists(workspace, "foo"); } @@ -1896,10 +1892,10 @@ fn test_dependencies_terminate() { let b_id = PkgId::new("b"); let workspace = create_local_package(&b_id); let workspace = workspace.path(); - let b_dir = workspace.join_many_str(["src", "b-0.1"]); - let b_subdir = b_dir.join_str("test"); + let b_dir = workspace.join_many(["src", "b-0.1"]); + let b_subdir = b_dir.join("test"); assert!(os::mkdir_recursive(&b_subdir, U_RWX)); - writeFile(&b_subdir.join_str("test.rs"), + writeFile(&b_subdir.join("test.rs"), "extern mod b; use b::f; #[test] fn g() { f() }"); command_line_test([~"install", ~"b"], workspace); } @@ -1960,13 +1956,13 @@ fn correct_package_name_with_rust_path_hack() { let bar_id = PkgId::new("bar"); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - let dest_workspace = mk_empty_workspace(&Path::from_str("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); - writeFile(&dest_workspace.join_many_str(["src", "bar-0.1", "main.rs"]), + writeFile(&dest_workspace.join_many(["src", "bar-0.1", "main.rs"]), "extern mod blat; fn main() { let _x = (); }"); - let foo_path = foo_workspace.join_many_str(["src", "foo-0.1"]); + let foo_path = foo_workspace.join_many(["src", "foo-0.1"]); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", format!("{}:{}", dest_workspace.as_str().unwrap(), foo_path.as_str().unwrap()))]); @@ -1989,7 +1985,7 @@ fn test_rustpkg_test_creates_exec() { let foo_id = PkgId::new("foo"); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - writeFile(&foo_workspace.join_many_str(["src", "foo-0.1", "test.rs"]), + writeFile(&foo_workspace.join_many(["src", "foo-0.1", "test.rs"]), "#[test] fn f() { assert!('a' == 'a'); }"); command_line_test([~"test", ~"foo"], foo_workspace); assert!(test_executable_exists(foo_workspace, "foo")); @@ -2013,7 +2009,7 @@ fn test_rebuild_when_needed() { let foo_id = PkgId::new("foo"); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - let test_crate = foo_workspace.join_many_str(["src", "foo-0.1", "test.rs"]); + let test_crate = foo_workspace.join_many(["src", "foo-0.1", "test.rs"]); writeFile(&test_crate, "#[test] fn f() { assert!('a' == 'a'); }"); command_line_test([~"test", ~"foo"], foo_workspace); assert!(test_executable_exists(foo_workspace, "foo")); @@ -2033,7 +2029,7 @@ fn test_no_rebuilding() { let foo_id = PkgId::new("foo"); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - let test_crate = foo_workspace.join_many_str(["src", "foo-0.1", "test.rs"]); + let test_crate = foo_workspace.join_many(["src", "foo-0.1", "test.rs"]); writeFile(&test_crate, "#[test] fn f() { assert!('a' == 'a'); }"); command_line_test([~"test", ~"foo"], foo_workspace); assert!(test_executable_exists(foo_workspace, "foo")); @@ -2058,16 +2054,16 @@ fn test_installed_read_only() { let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test-pkg"]); debug2!("repo_subdir = {}", repo_subdir.display()); - writeFile(&repo_subdir.join_str("main.rs"), + writeFile(&repo_subdir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&repo_subdir.join_str("lib.rs"), + writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files // FIXME (#9639): This needs to handle non-utf8 paths command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); - let ws = repo.join_str(".rust"); + let ws = repo.join(".rust"); // Check that all files exist debug2!("Checking for files in {}", ws.display()); let exec = target_executable_in_workspace(&temp_pkg_id, &ws); @@ -2099,9 +2095,9 @@ fn test_installed_local_changes() { debug2!("repo_subdir = {}", repo_subdir.display()); assert!(os::mkdir_recursive(&repo.join_many_str([".rust", "src"]), U_RWX)); - writeFile(&repo_subdir.join_str("main.rs"), + writeFile(&repo_subdir.join("main.rs"), "fn main() { let _x = (); }"); - writeFile(&repo_subdir.join_str("lib.rs"), + writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files @@ -2127,13 +2123,13 @@ fn test_installed_local_changes() { }; // Make a local change to it - writeFile(&target_dir.join_str("lib.rs"), + writeFile(&target_dir.join("lib.rs"), "pub fn g() { let _x = (); }"); // Finally, make *another* package that uses it let importer_pkg_id = fake_pkg(); let main_subdir = create_local_package_in(&importer_pkg_id, hacking_workspace); - writeFile(&main_subdir.join_str("main.rs"), + writeFile(&main_subdir.join("main.rs"), "extern mod test = \"mockgithub.com/catamorphism/test-pkg\"; \ use test::g; fn main() { g(); }"); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 14de18734ed..c5e81e6dc4a 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -467,8 +467,7 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> { self.context.context.use_rust_path_hack, pkg_id); let (outputs_disc, inputs_disc) = - self.context.install(pkg_src, - &JustOne(Path::from_str(lib_crate_filename))); + self.context.install(pkg_src, &JustOne(Path::new(lib_crate_filename))); debug2!("Installed {}, returned {:?} dependencies and \ {:?} transitive dependencies", lib_name, outputs_disc.len(), inputs_disc.len()); @@ -492,12 +491,13 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> { self.exec.discover_input(*what, *dep, digest_file_with_date( - &Path::from_str(*dep))); + &Path::new(dep.as_slice()))); } else if *what == ~"binary" { self.exec.discover_input(*what, *dep, - digest_only_date(&Path::from_str(*dep))); + digest_only_date( + &Path::new(dep.as_slice()))); } else { fail2!("Bad kind: {}", *what); diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index d0c76498c62..21abeeb03e3 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -99,7 +99,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option { let rustpath = rust_path(); for rp in rustpath.iter() { let local_path = rp.join_path(local_path); - let git_dir = local_path.join_str(".git"); + let git_dir = local_path.join(".git"); if !os::path_is_dir(&git_dir) { continue; } @@ -148,7 +148,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option { str::from_utf8(outp.output), str::from_utf8(outp.error)); let mut output = None; - let git_dir = tmp_dir.join_str(".git"); + let git_dir = tmp_dir.join(".git"); debug2!("(getting version, now getting tags) executing \\{git --git-dir={} tag -l\\}", git_dir.display()); // FIXME (#9639): This needs to handle non-utf8 paths diff --git a/src/librustpkg/workspace.rs b/src/librustpkg/workspace.rs index 15f9760a637..b4c2a66c1aa 100644 --- a/src/librustpkg/workspace.rs +++ b/src/librustpkg/workspace.rs @@ -52,7 +52,7 @@ pub fn pkg_parent_workspaces(cx: &Context, pkgid: &PkgId) -> ~[Path] { } pub fn is_workspace(p: &Path) -> bool { - os::path_is_dir(&p.join_str("src")) + os::path_is_dir(&p.join("src")) } /// Construct a workspace and package-ID name based on the current directory. @@ -60,7 +60,7 @@ pub fn is_workspace(p: &Path) -> bool { pub fn cwd_to_workspace() -> Option<(Path, PkgId)> { let cwd = os::getcwd(); for path in rust_path().move_iter() { - let srcpath = path.join_str("src"); + let srcpath = path.join("src"); if srcpath.is_ancestor_of(&cwd) { let rel = cwd.path_relative_from(&srcpath); let rel_s = rel.and_then_ref(|p|p.as_str()); diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 434d781805b..c03fc6d7ffb 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1893,7 +1893,7 @@ mod tests { #[test] fn test_simple() { - let tmpfile = &Path::from_str("tmp/lib-io-test-simple.tmp"); + let tmpfile = &Path::new("tmp/lib-io-test-simple.tmp"); debug2!("{}", tmpfile.display()); let frood: ~str = ~"A hoopy frood who really knows where his towel is."; @@ -1911,7 +1911,7 @@ mod tests { #[test] fn test_each_byte_each_char_file() { // Issue #5056 -- shouldn't include trailing EOF. - let path = Path::from_str("tmp/lib-io-test-each-byte-each-char-file.tmp"); + let path = Path::new("tmp/lib-io-test-each-byte-each-char-file.tmp"); { // create empty, enough to reproduce a problem @@ -2011,7 +2011,7 @@ mod tests { #[test] fn file_reader_not_exist() { - match io::file_reader(&Path::from_str("not a file")) { + match io::file_reader(&Path::new("not a file")) { Err(e) => { assert_eq!(e, ~"error opening not a file"); } @@ -2022,7 +2022,7 @@ mod tests { #[test] #[should_fail] fn test_read_buffer_too_small() { - let path = &Path::from_str("tmp/lib-io-test-read-buffer-too-small.tmp"); + let path = &Path::new("tmp/lib-io-test-read-buffer-too-small.tmp"); // ensure the file exists io::file_writer(path, [io::Create]).unwrap(); @@ -2033,7 +2033,7 @@ mod tests { #[test] fn test_read_buffer_big_enough() { - let path = &Path::from_str("tmp/lib-io-test-read-buffer-big-enough.tmp"); + let path = &Path::new("tmp/lib-io-test-read-buffer-big-enough.tmp"); // ensure the file exists io::file_writer(path, [io::Create]).unwrap(); @@ -2044,14 +2044,14 @@ mod tests { #[test] fn test_write_empty() { - let file = io::file_writer(&Path::from_str("tmp/lib-io-test-write-empty.tmp"), + let file = io::file_writer(&Path::new("tmp/lib-io-test-write-empty.tmp"), [io::Create]).unwrap(); file.write([]); } #[test] fn file_writer_bad_name() { - match io::file_writer(&Path("?/?"), []) { + match io::file_writer(&Path::new("?/?"), []) { Err(e) => { assert!(e.starts_with("error opening")); } @@ -2076,7 +2076,7 @@ mod tests { #[test] fn test_read_write_le() { - let path = Path::from_str("tmp/lib-io-test-read-write-le.tmp"); + let path = Path::new("tmp/lib-io-test-read-write-le.tmp"); let uints = [0, 1, 2, 42, 10_123, 100_123_456, u64::max_value]; // write the ints to the file @@ -2098,7 +2098,7 @@ mod tests { #[test] fn test_read_write_be() { - let path = Path::from_str("tmp/lib-io-test-read-write-be.tmp"); + let path = Path::new("tmp/lib-io-test-read-write-be.tmp"); let uints = [0, 1, 2, 42, 10_123, 100_123_456, u64::max_value]; // write the ints to the file @@ -2120,7 +2120,7 @@ mod tests { #[test] fn test_read_be_int_n() { - let path = Path::from_str("tmp/lib-io-test-read-be-int-n.tmp"); + let path = Path::new("tmp/lib-io-test-read-be-int-n.tmp"); let ints = [i32::min_value, -123456, -42, -5, 0, 1, i32::max_value]; // write the ints to the file @@ -2144,7 +2144,7 @@ mod tests { #[test] fn test_read_f32() { - let path = Path::from_str("tmp/lib-io-test-read-f32.tmp"); + let path = Path::new("tmp/lib-io-test-read-f32.tmp"); //big-endian floating-point 8.1250 let buf = ~[0x41, 0x02, 0x00, 0x00]; @@ -2162,7 +2162,7 @@ mod tests { #[test] fn test_read_write_f32() { - let path = Path::from_str("tmp/lib-io-test-read-write-f32.tmp"); + let path = Path::new("tmp/lib-io-test-read-write-f32.tmp"); let f:f32 = 8.1250; { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index bfde1a86771..449888b4e2a 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -513,7 +513,7 @@ pub fn self_exe_path() -> Option { } } - load_self().and_then(|path| Path::from_vec_opt(path).map(|p| p.dir_path())) + load_self().and_then(|path| Path::new_opt(path).map(|p| { p.pop(); p })) } @@ -538,7 +538,7 @@ pub fn self_exe_path() -> Option { pub fn homedir() -> Option { // FIXME (#7188): getenv needs a ~[u8] variant return match getenv("HOME") { - Some(ref p) if !p.is_empty() => Path::from_str_opt(*p), + Some(ref p) if !p.is_empty() => Path::new_opt(p.as_slice()), _ => secondary() }; @@ -551,7 +551,7 @@ pub fn homedir() -> Option { fn secondary() -> Option { do getenv("USERPROFILE").and_then |p| { if !p.is_empty() { - Path::from_str_opt(p) + Path::new_opt(p) } else { None } @@ -580,7 +580,7 @@ pub fn tmpdir() -> Path { if x.is_empty() { None } else { - Path::from_str_opt(x) + Path::new_opt(x) }, _ => None } @@ -589,9 +589,9 @@ pub fn tmpdir() -> Path { #[cfg(unix)] fn lookup() -> Path { if cfg!(target_os = "android") { - Path::from_str("/data/tmp") + Path::new("/data/tmp") } else { - getenv_nonempty("TMPDIR").unwrap_or(Path::from_str("/tmp")) + getenv_nonempty("TMPDIR").unwrap_or(Path::new("/tmp")) } } @@ -600,7 +600,7 @@ pub fn tmpdir() -> Path { getenv_nonempty("TMP").or( getenv_nonempty("TEMP").or( getenv_nonempty("USERPROFILE").or( - getenv_nonempty("WINDIR")))).unwrap_or(Path::from_str("C:\\Windows")) + getenv_nonempty("WINDIR")))).unwrap_or(Path::new("C:\\Windows")) } } @@ -762,7 +762,7 @@ pub fn list_dir(p: &Path) -> ~[Path] { fn rust_list_dir_wfd_size() -> libc::size_t; fn rust_list_dir_wfd_fp_buf(wfd: *libc::c_void) -> *u16; } - let star = p.join_str("*"); + let star = p.join("*"); do as_utf16_p(star.as_str().unwrap()) |path_ptr| { let mut paths = ~[]; let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint); @@ -778,7 +778,7 @@ pub fn list_dir(p: &Path) -> ~[Path] { let fp_vec = vec::from_buf( fp_buf, wcslen(fp_buf) as uint); let fp_str = str::from_utf16(fp_vec); - paths.push(Path::from_str(fp_str)); + paths.push(Path::new(fp_str)); } more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE); } @@ -1830,13 +1830,13 @@ mod tests { #[test] fn test() { - assert!((!Path::from_str("test-path").is_absolute())); + assert!((!Path::new("test-path").is_absolute())); let cwd = getcwd(); debug2!("Current working directory: {}", cwd.display()); - debug2!("{:?}", make_absolute(&Path::from_str("test-path"))); - debug2!("{:?}", make_absolute(&Path::from_str("/usr/bin"))); + debug2!("{:?}", make_absolute(&Path::new("test-path"))); + debug2!("{:?}", make_absolute(&Path::new("/usr/bin"))); } #[test] @@ -1845,7 +1845,7 @@ mod tests { let oldhome = getenv("HOME"); setenv("HOME", "/home/MountainView"); - assert_eq!(os::homedir(), Some(Path::from_str("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); setenv("HOME", ""); assert!(os::homedir().is_none()); @@ -1866,16 +1866,16 @@ mod tests { assert!(os::homedir().is_none()); setenv("HOME", "/home/MountainView"); - assert_eq!(os::homedir(), Some(Path::from_str("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); setenv("HOME", ""); setenv("USERPROFILE", "/home/MountainView"); - assert_eq!(os::homedir(), Some(Path::from_str("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); setenv("HOME", "/home/MountainView"); setenv("USERPROFILE", "/home/PaloAlto"); - assert_eq!(os::homedir(), Some(Path::from_str("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); for s in oldhome.iter() { setenv("HOME", *s) } for s in olduserprofile.iter() { setenv("USERPROFILE", *s) } @@ -1891,12 +1891,12 @@ mod tests { // Issue #712 #[test] fn test_list_dir_no_invalid_memory_access() { - os::list_dir(&Path::from_str(".")); + os::list_dir(&Path::new(".")); } #[test] fn list_dir() { - let dirs = os::list_dir(&Path::from_str(".")); + let dirs = os::list_dir(&Path::new(".")); // Just assuming that we've got some contents in the current directory assert!(dirs.len() > 0u); @@ -1908,35 +1908,35 @@ mod tests { #[test] #[cfg(not(windows))] fn list_dir_root() { - let dirs = os::list_dir(&Path::from_str("/")); + let dirs = os::list_dir(&Path::new("/")); assert!(dirs.len() > 1); } #[test] #[cfg(windows)] fn list_dir_root() { - let dirs = os::list_dir(&Path::from_str("C:\\")); + let dirs = os::list_dir(&Path::new("C:\\")); assert!(dirs.len() > 1); } #[test] fn path_is_dir() { - assert!((os::path_is_dir(&Path::from_str(".")))); - assert!((!os::path_is_dir(&Path::from_str("test/stdtest/fs.rs")))); + assert!((os::path_is_dir(&Path::new(".")))); + assert!((!os::path_is_dir(&Path::new("test/stdtest/fs.rs")))); } #[test] fn path_exists() { - assert!((os::path_exists(&Path::from_str(".")))); - assert!((!os::path_exists(&Path::from_str( + assert!((os::path_exists(&Path::new(".")))); + assert!((!os::path_exists(&Path::new( "test/nonexistent-bogus-path")))); } #[test] fn copy_file_does_not_exist() { - assert!(!os::copy_file(&Path::from_str("test/nonexistent-bogus-path"), - &Path::from_str("test/other-bogus-path"))); - assert!(!os::path_exists(&Path::from_str("test/other-bogus-path"))); + assert!(!os::copy_file(&Path::new("test/nonexistent-bogus-path"), + &Path::new("test/other-bogus-path"))); + assert!(!os::path_exists(&Path::new("test/other-bogus-path"))); } #[test] @@ -1946,8 +1946,8 @@ mod tests { unsafe { let tempdir = getcwd(); // would like to use $TMPDIR, // doesn't seem to work on Linux - let input = tempdir.join_str("in.txt"); - let out = tempdir.join_str("out.txt"); + let input = tempdir.join("in.txt"); + let out = tempdir.join("out.txt"); /* Write the temp input file */ let ostream = do input.with_c_str |fromp| { @@ -1983,7 +1983,7 @@ mod tests { #[test] fn recursive_mkdir_slash() { - let path = Path::from_str("/"); + let path = Path::new("/"); assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); } @@ -2032,7 +2032,7 @@ mod tests { } let mut path = tmpdir(); - path.push_str("mmap_file.tmp"); + path.push("mmap_file.tmp"); let size = MemoryMap::granularity() * 2; remove_file(&path); diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 1ecb31a2a87..561155f2258 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -20,8 +20,7 @@ appropriate platform-specific path variant. Both `PosixPath` and `WindowsPath` implement a trait `GenericPath`, which contains the set of methods that behave the same for both paths. They each also implement some methods that could not be expressed in `GenericPath`, yet behave -identically for both path flavors, such as `::from_str()` or -`.component_iter()`. +identically for both path flavors, such as `.component_iter()`. The three main design goals of this module are 1) to avoid unnecessary allocation, 2) to behave the same regardless of which flavor of path is being @@ -35,8 +34,8 @@ code, `Path` should be used to refer to the platform-native path, and methods used should be restricted to those defined in `GenericPath`, and those methods that are declared identically on both `PosixPath` and `WindowsPath`. -Creation of a path is typically done with either `Path::from_str(some_str)` or -`Path::from_vec(some_vec)`. This path can be modified with `.push()` and +Creation of a path is typically done with either `Path::new(some_str)` or +`Path::new(some_vec)`. This path can be modified with `.push()` and `.pop()` (and other setters). The resulting Path can either be passed to another API that expects a path, or can be turned into a &[u8] with `.as_vec()` or a Option<&str> with `.as_str()`. Similarly, attributes of the path can be queried @@ -44,10 +43,10 @@ with methods such as `.filename()`. There are also methods that return a new path instead of modifying the receiver, such as `.join()` or `.dir_path()`. Paths are always kept in normalized form. This means that creating the path -`Path::from_str("a/b/../c")` will return the path `a/c`. Similarly any attempt +`Path::new("a/b/../c")` will return the path `a/c`. Similarly any attempt to mutate the path will always leave it in normalized form. -When rendering a path to some form of display, there is a method `.display()` +When rendering a path to some form of output, there is a method `.display()` which is compatible with the `format!()` parameter `{}`. This will render the path as a string, replacing all non-utf8 sequences with the Replacement Character (U+FFFD). As such it is not suitable for passing to any API that @@ -56,10 +55,10 @@ actually operates on the path; it is only intended for display. ## Example ```rust -let mut path = Path::from_str("/tmp/path"); +let mut path = Path::new("/tmp/path"); debug2!("path: {}", path.display()); -path.set_filename_str("foo"); -path.push_str("bar"); +path.set_filename("foo"); +path.push("bar"); debug2!("new path: {}", path.display()); let b = std::os::path_exists(&path); debug2!("path exists: {}", b); @@ -70,6 +69,7 @@ debug2!("path exists: {}", b); use container::Container; use c_str::CString; use clone::Clone; +use either::{Left, Right}; use fmt; use iter::Iterator; use option::{Option, None, Some}; @@ -131,7 +131,7 @@ condition! { /// A trait that represents the generic operations available on paths pub trait GenericPath: Clone + GenericPathUnsafe { - /// Creates a new Path from a byte vector. + /// Creates a new Path from a byte vector or string. /// The resulting Path will always be normalized. /// /// # Failure @@ -140,52 +140,24 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// See individual Path impls for additional restrictions. #[inline] - fn from_vec(path: &[u8]) -> Self { - if contains_nul(path) { - let path = self::null_byte::cond.raise(path.to_owned()); + fn new(path: T) -> Self { + if contains_nul(path.container_as_bytes()) { + let path = self::null_byte::cond.raise(path.container_into_owned_bytes()); assert!(!contains_nul(path)); - unsafe { GenericPathUnsafe::from_vec_unchecked(path) } + unsafe { GenericPathUnsafe::new_unchecked(path) } } else { - unsafe { GenericPathUnsafe::from_vec_unchecked(path) } + unsafe { GenericPathUnsafe::new_unchecked(path) } } } - /// Creates a new Path from a byte vector, if possible. + /// Creates a new Path from a byte vector or string, if possible. /// The resulting Path will always be normalized. #[inline] - fn from_vec_opt(path: &[u8]) -> Option { - if contains_nul(path) { + fn new_opt(path: T) -> Option { + if contains_nul(path.container_as_bytes()) { None } else { - Some(unsafe { GenericPathUnsafe::from_vec_unchecked(path) }) - } - } - - /// Creates a new Path from a string. - /// The resulting Path will always be normalized. - /// - /// # Failure - /// - /// Raises the `null_byte` condition if the path contains a NUL. - #[inline] - fn from_str(path: &str) -> Self { - let v = path.as_bytes(); - if contains_nul(v) { - GenericPath::from_vec(path.as_bytes()) // let from_vec handle the condition - } else { - unsafe { GenericPathUnsafe::from_str_unchecked(path) } - } - } - - /// Creates a new Path from a string, if possible. - /// The resulting Path will always be normalized. - #[inline] - fn from_str_opt(path: &str) -> Option { - let v = path.as_bytes(); - if contains_nul(v) { - None - } else { - Some(unsafe { GenericPathUnsafe::from_str_unchecked(path) }) + Some(unsafe { GenericPathUnsafe::new_unchecked(path) }) } } @@ -199,7 +171,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let v = path.as_bytes(); // v is NUL-terminated. Strip it off let v = v.slice_to(v.len()-1); - unsafe { GenericPathUnsafe::from_vec_unchecked(v) } + unsafe { GenericPathUnsafe::new_unchecked(v) } } /// Returns the path as a string, if possible. @@ -209,9 +181,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe { str::from_utf8_slice_opt(self.as_vec()) } + /// Converts the Path into an owned string, if possible + fn into_str(self) -> Option<~str>; + /// Returns the path as a byte vector fn as_vec<'a>(&'a self) -> &'a [u8]; + /// Converts the Path into an owned byte vector + fn into_vec(self) -> ~[u8]; + /// Provides the path as a string /// /// If the path is not UTF-8, invalid sequences will be replaced with the unicode @@ -345,115 +323,91 @@ pub trait GenericPath: Clone + GenericPathUnsafe { self.extension().and_then(str::from_utf8_slice_opt) } - /// Replaces the directory portion of the path with the given byte vector. + /// Replaces the directory portion of the path with the given byte vector or string. /// If `self` represents the root of the filesystem hierarchy, the last path component - /// of the given byte vector becomes the filename. + /// of the argument becomes the filename. /// /// # Failure /// /// Raises the `null_byte` condition if the dirname contains a NUL. #[inline] - fn set_dirname(&mut self, dirname: &[u8]) { - if contains_nul(dirname) { - let dirname = self::null_byte::cond.raise(dirname.to_owned()); + fn set_dirname(&mut self, dirname: T) { + if contains_nul(dirname.container_as_bytes()) { + let dirname = self::null_byte::cond.raise(dirname.container_into_owned_bytes()); assert!(!contains_nul(dirname)); unsafe { self.set_dirname_unchecked(dirname) } } else { unsafe { self.set_dirname_unchecked(dirname) } } } - /// Replaces the directory portion of the path with the given string. - /// See `set_dirname` for details. - #[inline] - fn set_dirname_str(&mut self, dirname: &str) { - if contains_nul(dirname.as_bytes()) { - self.set_dirname(dirname.as_bytes()) // triggers null_byte condition - } else { - unsafe { self.set_dirname_str_unchecked(dirname) } - } - } - /// Replaces the filename portion of the path with the given byte vector. + /// Replaces the filename portion of the path with the given byte vector or string. /// If the replacement name is [], this is equivalent to popping the path. /// /// # Failure /// /// Raises the `null_byte` condition if the filename contains a NUL. #[inline] - fn set_filename(&mut self, filename: &[u8]) { - if contains_nul(filename) { - let filename = self::null_byte::cond.raise(filename.to_owned()); + fn set_filename(&mut self, filename: T) { + if contains_nul(filename.container_as_bytes()) { + let filename = self::null_byte::cond.raise(filename.container_into_owned_bytes()); assert!(!contains_nul(filename)); unsafe { self.set_filename_unchecked(filename) } } else { unsafe { self.set_filename_unchecked(filename) } } } - /// Replaces the filename portion of the path with the given string. - /// See `set_filename` for details. - #[inline] - fn set_filename_str(&mut self, filename: &str) { - if contains_nul(filename.as_bytes()) { - self.set_filename(filename.as_bytes()) // triggers null_byte condition - } else { - unsafe { self.set_filename_str_unchecked(filename) } - } - } - /// Replaces the filestem with the given byte vector. + /// Replaces the filestem with the given byte vector or string. /// If there is no extension in `self` (or `self` has no filename), this is equivalent - /// to `set_filename`. Otherwise, if the given byte vector is [], the extension (including + /// to `set_filename`. Otherwise, if the argument is [] or "", the extension (including /// the preceding '.') becomes the new filename. /// /// # Failure /// /// Raises the `null_byte` condition if the filestem contains a NUL. - fn set_filestem(&mut self, filestem: &[u8]) { + fn set_filestem(&mut self, filestem: T) { // borrowck is being a pain here let val = { match self.filename() { - None => None, + None => Left(filestem), Some(name) => { let dot = '.' as u8; match name.rposition_elem(&dot) { - None | Some(0) => None, + None | Some(0) => Left(filestem), Some(idx) => { let mut v; - if contains_nul(filestem) { - let filestem = self::null_byte::cond.raise(filestem.to_owned()); + if contains_nul(filestem.container_as_bytes()) { + let filestem = filestem.container_into_owned_bytes(); + let filestem = self::null_byte::cond.raise(filestem); assert!(!contains_nul(filestem)); v = filestem; let n = v.len(); v.reserve(n + name.len() - idx); } else { + let filestem = filestem.container_as_bytes(); v = vec::with_capacity(filestem.len() + name.len() - idx); v.push_all(filestem); } v.push_all(name.slice_from(idx)); - Some(v) + Right(v) } } } } }; match val { - None => self.set_filename(filestem), - Some(v) => unsafe { self.set_filename_unchecked(v) } + Left(v) => self.set_filename(v), + Right(v) => unsafe { self.set_filename_unchecked(v) } } } - /// Replaces the filestem with the given string. - /// See `set_filestem` for details. - #[inline] - fn set_filestem_str(&mut self, filestem: &str) { - self.set_filestem(filestem.as_bytes()) - } - /// Replaces the extension with the given byte vector. + /// Replaces the extension with the given byte vector or string. /// If there is no extension in `self`, this adds one. - /// If the given byte vector is [], this removes the extension. + /// If the argument is [] or "", this removes the extension. /// If `self` has no filename, this is a no-op. /// /// # Failure /// /// Raises the `null_byte` condition if the extension contains a NUL. - fn set_extension(&mut self, extension: &[u8]) { + fn set_extension(&mut self, extension: T) { // borrowck causes problems here too let val = { match self.filename() { @@ -462,12 +416,12 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let dot = '.' as u8; match name.rposition_elem(&dot) { None | Some(0) => { - if extension.is_empty() { + if extension.container_as_bytes().is_empty() { None } else { let mut v; - if contains_nul(extension) { - let ext = extension.to_owned(); + if contains_nul(extension.container_as_bytes()) { + let ext = extension.container_into_owned_bytes(); let extension = self::null_byte::cond.raise(ext); assert!(!contains_nul(extension)); v = vec::with_capacity(name.len() + extension.len() + 1); @@ -475,6 +429,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { v.push(dot); v.push_all(extension); } else { + let extension = extension.container_as_bytes(); v = vec::with_capacity(name.len() + extension.len() + 1); v.push_all(name); v.push(dot); @@ -484,18 +439,19 @@ pub trait GenericPath: Clone + GenericPathUnsafe { } } Some(idx) => { - if extension.is_empty() { + if extension.container_as_bytes().is_empty() { Some(name.slice_to(idx).to_owned()) } else { let mut v; - if contains_nul(extension) { - let ext = extension.to_owned(); + if contains_nul(extension.container_as_bytes()) { + let ext = extension.container_into_owned_bytes(); let extension = self::null_byte::cond.raise(ext); assert!(!contains_nul(extension)); v = vec::with_capacity(idx + extension.len() + 1); v.push_all(name.slice_to(idx+1)); v.push_all(extension); } else { + let extension = extension.container_as_bytes(); v = vec::with_capacity(idx + extension.len() + 1); v.push_all(name.slice_to(idx+1)); v.push_all(extension); @@ -512,31 +468,25 @@ pub trait GenericPath: Clone + GenericPathUnsafe { Some(v) => unsafe { self.set_filename_unchecked(v) } } } - /// Replaces the extension with the given string. - /// See `set_extension` for details. - #[inline] - fn set_extension_str(&mut self, extension: &str) { - self.set_extension(extension.as_bytes()) - } - /// Adds the given extension (as a byte vector) to the file. + /// Adds the given extension (as a byte vector or string) to the file. /// This does not remove any existing extension. /// `foo.bar`.add_extension(`baz`) becomes `foo.bar.baz`. /// If `self` has no filename, this is a no-op. - /// If the given byte vector is [], this is a no-op. + /// If the argument is [] or "", this is a no-op. /// /// # Failure /// /// Raises the `null_byte` condition if the extension contains a NUL. - fn add_extension(&mut self, extension: &[u8]) { - if extension.is_empty() { return; } + fn add_extension(&mut self, extension: T) { + if extension.container_as_bytes().is_empty() { return; } // appease borrowck let val = { match self.filename() { None => None, Some(name) => { let mut v; - if contains_nul(extension) { - let ext = extension.to_owned(); + if contains_nul(extension.container_as_bytes()) { + let ext = extension.container_into_owned_bytes(); let extension = self::null_byte::cond.raise(ext); assert!(!contains_nul(extension)); v = vec::with_capacity(name.len() + 1 + extension.len()); @@ -544,6 +494,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { v.push('.' as u8); v.push_all(extension); } else { + let extension = extension.container_as_bytes(); v = vec::with_capacity(name.len() + 1 + extension.len()); v.push_all(name); v.push('.' as u8); @@ -558,105 +509,71 @@ pub trait GenericPath: Clone + GenericPathUnsafe { Some(v) => unsafe { self.set_filename_unchecked(v) } } } - /// Adds the given extension (as a string) to the file. - /// See `add_extension` for details. - #[inline] - fn add_extension_str(&mut self, extension: &str) { - self.add_extension(extension.as_bytes()) - } - /// Returns a new Path constructed by replacing the dirname with the given byte vector. + /// Returns a new Path constructed by replacing the dirname with the given + /// byte vector or string. /// See `set_dirname` for details. /// /// # Failure /// /// Raises the `null_byte` condition if the dirname contains a NUL. #[inline] - fn with_dirname(&self, dirname: &[u8]) -> Self { + fn with_dirname(&self, dirname: T) -> Self { let mut p = self.clone(); p.set_dirname(dirname); p } - /// Returns a new Path constructed by replacing the dirname with the given string. - /// See `set_dirname` for details. - #[inline] - fn with_dirname_str(&self, dirname: &str) -> Self { - let mut p = self.clone(); - p.set_dirname_str(dirname); - p - } - /// Returns a new Path constructed by replacing the filename with the given byte vector. + /// Returns a new Path constructed by replacing the filename with the given + /// byte vector or string. /// See `set_filename` for details. /// /// # Failure /// /// Raises the `null_byte` condition if the filename contains a NUL. #[inline] - fn with_filename(&self, filename: &[u8]) -> Self { + fn with_filename(&self, filename: T) -> Self { let mut p = self.clone(); p.set_filename(filename); p } - /// Returns a new Path constructed by replacing the filename with the given string. - /// See `set_filename` for details. - #[inline] - fn with_filename_str(&self, filename: &str) -> Self { - let mut p = self.clone(); - p.set_filename_str(filename); - p - } - /// Returns a new Path constructed by setting the filestem to the given byte vector. + /// Returns a new Path constructed by setting the filestem to the given + /// byte vector or string. /// See `set_filestem` for details. /// /// # Failure /// /// Raises the `null_byte` condition if the filestem contains a NUL. #[inline] - fn with_filestem(&self, filestem: &[u8]) -> Self { + fn with_filestem(&self, filestem: T) -> Self { let mut p = self.clone(); p.set_filestem(filestem); p } - /// Returns a new Path constructed by setting the filestem to the given string. - /// See `set_filestem` for details. - #[inline] - fn with_filestem_str(&self, filestem: &str) -> Self { - let mut p = self.clone(); - p.set_filestem_str(filestem); - p - } - /// Returns a new Path constructed by setting the extension to the given byte vector. + /// Returns a new Path constructed by setting the extension to the given + /// byte vector or string. /// See `set_extension` for details. /// /// # Failure /// /// Raises the `null_byte` condition if the extension contains a NUL. #[inline] - fn with_extension(&self, extension: &[u8]) -> Self { + fn with_extension(&self, extension: T) -> Self { let mut p = self.clone(); p.set_extension(extension); p } - /// Returns a new Path constructed by setting the extension to the given string. - /// See `set_extension` for details. - #[inline] - fn with_extension_str(&self, extension: &str) -> Self { - let mut p = self.clone(); - p.set_extension_str(extension); - p - } /// Returns the directory component of `self`, as a Path. /// If `self` represents the root of the filesystem hierarchy, returns `self`. fn dir_path(&self) -> Self { // self.dirname() returns a NUL-free vector - unsafe { GenericPathUnsafe::from_vec_unchecked(self.dirname()) } + unsafe { GenericPathUnsafe::new_unchecked(self.dirname()) } } /// Returns the file component of `self`, as a relative Path. /// If `self` represents the root of the filesystem hierarchy, returns None. fn file_path(&self) -> Option { // self.filename() returns a NUL-free vector - self.filename().map_move(|v| unsafe { GenericPathUnsafe::from_vec_unchecked(v) }) + self.filename().map_move(|v| unsafe { GenericPathUnsafe::new_unchecked(v) }) } /// Returns a Path that represents the filesystem root that `self` is rooted in. @@ -664,51 +581,41 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// If `self` is not absolute, or vol-relative in the case of Windows, this returns None. fn root_path(&self) -> Option; - /// Pushes a path (as a byte vector) onto `self`. + /// Pushes a path (as a byte vector or string) onto `self`. /// If the argument represents an absolute path, it replaces `self`. /// /// # Failure /// /// Raises the `null_byte` condition if the path contains a NUL. #[inline] - fn push(&mut self, path: &[u8]) { - if contains_nul(path) { - let path = self::null_byte::cond.raise(path.to_owned()); + fn push(&mut self, path: T) { + if contains_nul(path.container_as_bytes()) { + let path = self::null_byte::cond.raise(path.container_into_owned_bytes()); assert!(!contains_nul(path)); unsafe { self.push_unchecked(path) } } else { unsafe { self.push_unchecked(path) } } } - /// Pushes a path (as a string) onto `self. - /// See `push` for details. - #[inline] - fn push_str(&mut self, path: &str) { - if contains_nul(path.as_bytes()) { - self.push(path.as_bytes()) // triggers null_byte condition - } else { - unsafe { self.push_str_unchecked(path) } - } - } /// Pushes a Path onto `self`. /// If the argument represents an absolute path, it replaces `self`. #[inline] fn push_path(&mut self, path: &Self) { self.push(path.as_vec()) } - /// Pushes multiple paths (as byte vectors) onto `self`. + /// Pushes multiple paths (as byte vectors or strings) onto `self`. /// See `push` for details. #[inline] - fn push_many>(&mut self, paths: &[V]) { - for p in paths.iter() { - self.push(p.as_slice()); - } - } - /// Pushes multiple paths (as strings) onto `self`. - #[inline] - fn push_many_str(&mut self, paths: &[S]) { - for p in paths.iter() { - self.push_str(p.as_slice()); + fn push_many(&mut self, paths: &[T]) { + let t: Option = None; + if BytesContainer::is_str(t) { + for p in paths.iter() { + self.push(p.container_as_str()) + } + } else { + for p in paths.iter() { + self.push(p.container_as_bytes()) + } } } /// Pops the last path component off of `self` and returns it. @@ -722,26 +629,19 @@ pub trait GenericPath: Clone + GenericPathUnsafe { self.pop().and_then(|v| str::from_utf8_owned_opt(v)) } - /// Returns a new Path constructed by joining `self` with the given path (as a byte vector). + /// Returns a new Path constructed by joining `self` with the given path + /// (as a byte vector or string). /// If the given path is absolute, the new Path will represent just that. /// /// # Failure /// /// Raises the `null_byte` condition if the path contains a NUL. #[inline] - fn join(&self, path: &[u8]) -> Self { + fn join(&self, path: T) -> Self { let mut p = self.clone(); p.push(path); p } - /// Returns a new Path constructed by joining `self` with the given path (as a string). - /// See `join` for details. - #[inline] - fn join_str(&self, path: &str) -> Self { - let mut p = self.clone(); - p.push_str(path); - p - } /// Returns a new Path constructed by joining `self` with the given path. /// If the given path is absolute, the new Path will represent just that. #[inline] @@ -750,22 +650,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe { p.push_path(path); p } - /// Returns a new Path constructed by joining `self` with the given paths (as byte vectors). + /// Returns a new Path constructed by joining `self` with the given paths + /// (as byte vectors or strings). /// See `join` for details. #[inline] - fn join_many>(&self, paths: &[V]) -> Self { + fn join_many(&self, paths: &[T]) -> Self { let mut p = self.clone(); p.push_many(paths); p } - /// Returns a new Path constructed by joining `self` with the given paths (as strings). - /// See `join` for details. - #[inline] - fn join_many_str(&self, paths: &[S]) -> Self { - let mut p = self.clone(); - p.push_many_str(paths); - p - } /// Returns whether `self` represents an absolute path. /// An absolute path is defined as one that, when joined to another path, will @@ -805,57 +698,59 @@ pub trait GenericPath: Clone + GenericPathUnsafe { } true } + + /// Returns whether the relative path `child` is a suffix of `self`. + fn ends_with_path(&self, child: &Self) -> bool; +} + +/// A trait that represents something bytes-like (e.g. a &[u8] or a &str) +pub trait BytesContainer { + /// Returns a &[u8] representing the receiver + fn container_as_bytes<'a>(&'a self) -> &'a [u8]; + /// Consumes the receiver and converts it into ~[u8] + #[inline] + fn container_into_owned_bytes(self) -> ~[u8] { + self.container_as_bytes().to_owned() + } + /// Returns the receiver interpreted as a utf-8 string + /// + /// # Failure + /// + /// Raises `str::null_byte` if not utf-8 + #[inline] + fn container_as_str<'a>(&'a self) -> &'a str { + str::from_utf8_slice(self.container_as_bytes()) + } + /// Returns the receiver interpreted as a utf-8 string, if possible + #[inline] + fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { + str::from_utf8_slice_opt(self.container_as_bytes()) + } + /// Returns whether the concrete receiver is a string type + // FIXME (#8888): Remove unused arg once :: works + #[inline] + fn is_str(_: Option) -> bool { false } } /// A trait that represents the unsafe operations on GenericPaths pub trait GenericPathUnsafe { - /// Creates a new Path from a byte vector without checking for null bytes. + /// Creates a new Path without checking for null bytes. /// The resulting Path will always be normalized. - unsafe fn from_vec_unchecked(path: &[u8]) -> Self; + unsafe fn new_unchecked(path: T) -> Self; - /// Creates a new Path from a str without checking for null bytes. - /// The resulting Path will always be normalized. - #[inline] - unsafe fn from_str_unchecked(path: &str) -> Self { - GenericPathUnsafe::from_vec_unchecked(path.as_bytes()) - } - - /// Replaces the directory portion of the path with the given byte vector without - /// checking for null bytes. + /// Replaces the directory portion of the path without checking for null + /// bytes. /// See `set_dirname` for details. - unsafe fn set_dirname_unchecked(&mut self, dirname: &[u8]); - - /// Replaces the directory portion of the path with the given str without - /// checking for null bytes. - /// See `set_dirname_str` for details. - #[inline] - unsafe fn set_dirname_str_unchecked(&mut self, dirname: &str) { - self.set_dirname_unchecked(dirname.as_bytes()) - } + unsafe fn set_dirname_unchecked(&mut self, dirname: T); - /// Replaces the filename portion of the path with the given byte vector without - /// checking for null bytes. + /// Replaces the filename portion of the path without checking for null + /// bytes. /// See `set_filename` for details. - unsafe fn set_filename_unchecked(&mut self, filename: &[u8]); - - /// Replaces the filename portion of the path with the given str without - /// checking for null bytes. - /// See `set_filename_str` for details. - #[inline] - unsafe fn set_filename_str_unchecked(&mut self, filename: &str) { - self.set_filename_unchecked(filename.as_bytes()) - } + unsafe fn set_filename_unchecked(&mut self, filename: T); - /// Pushes a byte vector onto `self` without checking for null bytes. + /// Pushes a path onto `self` without checking for null bytes. /// See `push` for details. - unsafe fn push_unchecked(&mut self, path: &[u8]); - - /// Pushes a str onto `self` without checking for null bytes. - /// See `push_str` for details. - #[inline] - unsafe fn push_str_unchecked(&mut self, path: &str) { - self.push_unchecked(path.as_bytes()) - } + unsafe fn push_unchecked(&mut self, path: T); } /// Helper struct for printing paths with format!() @@ -883,6 +778,86 @@ impl<'self, P: GenericPath> fmt::Default for FilenameDisplay<'self, P> { } } +impl<'self> BytesContainer for &'self str { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_bytes() + } + #[inline] + fn container_as_str<'a>(&'a self) -> &'a str { + *self + } + #[inline] + fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { + Some(*self) + } + #[inline] + fn is_str(_: Option<&'self str>) -> bool { true } +} + +impl BytesContainer for ~str { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_bytes() + } + #[inline] + fn container_into_owned_bytes(self) -> ~[u8] { + self.into_bytes() + } + #[inline] + fn container_as_str<'a>(&'a self) -> &'a str { + self.as_slice() + } + #[inline] + fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { + Some(self.as_slice()) + } + #[inline] + fn is_str(_: Option<~str>) -> bool { true } +} + +impl BytesContainer for @str { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_bytes() + } + #[inline] + fn container_as_str<'a>(&'a self) -> &'a str { + self.as_slice() + } + #[inline] + fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { + Some(self.as_slice()) + } + #[inline] + fn is_str(_: Option<@str>) -> bool { true } +} + +impl<'self> BytesContainer for &'self [u8] { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + *self + } +} + +impl BytesContainer for ~[u8] { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_slice() + } + #[inline] + fn container_into_owned_bytes(self) -> ~[u8] { + self + } +} + +impl BytesContainer for @[u8] { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_slice() + } +} + #[inline(always)] fn contains_nul(v: &[u8]) -> bool { v.iter().any(|&x| x == 0) diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f39062e66cb..3400b673c30 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -23,7 +23,7 @@ use to_bytes::IterBytes; use util; use vec; use vec::{CopyableVector, RSplitIterator, SplitIterator, Vector, VectorVector}; -use super::{GenericPath, GenericPathUnsafe}; +use super::{BytesContainer, GenericPath, GenericPathUnsafe}; #[cfg(not(target_os = "win32"))] use libc; @@ -65,12 +65,7 @@ impl Eq for Path { impl FromStr for Path { fn from_str(s: &str) -> Option { - let v = s.as_bytes(); - if contains_nul(v) { - None - } else { - Some(unsafe { GenericPathUnsafe::from_vec_unchecked(v) }) - } + Path::new_opt(s) } } @@ -95,14 +90,15 @@ impl IterBytes for Path { } impl GenericPathUnsafe for Path { - unsafe fn from_vec_unchecked(path: &[u8]) -> Path { - let path = Path::normalize(path); + unsafe fn new_unchecked(path: T) -> Path { + let path = Path::normalize(path.container_as_bytes()); assert!(!path.is_empty()); let idx = path.rposition_elem(&sep); Path{ repr: path, sepidx: idx } } - unsafe fn set_dirname_unchecked(&mut self, dirname: &[u8]) { + unsafe fn set_dirname_unchecked(&mut self, dirname: T) { + let dirname = dirname.container_as_bytes(); match self.sepidx { None if bytes!(".") == self.repr || bytes!("..") == self.repr => { self.repr = Path::normalize(dirname); @@ -134,7 +130,8 @@ impl GenericPathUnsafe for Path { self.sepidx = self.repr.rposition_elem(&sep); } - unsafe fn set_filename_unchecked(&mut self, filename: &[u8]) { + unsafe fn set_filename_unchecked(&mut self, filename: T) { + let filename = filename.container_as_bytes(); match self.sepidx { None if bytes!("..") == self.repr => { let mut v = vec::with_capacity(3 + filename.len()); @@ -163,7 +160,8 @@ impl GenericPathUnsafe for Path { self.sepidx = self.repr.rposition_elem(&sep); } - unsafe fn push_unchecked(&mut self, path: &[u8]) { + unsafe fn push_unchecked(&mut self, path: T) { + let path = path.container_as_bytes(); if !path.is_empty() { if path[0] == sep { self.repr = Path::normalize(path); @@ -185,6 +183,14 @@ impl GenericPath for Path { self.repr.as_slice() } + fn into_vec(self) -> ~[u8] { + self.repr + } + + fn into_str(self) -> Option<~str> { + str::from_utf8_owned_opt(self.repr) + } + fn dirname<'a>(&'a self) -> &'a [u8] { match self.sepidx { None if bytes!("..") == self.repr => self.repr.as_slice(), @@ -230,7 +236,7 @@ impl GenericPath for Path { fn root_path(&self) -> Option { if self.is_absolute() { - Some(Path::from_str("/")) + Some(Path::new("/")) } else { None } @@ -299,52 +305,41 @@ impl GenericPath for Path { } } } - Some(Path::from_vec(comps.connect_vec(&sep))) + Some(Path::new(comps.connect_vec(&sep))) + } + } + + fn ends_with_path(&self, child: &Path) -> bool { + if !child.is_relative() { return false; } + let mut selfit = self.rev_component_iter(); + let mut childit = child.rev_component_iter(); + loop { + match (selfit.next(), childit.next()) { + (Some(a), Some(b)) => if a != b { return false; }, + (Some(_), None) => break, + (None, Some(_)) => return false, + (None, None) => break + } } + true } } impl Path { - /// Returns a new Path from a byte vector + /// Returns a new Path from a byte vector or string /// /// # Failure /// /// Raises the `null_byte` condition if the vector contains a NUL. #[inline] - pub fn from_vec(v: &[u8]) -> Path { - GenericPath::from_vec(v) - } - - /// Returns a new Path from a byte vector, if possible - #[inline] - pub fn from_vec_opt(v: &[u8]) -> Option { - GenericPath::from_vec_opt(v) - } - - /// Returns a new Path from a string - /// - /// # Failure - /// - /// Raises the `null_byte` condition if the str contains a NUL. - #[inline] - pub fn from_str(s: &str) -> Path { - GenericPath::from_str(s) + pub fn new(path: T) -> Path { + GenericPath::new(path) } - /// Returns a new Path from a string, if possible + /// Returns a new Path from a byte vector or string, if possible #[inline] - pub fn from_str_opt(s: &str) -> Option { - GenericPath::from_str_opt(s) - } - - /// Converts the Path into an owned byte vector - pub fn into_vec(self) -> ~[u8] { - self.repr - } - - /// Converts the Path into an owned string, if possible - pub fn into_str(self) -> Option<~str> { - str::from_utf8_owned_opt(self.repr) + pub fn new_opt(path: T) -> Option { + GenericPath::new_opt(path) } /// Returns a normalized byte vector representation of a path, by removing all empty @@ -427,22 +422,6 @@ impl Path { pub fn rev_str_component_iter<'a>(&'a self) -> RevStrComponentIter<'a> { self.rev_component_iter().map(str::from_utf8_slice_opt) } - - /// Returns whether the relative path `child` is a suffix of `self`. - pub fn ends_with_path(&self, child: &Path) -> bool { - if !child.is_relative() { return false; } - let mut selfit = self.rev_component_iter(); - let mut childit = child.rev_component_iter(); - loop { - match (selfit.next(), childit.next()) { - (Some(a), Some(b)) => if a != b { return false; }, - (Some(_), None) => break, - (None, Some(_)) => return false, - (None, None) => break - } - } - true - } } // None result means the byte vector didn't need normalizing @@ -611,54 +590,55 @@ mod tests { #[test] fn test_paths() { - t!(v: Path::from_vec([]), b!(".")); - t!(v: Path::from_vec(b!("/")), b!("/")); - t!(v: Path::from_vec(b!("a/b/c")), b!("a/b/c")); - t!(v: Path::from_vec(b!("a/b/c", 0xff)), b!("a/b/c", 0xff)); - t!(v: Path::from_vec(b!(0xff, "/../foo", 0x80)), b!("foo", 0x80)); - let p = Path::from_vec(b!("a/b/c", 0xff)); + let empty: &[u8] = []; + t!(v: Path::new(empty), b!(".")); + t!(v: Path::new(b!("/")), b!("/")); + t!(v: Path::new(b!("a/b/c")), b!("a/b/c")); + t!(v: Path::new(b!("a/b/c", 0xff)), b!("a/b/c", 0xff)); + t!(v: Path::new(b!(0xff, "/../foo", 0x80)), b!("foo", 0x80)); + let p = Path::new(b!("a/b/c", 0xff)); assert_eq!(p.as_str(), None); - t!(s: Path::from_str(""), "."); - t!(s: Path::from_str("/"), "/"); - t!(s: Path::from_str("hi"), "hi"); - t!(s: Path::from_str("hi/"), "hi"); - t!(s: Path::from_str("/lib"), "/lib"); - t!(s: Path::from_str("/lib/"), "/lib"); - t!(s: Path::from_str("hi/there"), "hi/there"); - t!(s: Path::from_str("hi/there.txt"), "hi/there.txt"); - - t!(s: Path::from_str("hi/there/"), "hi/there"); - t!(s: Path::from_str("hi/../there"), "there"); - t!(s: Path::from_str("../hi/there"), "../hi/there"); - t!(s: Path::from_str("/../hi/there"), "/hi/there"); - t!(s: Path::from_str("foo/.."), "."); - t!(s: Path::from_str("/foo/.."), "/"); - t!(s: Path::from_str("/foo/../.."), "/"); - t!(s: Path::from_str("/foo/../../bar"), "/bar"); - t!(s: Path::from_str("/./hi/./there/."), "/hi/there"); - t!(s: Path::from_str("/./hi/./there/./.."), "/hi"); - t!(s: Path::from_str("foo/../.."), ".."); - t!(s: Path::from_str("foo/../../.."), "../.."); - t!(s: Path::from_str("foo/../../bar"), "../bar"); - - assert_eq!(Path::from_vec(b!("foo/bar")).into_vec(), b!("foo/bar").to_owned()); - assert_eq!(Path::from_vec(b!("/foo/../../bar")).into_vec(), + t!(s: Path::new(""), "."); + t!(s: Path::new("/"), "/"); + t!(s: Path::new("hi"), "hi"); + t!(s: Path::new("hi/"), "hi"); + t!(s: Path::new("/lib"), "/lib"); + t!(s: Path::new("/lib/"), "/lib"); + t!(s: Path::new("hi/there"), "hi/there"); + t!(s: Path::new("hi/there.txt"), "hi/there.txt"); + + t!(s: Path::new("hi/there/"), "hi/there"); + t!(s: Path::new("hi/../there"), "there"); + t!(s: Path::new("../hi/there"), "../hi/there"); + t!(s: Path::new("/../hi/there"), "/hi/there"); + t!(s: Path::new("foo/.."), "."); + t!(s: Path::new("/foo/.."), "/"); + t!(s: Path::new("/foo/../.."), "/"); + t!(s: Path::new("/foo/../../bar"), "/bar"); + t!(s: Path::new("/./hi/./there/."), "/hi/there"); + t!(s: Path::new("/./hi/./there/./.."), "/hi"); + t!(s: Path::new("foo/../.."), ".."); + t!(s: Path::new("foo/../../.."), "../.."); + t!(s: Path::new("foo/../../bar"), "../bar"); + + assert_eq!(Path::new(b!("foo/bar")).into_vec(), b!("foo/bar").to_owned()); + assert_eq!(Path::new(b!("/foo/../../bar")).into_vec(), b!("/bar").to_owned()); - assert_eq!(Path::from_str("foo/bar").into_str(), Some(~"foo/bar")); - assert_eq!(Path::from_str("/foo/../../bar").into_str(), Some(~"/bar")); + assert_eq!(Path::new("foo/bar").into_str(), Some(~"foo/bar")); + assert_eq!(Path::new("/foo/../../bar").into_str(), Some(~"/bar")); - let p = Path::from_vec(b!("foo/bar", 0x80)); + let p = Path::new(b!("foo/bar", 0x80)); assert_eq!(p.as_str(), None); - assert_eq!(Path::from_vec(b!("foo", 0xff, "/bar")).into_str(), None); + assert_eq!(Path::new(b!("foo", 0xff, "/bar")).into_str(), None); } #[test] fn test_opt_paths() { - assert_eq!(Path::from_vec_opt(b!("foo/bar", 0)), None); - t!(v: Path::from_vec_opt(b!("foo/bar")).unwrap(), b!("foo/bar")); - assert_eq!(Path::from_str_opt("foo/bar\0"), None); - t!(s: Path::from_str_opt("foo/bar").unwrap(), "foo/bar"); + assert_eq!(Path::new_opt(b!("foo/bar", 0)), None); + t!(v: Path::new_opt(b!("foo/bar")).unwrap(), b!("foo/bar")); + assert_eq!(Path::new_opt("foo/bar\0"), None); + t!(s: Path::new_opt("foo/bar").unwrap(), "foo/bar"); } #[test] @@ -671,7 +651,7 @@ mod tests { assert_eq!(v.as_slice(), b!("foo/bar", 0)); (b!("/bar").to_owned()) }).inside { - Path::from_vec(b!("foo/bar", 0)) + Path::new(b!("foo/bar", 0)) }; assert!(handled); assert_eq!(p.as_vec(), b!("/bar")); @@ -727,16 +707,16 @@ mod tests { ) ) - t!(~"from_vec() w/nul" => { + t!(~"new() w/nul" => { do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { - Path::from_vec(b!("foo/bar", 0)) + Path::new(b!("foo/bar", 0)) }; }) t!(~"set_filename w/nul" => { - let mut p = Path::from_vec(b!("foo/bar")); + let mut p = Path::new(b!("foo/bar")); do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { @@ -745,7 +725,7 @@ mod tests { }) t!(~"set_dirname w/nul" => { - let mut p = Path::from_vec(b!("foo/bar")); + let mut p = Path::new(b!("foo/bar")); do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { @@ -754,7 +734,7 @@ mod tests { }) t!(~"push w/nul" => { - let mut p = Path::from_vec(b!("foo/bar")); + let mut p = Path::new(b!("foo/bar")); do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { @@ -765,46 +745,46 @@ mod tests { #[test] fn test_display_str() { - assert_eq!(Path::from_str("foo").to_display_str(), ~"foo"); - assert_eq!(Path::from_vec(b!("foo", 0x80)).to_display_str(), ~"foo\uFFFD"); - assert_eq!(Path::from_vec(b!("foo", 0xff, "bar")).to_display_str(), ~"foo\uFFFDbar"); - assert_eq!(Path::from_vec(b!("foo", 0xff, "/bar")).to_filename_display_str(), Some(~"bar")); - assert_eq!(Path::from_vec(b!("foo/", 0xff, "bar")).to_filename_display_str(), + assert_eq!(Path::new("foo").to_display_str(), ~"foo"); + assert_eq!(Path::new(b!("foo", 0x80)).to_display_str(), ~"foo\uFFFD"); + assert_eq!(Path::new(b!("foo", 0xff, "bar")).to_display_str(), ~"foo\uFFFDbar"); + assert_eq!(Path::new(b!("foo", 0xff, "/bar")).to_filename_display_str(), Some(~"bar")); + assert_eq!(Path::new(b!("foo/", 0xff, "bar")).to_filename_display_str(), Some(~"\uFFFDbar")); - assert_eq!(Path::from_vec(b!("/")).to_filename_display_str(), None); + assert_eq!(Path::new(b!("/")).to_filename_display_str(), None); let mut called = false; - do Path::from_str("foo").with_display_str |s| { + do Path::new("foo").with_display_str |s| { assert_eq!(s, "foo"); called = true; }; assert!(called); called = false; - do Path::from_vec(b!("foo", 0x80)).with_display_str |s| { + do Path::new(b!("foo", 0x80)).with_display_str |s| { assert_eq!(s, "foo\uFFFD"); called = true; }; assert!(called); called = false; - do Path::from_vec(b!("foo", 0xff, "bar")).with_display_str |s| { + do Path::new(b!("foo", 0xff, "bar")).with_display_str |s| { assert_eq!(s, "foo\uFFFDbar"); called = true; }; assert!(called); called = false; - do Path::from_vec(b!("foo", 0xff, "/bar")).with_filename_display_str |s| { + do Path::new(b!("foo", 0xff, "/bar")).with_filename_display_str |s| { assert_eq!(s, Some("bar")); called = true; } assert!(called); called = false; - do Path::from_vec(b!("foo/", 0xff, "bar")).with_filename_display_str |s| { + do Path::new(b!("foo/", 0xff, "bar")).with_filename_display_str |s| { assert_eq!(s, Some("\uFFFDbar")); called = true; } assert!(called); called = false; - do Path::from_vec(b!("/")).with_filename_display_str |s| { + do Path::new(b!("/")).with_filename_display_str |s| { assert!(s.is_none()); called = true; } @@ -816,7 +796,7 @@ mod tests { macro_rules! t( ($path:expr, $exp:expr, $expf:expr) => ( { - let path = Path::from_vec($path); + let path = Path::new($path); let f = format!("{}", path.display()); assert_eq!(f.as_slice(), $exp); let f = format!("{}", path.filename_display()); @@ -839,20 +819,20 @@ mod tests { macro_rules! t( (s: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); assert_eq!(path.$op(), ($exp).as_bytes()); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let left = path.$op().map(|&x| str::from_utf8_slice(x)); assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::from_vec($path); + let path = Path::new($path); assert_eq!(path.$op(), $exp); } ); @@ -924,10 +904,10 @@ mod tests { { let path = ($path); let join = ($join); - let mut p1 = Path::from_str(path); + let mut p1 = Path::new(path); let p2 = p1.clone(); - p1.push_str(join); - assert_eq!(p1, p2.join_str(join)); + p1.push(join); + assert_eq!(p1, p2.join(join)); } ) ) @@ -943,8 +923,8 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::from_str($path); - let push = Path::from_str($push); + let mut p = Path::new($path); + let push = Path::new($push); p.push_path(&push); assert_eq!(p.as_str(), Some($exp)); } @@ -966,14 +946,14 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::from_str($path); - p.push_many_str($push); + let mut p = Path::new($path); + p.push_many($push); assert_eq!(p.as_str(), Some($exp)); } ); (v: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::from_vec($path); + let mut p = Path::new($path); p.push_many($push); assert_eq!(p.as_vec(), $exp); } @@ -997,7 +977,7 @@ mod tests { macro_rules! t( (s: $path:expr, $left:expr, $right:expr) => ( { - let mut p = Path::from_str($path); + let mut p = Path::new($path); let file = p.pop_str(); assert_eq!(p.as_str(), Some($left)); assert_eq!(file.map(|s| s.as_slice()), $right); @@ -1005,7 +985,7 @@ mod tests { ); (v: [$($path:expr),+], [$($left:expr),+], Some($($right:expr),+)) => ( { - let mut p = Path::from_vec(b!($($path),+)); + let mut p = Path::new(b!($($path),+)); let file = p.pop(); assert_eq!(p.as_vec(), b!($($left),+)); assert_eq!(file.map(|v| v.as_slice()), Some(b!($($right),+))); @@ -1013,7 +993,7 @@ mod tests { ); (v: [$($path:expr),+], [$($left:expr),+], None) => ( { - let mut p = Path::from_vec(b!($($path),+)); + let mut p = Path::new(b!($($path),+)); let file = p.pop(); assert_eq!(p.as_vec(), b!($($left),+)); assert_eq!(file, None); @@ -1036,27 +1016,27 @@ mod tests { t!(s: "/a", "/", Some("a")); t!(s: "/", "/", None); - assert_eq!(Path::from_vec(b!("foo/bar", 0x80)).pop_str(), None); - assert_eq!(Path::from_vec(b!("foo", 0x80, "/bar")).pop_str(), Some(~"bar")); + assert_eq!(Path::new(b!("foo/bar", 0x80)).pop_str(), None); + assert_eq!(Path::new(b!("foo", 0x80, "/bar")).pop_str(), Some(~"bar")); } #[test] fn test_root_path() { - assert_eq!(Path::from_vec(b!("a/b/c")).root_path(), None); - assert_eq!(Path::from_vec(b!("/a/b/c")).root_path(), Some(Path::from_str("/"))); + assert_eq!(Path::new(b!("a/b/c")).root_path(), None); + assert_eq!(Path::new(b!("/a/b/c")).root_path(), Some(Path::new("/"))); } #[test] fn test_join() { - t!(v: Path::from_vec(b!("a/b/c")).join(b!("..")), b!("a/b")); - t!(v: Path::from_vec(b!("/a/b/c")).join(b!("d")), b!("/a/b/c/d")); - t!(v: Path::from_vec(b!("a/", 0x80, "/c")).join(b!(0xff)), b!("a/", 0x80, "/c/", 0xff)); - t!(s: Path::from_str("a/b/c").join_str(".."), "a/b"); - t!(s: Path::from_str("/a/b/c").join_str("d"), "/a/b/c/d"); - t!(s: Path::from_str("a/b").join_str("c/d"), "a/b/c/d"); - t!(s: Path::from_str("a/b").join_str("/c/d"), "/c/d"); - t!(s: Path::from_str(".").join_str("a/b"), "a/b"); - t!(s: Path::from_str("/").join_str("a/b"), "/a/b"); + t!(v: Path::new(b!("a/b/c")).join(b!("..")), b!("a/b")); + t!(v: Path::new(b!("/a/b/c")).join(b!("d")), b!("/a/b/c/d")); + t!(v: Path::new(b!("a/", 0x80, "/c")).join(b!(0xff)), b!("a/", 0x80, "/c/", 0xff)); + t!(s: Path::new("a/b/c").join(".."), "a/b"); + t!(s: Path::new("/a/b/c").join("d"), "/a/b/c/d"); + t!(s: Path::new("a/b").join("c/d"), "a/b/c/d"); + t!(s: Path::new("a/b").join("/c/d"), "/c/d"); + t!(s: Path::new(".").join("a/b"), "a/b"); + t!(s: Path::new("/").join("a/b"), "/a/b"); } #[test] @@ -1064,8 +1044,8 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let join = Path::from_str($join); + let path = Path::new($path); + let join = Path::new($join); let res = path.join_path(&join); assert_eq!(res.as_str(), Some($exp)); } @@ -1087,14 +1067,14 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let res = path.join_many_str($join); + let path = Path::new($path); + let res = path.join_many($join); assert_eq!(res.as_str(), Some($exp)); } ); (v: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::from_vec($path); + let path = Path::new($path); let res = path.join_many($join); assert_eq!(res.as_vec(), $exp); } @@ -1114,100 +1094,102 @@ mod tests { #[test] fn test_with_helpers() { - t!(v: Path::from_vec(b!("a/b/c")).with_dirname(b!("d")), b!("d/c")); - t!(v: Path::from_vec(b!("a/b/c")).with_dirname(b!("d/e")), b!("d/e/c")); - t!(v: Path::from_vec(b!("a/", 0x80, "b/c")).with_dirname(b!(0xff)), b!(0xff, "/c")); - t!(v: Path::from_vec(b!("a/b/", 0x80)).with_dirname(b!("/", 0xcd)), + let empty: &[u8] = []; + + t!(v: Path::new(b!("a/b/c")).with_dirname(b!("d")), b!("d/c")); + t!(v: Path::new(b!("a/b/c")).with_dirname(b!("d/e")), b!("d/e/c")); + t!(v: Path::new(b!("a/", 0x80, "b/c")).with_dirname(b!(0xff)), b!(0xff, "/c")); + t!(v: Path::new(b!("a/b/", 0x80)).with_dirname(b!("/", 0xcd)), b!("/", 0xcd, "/", 0x80)); - t!(s: Path::from_str("a/b/c").with_dirname_str("d"), "d/c"); - t!(s: Path::from_str("a/b/c").with_dirname_str("d/e"), "d/e/c"); - t!(s: Path::from_str("a/b/c").with_dirname_str(""), "c"); - t!(s: Path::from_str("a/b/c").with_dirname_str("/"), "/c"); - t!(s: Path::from_str("a/b/c").with_dirname_str("."), "c"); - t!(s: Path::from_str("a/b/c").with_dirname_str(".."), "../c"); - t!(s: Path::from_str("/").with_dirname_str("foo"), "foo"); - t!(s: Path::from_str("/").with_dirname_str(""), "."); - t!(s: Path::from_str("/foo").with_dirname_str("bar"), "bar/foo"); - t!(s: Path::from_str("..").with_dirname_str("foo"), "foo"); - t!(s: Path::from_str("../..").with_dirname_str("foo"), "foo"); - t!(s: Path::from_str("..").with_dirname_str(""), "."); - t!(s: Path::from_str("../..").with_dirname_str(""), "."); - t!(s: Path::from_str("foo").with_dirname_str(".."), "../foo"); - t!(s: Path::from_str("foo").with_dirname_str("../.."), "../../foo"); - - t!(v: Path::from_vec(b!("a/b/c")).with_filename(b!("d")), b!("a/b/d")); - t!(v: Path::from_vec(b!("a/b/c", 0xff)).with_filename(b!(0x80)), b!("a/b/", 0x80)); - t!(v: Path::from_vec(b!("/", 0xff, "/foo")).with_filename(b!(0xcd)), + t!(s: Path::new("a/b/c").with_dirname("d"), "d/c"); + t!(s: Path::new("a/b/c").with_dirname("d/e"), "d/e/c"); + t!(s: Path::new("a/b/c").with_dirname(""), "c"); + t!(s: Path::new("a/b/c").with_dirname("/"), "/c"); + t!(s: Path::new("a/b/c").with_dirname("."), "c"); + t!(s: Path::new("a/b/c").with_dirname(".."), "../c"); + t!(s: Path::new("/").with_dirname("foo"), "foo"); + t!(s: Path::new("/").with_dirname(""), "."); + t!(s: Path::new("/foo").with_dirname("bar"), "bar/foo"); + t!(s: Path::new("..").with_dirname("foo"), "foo"); + t!(s: Path::new("../..").with_dirname("foo"), "foo"); + t!(s: Path::new("..").with_dirname(""), "."); + t!(s: Path::new("../..").with_dirname(""), "."); + t!(s: Path::new("foo").with_dirname(".."), "../foo"); + t!(s: Path::new("foo").with_dirname("../.."), "../../foo"); + + t!(v: Path::new(b!("a/b/c")).with_filename(b!("d")), b!("a/b/d")); + t!(v: Path::new(b!("a/b/c", 0xff)).with_filename(b!(0x80)), b!("a/b/", 0x80)); + t!(v: Path::new(b!("/", 0xff, "/foo")).with_filename(b!(0xcd)), b!("/", 0xff, "/", 0xcd)); - t!(s: Path::from_str("a/b/c").with_filename_str("d"), "a/b/d"); - t!(s: Path::from_str(".").with_filename_str("foo"), "foo"); - t!(s: Path::from_str("/a/b/c").with_filename_str("d"), "/a/b/d"); - t!(s: Path::from_str("/").with_filename_str("foo"), "/foo"); - t!(s: Path::from_str("/a").with_filename_str("foo"), "/foo"); - t!(s: Path::from_str("foo").with_filename_str("bar"), "bar"); - t!(s: Path::from_str("/").with_filename_str("foo/"), "/foo"); - t!(s: Path::from_str("/a").with_filename_str("foo/"), "/foo"); - t!(s: Path::from_str("a/b/c").with_filename_str(""), "a/b"); - t!(s: Path::from_str("a/b/c").with_filename_str("."), "a/b"); - t!(s: Path::from_str("a/b/c").with_filename_str(".."), "a"); - t!(s: Path::from_str("/a").with_filename_str(""), "/"); - t!(s: Path::from_str("foo").with_filename_str(""), "."); - t!(s: Path::from_str("a/b/c").with_filename_str("d/e"), "a/b/d/e"); - t!(s: Path::from_str("a/b/c").with_filename_str("/d"), "a/b/d"); - t!(s: Path::from_str("..").with_filename_str("foo"), "../foo"); - t!(s: Path::from_str("../..").with_filename_str("foo"), "../../foo"); - t!(s: Path::from_str("..").with_filename_str(""), ".."); - t!(s: Path::from_str("../..").with_filename_str(""), "../.."); - - t!(v: Path::from_vec(b!("hi/there", 0x80, ".txt")).with_filestem(b!(0xff)), + t!(s: Path::new("a/b/c").with_filename("d"), "a/b/d"); + t!(s: Path::new(".").with_filename("foo"), "foo"); + t!(s: Path::new("/a/b/c").with_filename("d"), "/a/b/d"); + t!(s: Path::new("/").with_filename("foo"), "/foo"); + t!(s: Path::new("/a").with_filename("foo"), "/foo"); + t!(s: Path::new("foo").with_filename("bar"), "bar"); + t!(s: Path::new("/").with_filename("foo/"), "/foo"); + t!(s: Path::new("/a").with_filename("foo/"), "/foo"); + t!(s: Path::new("a/b/c").with_filename(""), "a/b"); + t!(s: Path::new("a/b/c").with_filename("."), "a/b"); + t!(s: Path::new("a/b/c").with_filename(".."), "a"); + t!(s: Path::new("/a").with_filename(""), "/"); + t!(s: Path::new("foo").with_filename(""), "."); + t!(s: Path::new("a/b/c").with_filename("d/e"), "a/b/d/e"); + t!(s: Path::new("a/b/c").with_filename("/d"), "a/b/d"); + t!(s: Path::new("..").with_filename("foo"), "../foo"); + t!(s: Path::new("../..").with_filename("foo"), "../../foo"); + t!(s: Path::new("..").with_filename(""), ".."); + t!(s: Path::new("../..").with_filename(""), "../.."); + + t!(v: Path::new(b!("hi/there", 0x80, ".txt")).with_filestem(b!(0xff)), b!("hi/", 0xff, ".txt")); - t!(v: Path::from_vec(b!("hi/there.txt", 0x80)).with_filestem(b!(0xff)), + t!(v: Path::new(b!("hi/there.txt", 0x80)).with_filestem(b!(0xff)), b!("hi/", 0xff, ".txt", 0x80)); - t!(v: Path::from_vec(b!("hi/there", 0xff)).with_filestem(b!(0x80)), b!("hi/", 0x80)); - t!(v: Path::from_vec(b!("hi", 0x80, "/there")).with_filestem([]), b!("hi", 0x80)); - t!(s: Path::from_str("hi/there.txt").with_filestem_str("here"), "hi/here.txt"); - t!(s: Path::from_str("hi/there.txt").with_filestem_str(""), "hi/.txt"); - t!(s: Path::from_str("hi/there.txt").with_filestem_str("."), "hi/..txt"); - t!(s: Path::from_str("hi/there.txt").with_filestem_str(".."), "hi/...txt"); - t!(s: Path::from_str("hi/there.txt").with_filestem_str("/"), "hi/.txt"); - t!(s: Path::from_str("hi/there.txt").with_filestem_str("foo/bar"), "hi/foo/bar.txt"); - t!(s: Path::from_str("hi/there.foo.txt").with_filestem_str("here"), "hi/here.txt"); - t!(s: Path::from_str("hi/there").with_filestem_str("here"), "hi/here"); - t!(s: Path::from_str("hi/there").with_filestem_str(""), "hi"); - t!(s: Path::from_str("hi").with_filestem_str(""), "."); - t!(s: Path::from_str("/hi").with_filestem_str(""), "/"); - t!(s: Path::from_str("hi/there").with_filestem_str(".."), "."); - t!(s: Path::from_str("hi/there").with_filestem_str("."), "hi"); - t!(s: Path::from_str("hi/there.").with_filestem_str("foo"), "hi/foo."); - t!(s: Path::from_str("hi/there.").with_filestem_str(""), "hi"); - t!(s: Path::from_str("hi/there.").with_filestem_str("."), "."); - t!(s: Path::from_str("hi/there.").with_filestem_str(".."), "hi/..."); - t!(s: Path::from_str("/").with_filestem_str("foo"), "/foo"); - t!(s: Path::from_str(".").with_filestem_str("foo"), "foo"); - t!(s: Path::from_str("hi/there..").with_filestem_str("here"), "hi/here."); - t!(s: Path::from_str("hi/there..").with_filestem_str(""), "hi"); - - t!(v: Path::from_vec(b!("hi/there", 0x80, ".txt")).with_extension(b!("exe")), + t!(v: Path::new(b!("hi/there", 0xff)).with_filestem(b!(0x80)), b!("hi/", 0x80)); + t!(v: Path::new(b!("hi", 0x80, "/there")).with_filestem(empty), b!("hi", 0x80)); + t!(s: Path::new("hi/there.txt").with_filestem("here"), "hi/here.txt"); + t!(s: Path::new("hi/there.txt").with_filestem(""), "hi/.txt"); + t!(s: Path::new("hi/there.txt").with_filestem("."), "hi/..txt"); + t!(s: Path::new("hi/there.txt").with_filestem(".."), "hi/...txt"); + t!(s: Path::new("hi/there.txt").with_filestem("/"), "hi/.txt"); + t!(s: Path::new("hi/there.txt").with_filestem("foo/bar"), "hi/foo/bar.txt"); + t!(s: Path::new("hi/there.foo.txt").with_filestem("here"), "hi/here.txt"); + t!(s: Path::new("hi/there").with_filestem("here"), "hi/here"); + t!(s: Path::new("hi/there").with_filestem(""), "hi"); + t!(s: Path::new("hi").with_filestem(""), "."); + t!(s: Path::new("/hi").with_filestem(""), "/"); + t!(s: Path::new("hi/there").with_filestem(".."), "."); + t!(s: Path::new("hi/there").with_filestem("."), "hi"); + t!(s: Path::new("hi/there.").with_filestem("foo"), "hi/foo."); + t!(s: Path::new("hi/there.").with_filestem(""), "hi"); + t!(s: Path::new("hi/there.").with_filestem("."), "."); + t!(s: Path::new("hi/there.").with_filestem(".."), "hi/..."); + t!(s: Path::new("/").with_filestem("foo"), "/foo"); + t!(s: Path::new(".").with_filestem("foo"), "foo"); + t!(s: Path::new("hi/there..").with_filestem("here"), "hi/here."); + t!(s: Path::new("hi/there..").with_filestem(""), "hi"); + + t!(v: Path::new(b!("hi/there", 0x80, ".txt")).with_extension(b!("exe")), b!("hi/there", 0x80, ".exe")); - t!(v: Path::from_vec(b!("hi/there.txt", 0x80)).with_extension(b!(0xff)), + t!(v: Path::new(b!("hi/there.txt", 0x80)).with_extension(b!(0xff)), b!("hi/there.", 0xff)); - t!(v: Path::from_vec(b!("hi/there", 0x80)).with_extension(b!(0xff)), + t!(v: Path::new(b!("hi/there", 0x80)).with_extension(b!(0xff)), b!("hi/there", 0x80, ".", 0xff)); - t!(v: Path::from_vec(b!("hi/there.", 0xff)).with_extension([]), b!("hi/there")); - t!(s: Path::from_str("hi/there.txt").with_extension_str("exe"), "hi/there.exe"); - t!(s: Path::from_str("hi/there.txt").with_extension_str(""), "hi/there"); - t!(s: Path::from_str("hi/there.txt").with_extension_str("."), "hi/there.."); - t!(s: Path::from_str("hi/there.txt").with_extension_str(".."), "hi/there..."); - t!(s: Path::from_str("hi/there").with_extension_str("txt"), "hi/there.txt"); - t!(s: Path::from_str("hi/there").with_extension_str("."), "hi/there.."); - t!(s: Path::from_str("hi/there").with_extension_str(".."), "hi/there..."); - t!(s: Path::from_str("hi/there.").with_extension_str("txt"), "hi/there.txt"); - t!(s: Path::from_str("hi/.foo").with_extension_str("txt"), "hi/.foo.txt"); - t!(s: Path::from_str("hi/there.txt").with_extension_str(".foo"), "hi/there..foo"); - t!(s: Path::from_str("/").with_extension_str("txt"), "/"); - t!(s: Path::from_str("/").with_extension_str("."), "/"); - t!(s: Path::from_str("/").with_extension_str(".."), "/"); - t!(s: Path::from_str(".").with_extension_str("txt"), "."); + t!(v: Path::new(b!("hi/there.", 0xff)).with_extension(empty), b!("hi/there")); + t!(s: Path::new("hi/there.txt").with_extension("exe"), "hi/there.exe"); + t!(s: Path::new("hi/there.txt").with_extension(""), "hi/there"); + t!(s: Path::new("hi/there.txt").with_extension("."), "hi/there.."); + t!(s: Path::new("hi/there.txt").with_extension(".."), "hi/there..."); + t!(s: Path::new("hi/there").with_extension("txt"), "hi/there.txt"); + t!(s: Path::new("hi/there").with_extension("."), "hi/there.."); + t!(s: Path::new("hi/there").with_extension(".."), "hi/there..."); + t!(s: Path::new("hi/there.").with_extension("txt"), "hi/there.txt"); + t!(s: Path::new("hi/.foo").with_extension("txt"), "hi/.foo.txt"); + t!(s: Path::new("hi/there.txt").with_extension(".foo"), "hi/there..foo"); + t!(s: Path::new("/").with_extension("txt"), "/"); + t!(s: Path::new("/").with_extension("."), "/"); + t!(s: Path::new("/").with_extension(".."), "/"); + t!(s: Path::new(".").with_extension("txt"), "."); } #[test] @@ -1217,9 +1199,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::from_str(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::from_str(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ); @@ -1227,9 +1209,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::from_vec(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::from_vec(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ) @@ -1238,39 +1220,39 @@ mod tests { t!(v: b!("a/b/c"), set_dirname, with_dirname, b!("d")); t!(v: b!("a/b/c"), set_dirname, with_dirname, b!("d/e")); t!(v: b!("a/", 0x80, "/c"), set_dirname, with_dirname, b!(0xff)); - t!(s: "a/b/c", set_dirname_str, with_dirname_str, "d"); - t!(s: "a/b/c", set_dirname_str, with_dirname_str, "d/e"); - t!(s: "/", set_dirname_str, with_dirname_str, "foo"); - t!(s: "/foo", set_dirname_str, with_dirname_str, "bar"); - t!(s: "a/b/c", set_dirname_str, with_dirname_str, ""); - t!(s: "../..", set_dirname_str, with_dirname_str, "x"); - t!(s: "foo", set_dirname_str, with_dirname_str, "../.."); + t!(s: "a/b/c", set_dirname, with_dirname, "d"); + t!(s: "a/b/c", set_dirname, with_dirname, "d/e"); + t!(s: "/", set_dirname, with_dirname, "foo"); + t!(s: "/foo", set_dirname, with_dirname, "bar"); + t!(s: "a/b/c", set_dirname, with_dirname, ""); + t!(s: "../..", set_dirname, with_dirname, "x"); + t!(s: "foo", set_dirname, with_dirname, "../.."); t!(v: b!("a/b/c"), set_filename, with_filename, b!("d")); t!(v: b!("/"), set_filename, with_filename, b!("foo")); t!(v: b!(0x80), set_filename, with_filename, b!(0xff)); - t!(s: "a/b/c", set_filename_str, with_filename_str, "d"); - t!(s: "/", set_filename_str, with_filename_str, "foo"); - t!(s: ".", set_filename_str, with_filename_str, "foo"); - t!(s: "a/b", set_filename_str, with_filename_str, ""); - t!(s: "a", set_filename_str, with_filename_str, ""); + t!(s: "a/b/c", set_filename, with_filename, "d"); + t!(s: "/", set_filename, with_filename, "foo"); + t!(s: ".", set_filename, with_filename, "foo"); + t!(s: "a/b", set_filename, with_filename, ""); + t!(s: "a", set_filename, with_filename, ""); t!(v: b!("hi/there.txt"), set_filestem, with_filestem, b!("here")); t!(v: b!("hi/there", 0x80, ".txt"), set_filestem, with_filestem, b!("here", 0xff)); - t!(s: "hi/there.txt", set_filestem_str, with_filestem_str, "here"); - t!(s: "hi/there.", set_filestem_str, with_filestem_str, "here"); - t!(s: "hi/there", set_filestem_str, with_filestem_str, "here"); - t!(s: "hi/there.txt", set_filestem_str, with_filestem_str, ""); - t!(s: "hi/there", set_filestem_str, with_filestem_str, ""); + t!(s: "hi/there.txt", set_filestem, with_filestem, "here"); + t!(s: "hi/there.", set_filestem, with_filestem, "here"); + t!(s: "hi/there", set_filestem, with_filestem, "here"); + t!(s: "hi/there.txt", set_filestem, with_filestem, ""); + t!(s: "hi/there", set_filestem, with_filestem, ""); t!(v: b!("hi/there.txt"), set_extension, with_extension, b!("exe")); t!(v: b!("hi/there.t", 0x80, "xt"), set_extension, with_extension, b!("exe", 0xff)); - t!(s: "hi/there.txt", set_extension_str, with_extension_str, "exe"); - t!(s: "hi/there.", set_extension_str, with_extension_str, "txt"); - t!(s: "hi/there", set_extension_str, with_extension_str, "txt"); - t!(s: "hi/there.txt", set_extension_str, with_extension_str, ""); - t!(s: "hi/there", set_extension_str, with_extension_str, ""); - t!(s: ".", set_extension_str, with_extension_str, "txt"); + t!(s: "hi/there.txt", set_extension, with_extension, "exe"); + t!(s: "hi/there.", set_extension, with_extension, "txt"); + t!(s: "hi/there", set_extension, with_extension, "txt"); + t!(s: "hi/there.txt", set_extension, with_extension, ""); + t!(s: "hi/there", set_extension, with_extension, ""); + t!(s: ".", set_extension, with_extension, "txt"); } #[test] @@ -1278,14 +1260,14 @@ mod tests { macro_rules! t( (s: $path:expr, $ext:expr, $exp:expr) => ( { - let mut path = Path::from_str($path); - path.add_extension_str($ext); + let mut path = Path::new($path); + path.add_extension($ext); assert_eq!(path.as_str(), Some($exp)); } ); (v: $path:expr, $ext:expr, $exp:expr) => ( { - let mut path = Path::from_vec($path); + let mut path = Path::new($path); path.add_extension($ext); assert_eq!(path.as_vec(), $exp); } @@ -1338,39 +1320,39 @@ mod tests { ) ) - t!(v: Path::from_vec(b!("a/b/c")), Some(b!("c")), b!("a/b"), Some(b!("c")), None); - t!(v: Path::from_vec(b!("a/b/", 0xff)), Some(b!(0xff)), b!("a/b"), Some(b!(0xff)), None); - t!(v: Path::from_vec(b!("hi/there.", 0xff)), Some(b!("there.", 0xff)), b!("hi"), + t!(v: Path::new(b!("a/b/c")), Some(b!("c")), b!("a/b"), Some(b!("c")), None); + t!(v: Path::new(b!("a/b/", 0xff)), Some(b!(0xff)), b!("a/b"), Some(b!(0xff)), None); + t!(v: Path::new(b!("hi/there.", 0xff)), Some(b!("there.", 0xff)), b!("hi"), Some(b!("there")), Some(b!(0xff))); - t!(s: Path::from_str("a/b/c"), Some("c"), Some("a/b"), Some("c"), None); - t!(s: Path::from_str("."), None, Some("."), None, None); - t!(s: Path::from_str("/"), None, Some("/"), None, None); - t!(s: Path::from_str(".."), None, Some(".."), None, None); - t!(s: Path::from_str("../.."), None, Some("../.."), None, None); - t!(s: Path::from_str("hi/there.txt"), Some("there.txt"), Some("hi"), + t!(s: Path::new("a/b/c"), Some("c"), Some("a/b"), Some("c"), None); + t!(s: Path::new("."), None, Some("."), None, None); + t!(s: Path::new("/"), None, Some("/"), None, None); + t!(s: Path::new(".."), None, Some(".."), None, None); + t!(s: Path::new("../.."), None, Some("../.."), None, None); + t!(s: Path::new("hi/there.txt"), Some("there.txt"), Some("hi"), Some("there"), Some("txt")); - t!(s: Path::from_str("hi/there"), Some("there"), Some("hi"), Some("there"), None); - t!(s: Path::from_str("hi/there."), Some("there."), Some("hi"), + t!(s: Path::new("hi/there"), Some("there"), Some("hi"), Some("there"), None); + t!(s: Path::new("hi/there."), Some("there."), Some("hi"), Some("there"), Some("")); - t!(s: Path::from_str("hi/.there"), Some(".there"), Some("hi"), Some(".there"), None); - t!(s: Path::from_str("hi/..there"), Some("..there"), Some("hi"), + t!(s: Path::new("hi/.there"), Some(".there"), Some("hi"), Some(".there"), None); + t!(s: Path::new("hi/..there"), Some("..there"), Some("hi"), Some("."), Some("there")); - t!(s: Path::from_vec(b!("a/b/", 0xff)), None, Some("a/b"), None, None); - t!(s: Path::from_vec(b!("a/b/", 0xff, ".txt")), None, Some("a/b"), None, Some("txt")); - t!(s: Path::from_vec(b!("a/b/c.", 0x80)), None, Some("a/b"), Some("c"), None); - t!(s: Path::from_vec(b!(0xff, "/b")), Some("b"), None, Some("b"), None); + t!(s: Path::new(b!("a/b/", 0xff)), None, Some("a/b"), None, None); + t!(s: Path::new(b!("a/b/", 0xff, ".txt")), None, Some("a/b"), None, Some("txt")); + t!(s: Path::new(b!("a/b/c.", 0x80)), None, Some("a/b"), Some("c"), None); + t!(s: Path::new(b!(0xff, "/b")), Some("b"), None, Some("b"), None); } #[test] fn test_dir_file_path() { - t!(v: Path::from_vec(b!("hi/there", 0x80)).dir_path(), b!("hi")); - t!(v: Path::from_vec(b!("hi", 0xff, "/there")).dir_path(), b!("hi", 0xff)); - t!(s: Path::from_str("hi/there").dir_path(), "hi"); - t!(s: Path::from_str("hi").dir_path(), "."); - t!(s: Path::from_str("/hi").dir_path(), "/"); - t!(s: Path::from_str("/").dir_path(), "/"); - t!(s: Path::from_str("..").dir_path(), ".."); - t!(s: Path::from_str("../..").dir_path(), "../.."); + t!(v: Path::new(b!("hi/there", 0x80)).dir_path(), b!("hi")); + t!(v: Path::new(b!("hi", 0xff, "/there")).dir_path(), b!("hi", 0xff)); + t!(s: Path::new("hi/there").dir_path(), "hi"); + t!(s: Path::new("hi").dir_path(), "."); + t!(s: Path::new("/hi").dir_path(), "/"); + t!(s: Path::new("/").dir_path(), "/"); + t!(s: Path::new("..").dir_path(), ".."); + t!(s: Path::new("../..").dir_path(), "../.."); macro_rules! t( (s: $path:expr, $exp:expr) => ( @@ -1389,14 +1371,14 @@ mod tests { ) ) - t!(v: Path::from_vec(b!("hi/there", 0x80)).file_path(), Some(b!("there", 0x80))); - t!(v: Path::from_vec(b!("hi", 0xff, "/there")).file_path(), Some(b!("there"))); - t!(s: Path::from_str("hi/there").file_path(), Some("there")); - t!(s: Path::from_str("hi").file_path(), Some("hi")); - t!(s: Path::from_str(".").file_path(), None); - t!(s: Path::from_str("/").file_path(), None); - t!(s: Path::from_str("..").file_path(), None); - t!(s: Path::from_str("../..").file_path(), None); + t!(v: Path::new(b!("hi/there", 0x80)).file_path(), Some(b!("there", 0x80))); + t!(v: Path::new(b!("hi", 0xff, "/there")).file_path(), Some(b!("there"))); + t!(s: Path::new("hi/there").file_path(), Some("there")); + t!(s: Path::new("hi").file_path(), Some("hi")); + t!(s: Path::new(".").file_path(), None); + t!(s: Path::new("/").file_path(), None); + t!(s: Path::new("..").file_path(), None); + t!(s: Path::new("../..").file_path(), None); } #[test] @@ -1404,7 +1386,7 @@ mod tests { macro_rules! t( (s: $path:expr, $abs:expr, $rel:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); assert_eq!(path.is_absolute(), $abs); assert_eq!(path.is_relative(), $rel); } @@ -1425,8 +1407,8 @@ mod tests { macro_rules! t( (s: $path:expr, $dest:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let dest = Path::from_str($dest); + let path = Path::new($path); + let dest = Path::new($dest); assert_eq!(path.is_ancestor_of(&dest), $exp); } ) @@ -1459,15 +1441,15 @@ mod tests { macro_rules! t( (s: $path:expr, $child:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let child = Path::from_str($child); + let path = Path::new($path); + let child = Path::new($child); assert_eq!(path.ends_with_path(&child), $exp); } ); (v: $path:expr, $child:expr, $exp:expr) => ( { - let path = Path::from_vec($path); - let child = Path::from_vec($child); + let path = Path::new($path); + let child = Path::new($child); assert_eq!(path.ends_with_path(&child), $exp); } ) @@ -1498,8 +1480,8 @@ mod tests { macro_rules! t( (s: $path:expr, $other:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let other = Path::from_str($other); + let path = Path::new($path); + let other = Path::new($other); let res = path.path_relative_from(&other); assert_eq!(res.and_then_ref(|x| x.as_str()), $exp); } @@ -1543,7 +1525,7 @@ mod tests { macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let comps = path.component_iter().to_owned_vec(); let exp: &[&str] = $exp; let exps = exp.iter().map(|x| x.as_bytes()).to_owned_vec(); @@ -1557,7 +1539,7 @@ mod tests { ); (v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => ( { - let path = Path::from_vec(b!($($arg),+)); + let path = Path::new(b!($($arg),+)); let comps = path.component_iter().to_owned_vec(); let exp: &[&[u8]] = [$(b!($($exp),*)),*]; assert!(comps.as_slice() == exp, "component_iter: Expected {:?}, found {:?}", @@ -1592,7 +1574,7 @@ mod tests { macro_rules! t( (v: [$($arg:expr),+], $exp:expr) => ( { - let path = Path::from_vec(b!($($arg),+)); + let path = Path::new(b!($($arg),+)); let comps = path.str_component_iter().to_owned_vec(); let exp: &[Option<&str>] = $exp; assert!(comps.as_slice() == exp, @@ -1616,13 +1598,13 @@ mod tests { #[test] fn test_each_parent() { - assert!(Path::from_str("/foo/bar").each_parent(|_| true)); - assert!(!Path::from_str("/foo/bar").each_parent(|_| false)); + assert!(Path::new("/foo/bar").each_parent(|_| true)); + assert!(!Path::new("/foo/bar").each_parent(|_| false)); macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let exp: &[&str] = $exp; let mut comps = exp.iter().map(|&x|x); do path.each_parent |p| { @@ -1638,7 +1620,7 @@ mod tests { ); (v: $path:expr, $exp:expr) => ( { - let path = Path::from_vec($path); + let path = Path::new($path); let exp: &[&[u8]] = $exp; let mut comps = exp.iter().map(|&x|x); do path.each_parent |p| { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 5dfe5b4f35a..cc04261ec66 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -22,7 +22,7 @@ use str::{CharSplitIterator, OwnedStr, Str, StrVector}; use to_bytes::IterBytes; use util; use vec::Vector; -use super::{GenericPath, GenericPathUnsafe}; +use super::{BytesContainer, GenericPath, GenericPathUnsafe}; #[cfg(target_os = "win32")] use libc; @@ -97,11 +97,7 @@ impl Eq for Path { impl FromStr for Path { fn from_str(s: &str) -> Option { - if contains_nul(s.as_bytes()) { - None - } else { - Some(unsafe { GenericPathUnsafe::from_str_unchecked(s) }) - } + Path::new_opt(s) } } @@ -132,18 +128,8 @@ impl GenericPathUnsafe for Path { /// /// Raises the `str::not_utf8` condition if not valid UTF-8. #[inline] - unsafe fn from_vec_unchecked(path: &[u8]) -> Path { - if !str::is_utf8(path) { - let path = str::from_utf8(path); // triggers not_utf8 condition - GenericPathUnsafe::from_str_unchecked(path) - } else { - GenericPathUnsafe::from_str_unchecked(cast::transmute(path)) - } - } - - #[inline] - unsafe fn from_str_unchecked(path: &str) -> Path { - let (prefix, path) = Path::normalize_(path); + unsafe fn new_unchecked(path: T) -> Path { + let (prefix, path) = Path::normalize_(path.container_as_str()); assert!(!path.is_empty()); let mut ret = Path{ repr: path, prefix: prefix, sepidx: None }; ret.update_sepidx(); @@ -155,17 +141,8 @@ impl GenericPathUnsafe for Path { /// # Failure /// /// Raises the `str::not_utf8` condition if not valid UTF-8. - #[inline] - unsafe fn set_dirname_unchecked(&mut self, dirname: &[u8]) { - if !str::is_utf8(dirname) { - let dirname = str::from_utf8(dirname); // triggers not_utf8 condition - self.set_dirname_str_unchecked(dirname); - } else { - self.set_dirname_str_unchecked(cast::transmute(dirname)) - } - } - - unsafe fn set_dirname_str_unchecked(&mut self, dirname: &str) { + unsafe fn set_dirname_unchecked(&mut self, dirname: T) { + let dirname = dirname.container_as_str(); match self.sepidx_or_prefix_len() { None if "." == self.repr || ".." == self.repr => { self.update_normalized(dirname); @@ -207,17 +184,8 @@ impl GenericPathUnsafe for Path { /// # Failure /// /// Raises the `str::not_utf8` condition if not valid UTF-8. - #[inline] - unsafe fn set_filename_unchecked(&mut self, filename: &[u8]) { - if !str::is_utf8(filename) { - let filename = str::from_utf8(filename); // triggers not_utf8 condition - self.set_filename_str_unchecked(filename) - } else { - self.set_filename_str_unchecked(cast::transmute(filename)) - } - } - - unsafe fn set_filename_str_unchecked(&mut self, filename: &str) { + unsafe fn set_filename_unchecked(&mut self, filename: T) { + let filename = filename.container_as_str(); match self.sepidx_or_prefix_len() { None if ".." == self.repr => { let mut s = str::with_capacity(3 + filename.len()); @@ -254,20 +222,6 @@ impl GenericPathUnsafe for Path { /// See `GenericPathUnsafe::push_unchecked`. /// - /// # Failure - /// - /// Raises the `str::not_utf8` condition if not valid UTF-8. - unsafe fn push_unchecked(&mut self, path: &[u8]) { - if !str::is_utf8(path) { - let path = str::from_utf8(path); // triggers not_utf8 condition - self.push_str_unchecked(path); - } else { - self.push_str_unchecked(cast::transmute(path)); - } - } - - /// See `GenericPathUnsafe::push_str_unchecked`. - /// /// Concatenating two Windows Paths is rather complicated. /// For the most part, it will behave as expected, except in the case of /// pushing a volume-relative path, e.g. `C:foo.txt`. Because we have no @@ -276,7 +230,8 @@ impl GenericPathUnsafe for Path { /// the same volume as the new path, it will be treated as the cwd that /// the new path is relative to. Otherwise, the new path will be treated /// as if it were absolute and will replace the receiver outright. - unsafe fn push_str_unchecked(&mut self, path: &str) { + unsafe fn push_unchecked(&mut self, path: T) { + let path = path.container_as_str(); fn is_vol_abs(path: &str, prefix: Option) -> bool { // assume prefix is Some(DiskPrefix) let rest = path.slice_from(prefix_len(prefix)); @@ -357,11 +312,17 @@ impl GenericPathUnsafe for Path { impl GenericPath for Path { #[inline] - fn from_vec_opt(v: &[u8]) -> Option { - if contains_nul(v) || !str::is_utf8(v) { - None - } else { - Some(unsafe { GenericPathUnsafe::from_vec_unchecked(v) }) + fn new_opt(path: T) -> Option { + let s = path.container_as_str_opt(); + match s { + None => None, + Some(s) => { + if contains_nul(s.as_bytes()) { + None + } else { + Some(unsafe { GenericPathUnsafe::new_unchecked(s) }) + } + } } } @@ -372,11 +333,23 @@ impl GenericPath for Path { Some(self.repr.as_slice()) } + /// See `GenericPath::into_str` for info. + /// Always returns a `Some` value. + #[inline] + fn into_str(self) -> Option<~str> { + Some(self.repr) + } + #[inline] fn as_vec<'a>(&'a self) -> &'a [u8] { self.repr.as_bytes() } + #[inline] + fn into_vec(self) -> ~[u8] { + self.repr.into_bytes() + } + #[inline] fn with_display_str(&self, f: &fn(&str) -> T) -> T { f(self.repr.as_slice()) @@ -448,16 +421,16 @@ impl GenericPath for Path { } fn dir_path(&self) -> Path { - unsafe { GenericPathUnsafe::from_str_unchecked(self.dirname_str().unwrap()) } + unsafe { GenericPathUnsafe::new_unchecked(self.dirname_str().unwrap()) } } fn file_path(&self) -> Option { - self.filename_str().map_move(|s| unsafe { GenericPathUnsafe::from_str_unchecked(s) }) + self.filename_str().map_move(|s| unsafe { GenericPathUnsafe::new_unchecked(s) }) } #[inline] fn push_path(&mut self, path: &Path) { - self.push_str(path.as_str().unwrap()) + self.push(path.as_str().unwrap()) } #[inline] @@ -494,14 +467,14 @@ impl GenericPath for Path { fn root_path(&self) -> Option { if self.is_absolute() { - Some(Path::from_str(match self.prefix { + Some(Path::new(match self.prefix { Some(VerbatimDiskPrefix)|Some(DiskPrefix) => { self.repr.slice_to(self.prefix_len()+1) } _ => self.repr.slice_to(self.prefix_len()) })) } else if self.is_vol_relative() { - Some(Path::from_str(self.repr.slice_to(1))) + Some(Path::new(self.repr.slice_to(1))) } else { None } @@ -631,11 +604,10 @@ impl GenericPath for Path { } } } - Some(Path::from_str(comps.connect("\\"))) + Some(Path::new(comps.connect("\\"))) } } - /// Executes a callback with the receiver and every parent fn each_parent(&self, f: &fn(&Path) -> bool) -> bool { let mut p = self.clone(); loop { @@ -649,52 +621,39 @@ impl GenericPath for Path { } true } + + fn ends_with_path(&self, child: &Path) -> bool { + if !child.is_relative() { return false; } + let mut selfit = self.str_component_iter().invert(); + let mut childit = child.str_component_iter().invert(); + loop { + match (selfit.next(), childit.next()) { + (Some(a), Some(b)) => if a != b { return false; }, + (Some(_), None) => break, + (None, Some(_)) => return false, + (None, None) => break + } + } + true + } } impl Path { - /// Returns a new Path from a byte vector + /// Returns a new Path from a byte vector or string /// /// # Failure /// /// Raises the `null_byte` condition if the vector contains a NUL. /// Raises the `str::not_utf8` condition if invalid UTF-8. #[inline] - pub fn from_vec(v: &[u8]) -> Path { - GenericPath::from_vec(v) - } - - /// Returns a new Path from a byte vector, if possible - #[inline] - pub fn from_vec_opt(v: &[u8]) -> Option { - GenericPath::from_vec_opt(v) + pub fn new(path: T) -> Path { + GenericPath::new(path) } - /// Returns a new Path from a string - /// - /// # Failure - /// - /// Raises the `null_byte` condition if the vector contains a NUL. + /// Returns a new Path from a byte vector or string, if possible #[inline] - pub fn from_str(s: &str) -> Path { - GenericPath::from_str(s) - } - - /// Returns a new Path from a string, if possible - #[inline] - pub fn from_str_opt(s: &str) -> Option { - GenericPath::from_str_opt(s) - } - - /// Converts the Path into an owned byte vector - pub fn into_vec(self) -> ~[u8] { - self.repr.into_bytes() - } - - /// Converts the Path into an owned string - /// Returns an Option for compatibility with posix::Path, but the - /// return value will always be Some. - pub fn into_str(self) -> Option<~str> { - Some(self.repr) + pub fn new_opt(path: T) -> Option { + GenericPath::new_opt(path) } /// Returns an iterator that yields each component of the path in turn as a Option<&str>. @@ -745,22 +704,6 @@ impl Path { self.rev_str_component_iter().map(convert) } - /// Returns whether the relative path `child` is a suffix of `self`. - pub fn ends_with_path(&self, child: &Path) -> bool { - if !child.is_relative() { return false; } - let mut selfit = self.str_component_iter().invert(); - let mut childit = child.str_component_iter().invert(); - loop { - match (selfit.next(), childit.next()) { - (Some(a), Some(b)) => if a != b { return false; }, - (Some(_), None) => break, - (None, Some(_)) => return false, - (None, None) => break - } - } - true - } - /// Returns whether the path is considered "volume-relative", which means a path /// that looks like "\foo". Paths of this form are relative to the current volume, /// but absolute within that volume. @@ -1310,102 +1253,103 @@ mod tests { #[test] fn test_paths() { - t!(v: Path::from_vec([]), b!(".")); - t!(v: Path::from_vec(b!("\\")), b!("\\")); - t!(v: Path::from_vec(b!("a\\b\\c")), b!("a\\b\\c")); - - t!(s: Path::from_str(""), "."); - t!(s: Path::from_str("\\"), "\\"); - t!(s: Path::from_str("hi"), "hi"); - t!(s: Path::from_str("hi\\"), "hi"); - t!(s: Path::from_str("\\lib"), "\\lib"); - t!(s: Path::from_str("\\lib\\"), "\\lib"); - t!(s: Path::from_str("hi\\there"), "hi\\there"); - t!(s: Path::from_str("hi\\there.txt"), "hi\\there.txt"); - t!(s: Path::from_str("/"), "\\"); - t!(s: Path::from_str("hi/"), "hi"); - t!(s: Path::from_str("/lib"), "\\lib"); - t!(s: Path::from_str("/lib/"), "\\lib"); - t!(s: Path::from_str("hi/there"), "hi\\there"); - - t!(s: Path::from_str("hi\\there\\"), "hi\\there"); - t!(s: Path::from_str("hi\\..\\there"), "there"); - t!(s: Path::from_str("hi/../there"), "there"); - t!(s: Path::from_str("..\\hi\\there"), "..\\hi\\there"); - t!(s: Path::from_str("\\..\\hi\\there"), "\\hi\\there"); - t!(s: Path::from_str("/../hi/there"), "\\hi\\there"); - t!(s: Path::from_str("foo\\.."), "."); - t!(s: Path::from_str("\\foo\\.."), "\\"); - t!(s: Path::from_str("\\foo\\..\\.."), "\\"); - t!(s: Path::from_str("\\foo\\..\\..\\bar"), "\\bar"); - t!(s: Path::from_str("\\.\\hi\\.\\there\\."), "\\hi\\there"); - t!(s: Path::from_str("\\.\\hi\\.\\there\\.\\.."), "\\hi"); - t!(s: Path::from_str("foo\\..\\.."), ".."); - t!(s: Path::from_str("foo\\..\\..\\.."), "..\\.."); - t!(s: Path::from_str("foo\\..\\..\\bar"), "..\\bar"); - - assert_eq!(Path::from_vec(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned()); - assert_eq!(Path::from_vec(b!("\\foo\\..\\..\\bar")).into_vec(), + let empty: &[u8] = []; + t!(v: Path::new(empty), b!(".")); + t!(v: Path::new(b!("\\")), b!("\\")); + t!(v: Path::new(b!("a\\b\\c")), b!("a\\b\\c")); + + t!(s: Path::new(""), "."); + t!(s: Path::new("\\"), "\\"); + t!(s: Path::new("hi"), "hi"); + t!(s: Path::new("hi\\"), "hi"); + t!(s: Path::new("\\lib"), "\\lib"); + t!(s: Path::new("\\lib\\"), "\\lib"); + t!(s: Path::new("hi\\there"), "hi\\there"); + t!(s: Path::new("hi\\there.txt"), "hi\\there.txt"); + t!(s: Path::new("/"), "\\"); + t!(s: Path::new("hi/"), "hi"); + t!(s: Path::new("/lib"), "\\lib"); + t!(s: Path::new("/lib/"), "\\lib"); + t!(s: Path::new("hi/there"), "hi\\there"); + + t!(s: Path::new("hi\\there\\"), "hi\\there"); + t!(s: Path::new("hi\\..\\there"), "there"); + t!(s: Path::new("hi/../there"), "there"); + t!(s: Path::new("..\\hi\\there"), "..\\hi\\there"); + t!(s: Path::new("\\..\\hi\\there"), "\\hi\\there"); + t!(s: Path::new("/../hi/there"), "\\hi\\there"); + t!(s: Path::new("foo\\.."), "."); + t!(s: Path::new("\\foo\\.."), "\\"); + t!(s: Path::new("\\foo\\..\\.."), "\\"); + t!(s: Path::new("\\foo\\..\\..\\bar"), "\\bar"); + t!(s: Path::new("\\.\\hi\\.\\there\\."), "\\hi\\there"); + t!(s: Path::new("\\.\\hi\\.\\there\\.\\.."), "\\hi"); + t!(s: Path::new("foo\\..\\.."), ".."); + t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); + t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); + + assert_eq!(Path::new(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned()); + assert_eq!(Path::new(b!("\\foo\\..\\..\\bar")).into_vec(), b!("\\bar").to_owned()); - assert_eq!(Path::from_str("foo\\bar").into_str(), Some(~"foo\\bar")); - assert_eq!(Path::from_str("\\foo\\..\\..\\bar").into_str(), Some(~"\\bar")); - - t!(s: Path::from_str("\\\\a"), "\\a"); - t!(s: Path::from_str("\\\\a\\"), "\\a"); - t!(s: Path::from_str("\\\\a\\b"), "\\\\a\\b"); - t!(s: Path::from_str("\\\\a\\b\\"), "\\\\a\\b"); - t!(s: Path::from_str("\\\\a\\b/"), "\\\\a\\b"); - t!(s: Path::from_str("\\\\\\b"), "\\b"); - t!(s: Path::from_str("\\\\a\\\\b"), "\\a\\b"); - t!(s: Path::from_str("\\\\a\\b\\c"), "\\\\a\\b\\c"); - t!(s: Path::from_str("\\\\server\\share/path"), "\\\\server\\share\\path"); - t!(s: Path::from_str("\\\\server/share/path"), "\\\\server\\share\\path"); - t!(s: Path::from_str("C:a\\b.txt"), "C:a\\b.txt"); - t!(s: Path::from_str("C:a/b.txt"), "C:a\\b.txt"); - t!(s: Path::from_str("z:\\a\\b.txt"), "Z:\\a\\b.txt"); - t!(s: Path::from_str("z:/a/b.txt"), "Z:\\a\\b.txt"); - t!(s: Path::from_str("ab:/a/b.txt"), "ab:\\a\\b.txt"); - t!(s: Path::from_str("C:\\"), "C:\\"); - t!(s: Path::from_str("C:"), "C:"); - t!(s: Path::from_str("q:"), "Q:"); - t!(s: Path::from_str("C:/"), "C:\\"); - t!(s: Path::from_str("C:\\foo\\.."), "C:\\"); - t!(s: Path::from_str("C:foo\\.."), "C:"); - t!(s: Path::from_str("C:\\a\\"), "C:\\a"); - t!(s: Path::from_str("C:\\a/"), "C:\\a"); - t!(s: Path::from_str("C:\\a\\b\\"), "C:\\a\\b"); - t!(s: Path::from_str("C:\\a\\b/"), "C:\\a\\b"); - t!(s: Path::from_str("C:a\\"), "C:a"); - t!(s: Path::from_str("C:a/"), "C:a"); - t!(s: Path::from_str("C:a\\b\\"), "C:a\\b"); - t!(s: Path::from_str("C:a\\b/"), "C:a\\b"); - t!(s: Path::from_str("\\\\?\\z:\\a\\b.txt"), "\\\\?\\z:\\a\\b.txt"); - t!(s: Path::from_str("\\\\?\\C:/a/b.txt"), "\\\\?\\C:/a/b.txt"); - t!(s: Path::from_str("\\\\?\\C:\\a/b.txt"), "\\\\?\\C:\\a/b.txt"); - t!(s: Path::from_str("\\\\?\\test\\a\\b.txt"), "\\\\?\\test\\a\\b.txt"); - t!(s: Path::from_str("\\\\?\\foo\\bar\\"), "\\\\?\\foo\\bar\\"); - t!(s: Path::from_str("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); - t!(s: Path::from_str("\\\\.\\"), "\\\\.\\"); - t!(s: Path::from_str("\\\\?\\UNC\\server\\share\\foo"), "\\\\?\\UNC\\server\\share\\foo"); - t!(s: Path::from_str("\\\\?\\UNC\\server/share"), "\\\\?\\UNC\\server/share\\"); - t!(s: Path::from_str("\\\\?\\UNC\\server"), "\\\\?\\UNC\\server\\"); - t!(s: Path::from_str("\\\\?\\UNC\\"), "\\\\?\\UNC\\\\"); - t!(s: Path::from_str("\\\\?\\UNC"), "\\\\?\\UNC"); + assert_eq!(Path::new("foo\\bar").into_str(), Some(~"foo\\bar")); + assert_eq!(Path::new("\\foo\\..\\..\\bar").into_str(), Some(~"\\bar")); + + t!(s: Path::new("\\\\a"), "\\a"); + t!(s: Path::new("\\\\a\\"), "\\a"); + t!(s: Path::new("\\\\a\\b"), "\\\\a\\b"); + t!(s: Path::new("\\\\a\\b\\"), "\\\\a\\b"); + t!(s: Path::new("\\\\a\\b/"), "\\\\a\\b"); + t!(s: Path::new("\\\\\\b"), "\\b"); + t!(s: Path::new("\\\\a\\\\b"), "\\a\\b"); + t!(s: Path::new("\\\\a\\b\\c"), "\\\\a\\b\\c"); + t!(s: Path::new("\\\\server\\share/path"), "\\\\server\\share\\path"); + t!(s: Path::new("\\\\server/share/path"), "\\\\server\\share\\path"); + t!(s: Path::new("C:a\\b.txt"), "C:a\\b.txt"); + t!(s: Path::new("C:a/b.txt"), "C:a\\b.txt"); + t!(s: Path::new("z:\\a\\b.txt"), "Z:\\a\\b.txt"); + t!(s: Path::new("z:/a/b.txt"), "Z:\\a\\b.txt"); + t!(s: Path::new("ab:/a/b.txt"), "ab:\\a\\b.txt"); + t!(s: Path::new("C:\\"), "C:\\"); + t!(s: Path::new("C:"), "C:"); + t!(s: Path::new("q:"), "Q:"); + t!(s: Path::new("C:/"), "C:\\"); + t!(s: Path::new("C:\\foo\\.."), "C:\\"); + t!(s: Path::new("C:foo\\.."), "C:"); + t!(s: Path::new("C:\\a\\"), "C:\\a"); + t!(s: Path::new("C:\\a/"), "C:\\a"); + t!(s: Path::new("C:\\a\\b\\"), "C:\\a\\b"); + t!(s: Path::new("C:\\a\\b/"), "C:\\a\\b"); + t!(s: Path::new("C:a\\"), "C:a"); + t!(s: Path::new("C:a/"), "C:a"); + t!(s: Path::new("C:a\\b\\"), "C:a\\b"); + t!(s: Path::new("C:a\\b/"), "C:a\\b"); + t!(s: Path::new("\\\\?\\z:\\a\\b.txt"), "\\\\?\\z:\\a\\b.txt"); + t!(s: Path::new("\\\\?\\C:/a/b.txt"), "\\\\?\\C:/a/b.txt"); + t!(s: Path::new("\\\\?\\C:\\a/b.txt"), "\\\\?\\C:\\a/b.txt"); + t!(s: Path::new("\\\\?\\test\\a\\b.txt"), "\\\\?\\test\\a\\b.txt"); + t!(s: Path::new("\\\\?\\foo\\bar\\"), "\\\\?\\foo\\bar\\"); + t!(s: Path::new("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); + t!(s: Path::new("\\\\.\\"), "\\\\.\\"); + t!(s: Path::new("\\\\?\\UNC\\server\\share\\foo"), "\\\\?\\UNC\\server\\share\\foo"); + t!(s: Path::new("\\\\?\\UNC\\server/share"), "\\\\?\\UNC\\server/share\\"); + t!(s: Path::new("\\\\?\\UNC\\server"), "\\\\?\\UNC\\server\\"); + t!(s: Path::new("\\\\?\\UNC\\"), "\\\\?\\UNC\\\\"); + t!(s: Path::new("\\\\?\\UNC"), "\\\\?\\UNC"); // I'm not sure whether \\.\foo/bar should normalize to \\.\foo\bar // as information is sparse and this isn't really googleable. // I'm going to err on the side of not normalizing it, as this skips the filesystem - t!(s: Path::from_str("\\\\.\\foo/bar"), "\\\\.\\foo/bar"); - t!(s: Path::from_str("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); + t!(s: Path::new("\\\\.\\foo/bar"), "\\\\.\\foo/bar"); + t!(s: Path::new("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); } #[test] fn test_opt_paths() { - assert_eq!(Path::from_vec_opt(b!("foo\\bar", 0)), None); - assert_eq!(Path::from_vec_opt(b!("foo\\bar", 0x80)), None); - t!(v: Path::from_vec_opt(b!("foo\\bar")).unwrap(), b!("foo\\bar")); - assert_eq!(Path::from_str_opt("foo\\bar\0"), None); - t!(s: Path::from_str_opt("foo\\bar").unwrap(), "foo\\bar"); + assert_eq!(Path::new_opt(b!("foo\\bar", 0)), None); + assert_eq!(Path::new_opt(b!("foo\\bar", 0x80)), None); + t!(v: Path::new_opt(b!("foo\\bar")).unwrap(), b!("foo\\bar")); + assert_eq!(Path::new_opt("foo\\bar\0"), None); + t!(s: Path::new_opt("foo\\bar").unwrap(), "foo\\bar"); } #[test] @@ -1418,7 +1362,7 @@ mod tests { assert_eq!(v.as_slice(), b!("foo\\bar", 0)); (b!("\\bar").to_owned()) }).inside { - Path::from_vec(b!("foo\\bar", 0)) + Path::new(b!("foo\\bar", 0)) }; assert!(handled); assert_eq!(p.as_vec(), b!("\\bar")); @@ -1478,12 +1422,12 @@ mod tests { do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { - Path::from_vec(b!("foo\\bar", 0)) + Path::new(b!("foo\\bar", 0)) }; }) t!(~"set_filename w\\nul" => { - let mut p = Path::from_vec(b!("foo\\bar")); + let mut p = Path::new(b!("foo\\bar")); do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { @@ -1492,7 +1436,7 @@ mod tests { }) t!(~"set_dirname w\\nul" => { - let mut p = Path::from_vec(b!("foo\\bar")); + let mut p = Path::new(b!("foo\\bar")); do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { @@ -1501,7 +1445,7 @@ mod tests { }) t!(~"push w\\nul" => { - let mut p = Path::from_vec(b!("foo\\bar")); + let mut p = Path::new(b!("foo\\bar")); do cond.trap(|_| { (b!("null", 0).to_owned()) }).inside { @@ -1513,22 +1457,22 @@ mod tests { #[test] #[should_fail] fn test_not_utf8_fail() { - Path::from_vec(b!("hello", 0x80, ".txt")); + Path::new(b!("hello", 0x80, ".txt")); } #[test] fn test_display_str() { - assert_eq!(Path::from_str("foo").to_display_str(), ~"foo"); - assert_eq!(Path::from_vec(b!("\\")).to_filename_display_str(), None); + assert_eq!(Path::new("foo").to_display_str(), ~"foo"); + assert_eq!(Path::new(b!("\\")).to_filename_display_str(), None); let mut called = false; - do Path::from_str("foo").with_display_str |s| { + do Path::new("foo").with_display_str |s| { assert_eq!(s, "foo"); called = true; }; assert!(called); called = false; - do Path::from_vec(b!("\\")).with_filename_display_str |s| { + do Path::new(b!("\\")).with_filename_display_str |s| { assert!(s.is_none()); called = true; } @@ -1540,7 +1484,7 @@ mod tests { macro_rules! t( ($path:expr, $exp:expr, $expf:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let f = format!("{}", path.display()); assert_eq!(f.as_slice(), $exp); let f = format!("{}", path.filename_display()); @@ -1559,20 +1503,20 @@ mod tests { macro_rules! t( (s: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); assert_eq!(path.$op(), Some($exp)); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let left = path.$op(); assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::from_vec($path); + let path = Path::new($path); assert_eq!(path.$op(), $exp); } ) @@ -1681,10 +1625,10 @@ mod tests { { let path = ($path); let join = ($join); - let mut p1 = Path::from_str(path); + let mut p1 = Path::new(path); let p2 = p1.clone(); - p1.push_str(join); - assert_eq!(p1, p2.join_str(join)); + p1.push(join); + assert_eq!(p1, p2.join(join)); } ) ) @@ -1693,19 +1637,19 @@ mod tests { t!(s: "\\a\\b\\c", "d"); t!(s: "a\\b", "c\\d"); t!(s: "a\\b", "\\c\\d"); - // this is just a sanity-check test. push_str and join_str share an implementation, + // this is just a sanity-check test. push and join share an implementation, // so there's no need for the full set of prefix tests // we do want to check one odd case though to ensure the prefix is re-parsed - let mut p = Path::from_str("\\\\?\\C:"); + let mut p = Path::new("\\\\?\\C:"); assert_eq!(p.prefix(), Some(VerbatimPrefix(2))); - p.push_str("foo"); + p.push("foo"); assert_eq!(p.prefix(), Some(VerbatimDiskPrefix)); assert_eq!(p.as_str(), Some("\\\\?\\C:\\foo")); // and another with verbatim non-normalized paths - let mut p = Path::from_str("\\\\?\\C:\\a\\"); - p.push_str("foo"); + let mut p = Path::new("\\\\?\\C:\\a\\"); + p.push("foo"); assert_eq!(p.as_str(), Some("\\\\?\\C:\\a\\foo")); } @@ -1714,8 +1658,8 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::from_str($path); - let push = Path::from_str($push); + let mut p = Path::new($path); + let push = Path::new($push); p.push_path(&push); assert_eq!(p.as_str(), Some($exp)); } @@ -1766,14 +1710,14 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::from_str($path); - p.push_many_str($push); + let mut p = Path::new($path); + p.push_many($push); assert_eq!(p.as_str(), Some($exp)); } ); (v: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::from_vec($path); + let mut p = Path::new($path); p.push_many($push); assert_eq!(p.as_vec(), $exp); } @@ -1798,7 +1742,7 @@ mod tests { (s: $path:expr, $left:expr, $right:expr) => ( { let pstr = $path; - let mut p = Path::from_str(pstr); + let mut p = Path::new(pstr); let file = p.pop_str(); let left = $left; assert!(p.as_str() == Some(left), @@ -1812,7 +1756,7 @@ mod tests { ); (v: [$($path:expr),+], [$($left:expr),+], Some($($right:expr),+)) => ( { - let mut p = Path::from_vec(b!($($path),+)); + let mut p = Path::new(b!($($path),+)); let file = p.pop(); assert_eq!(p.as_vec(), b!($($left),+)); assert_eq!(file.map(|v| v.as_slice()), Some(b!($($right),+))); @@ -1820,7 +1764,7 @@ mod tests { ); (v: [$($path:expr),+], [$($left:expr),+], None) => ( { - let mut p = Path::from_vec(b!($($path),+)); + let mut p = Path::new(b!($($path),+)); let file = p.pop(); assert_eq!(p.as_vec(), b!($($left),+)); assert_eq!(file, None); @@ -1866,28 +1810,28 @@ mod tests { #[test] fn test_root_path() { - assert_eq!(Path::from_str("a\\b\\c").root_path(), None); - assert_eq!(Path::from_str("\\a\\b\\c").root_path(), Some(Path::from_str("\\"))); - assert_eq!(Path::from_str("C:a").root_path(), None); - assert_eq!(Path::from_str("C:\\a").root_path(), Some(Path::from_str("C:\\"))); - assert_eq!(Path::from_str("\\\\a\\b\\c").root_path(), Some(Path::from_str("\\\\a\\b"))); - assert_eq!(Path::from_str("\\\\?\\a\\b").root_path(), Some(Path::from_str("\\\\?\\a"))); - assert_eq!(Path::from_str("\\\\?\\C:\\a").root_path(), Some(Path::from_str("\\\\?\\C:\\"))); - assert_eq!(Path::from_str("\\\\?\\UNC\\a\\b\\c").root_path(), - Some(Path::from_str("\\\\?\\UNC\\a\\b"))); - assert_eq!(Path::from_str("\\\\.\\a\\b").root_path(), Some(Path::from_str("\\\\.\\a"))); + assert_eq!(Path::new("a\\b\\c").root_path(), None); + assert_eq!(Path::new("\\a\\b\\c").root_path(), Some(Path::new("\\"))); + assert_eq!(Path::new("C:a").root_path(), None); + assert_eq!(Path::new("C:\\a").root_path(), Some(Path::new("C:\\"))); + assert_eq!(Path::new("\\\\a\\b\\c").root_path(), Some(Path::new("\\\\a\\b"))); + assert_eq!(Path::new("\\\\?\\a\\b").root_path(), Some(Path::new("\\\\?\\a"))); + assert_eq!(Path::new("\\\\?\\C:\\a").root_path(), Some(Path::new("\\\\?\\C:\\"))); + assert_eq!(Path::new("\\\\?\\UNC\\a\\b\\c").root_path(), + Some(Path::new("\\\\?\\UNC\\a\\b"))); + assert_eq!(Path::new("\\\\.\\a\\b").root_path(), Some(Path::new("\\\\.\\a"))); } #[test] fn test_join() { - t!(s: Path::from_str("a\\b\\c").join_str(".."), "a\\b"); - t!(s: Path::from_str("\\a\\b\\c").join_str("d"), "\\a\\b\\c\\d"); - t!(s: Path::from_str("a\\b").join_str("c\\d"), "a\\b\\c\\d"); - t!(s: Path::from_str("a\\b").join_str("\\c\\d"), "\\c\\d"); - t!(s: Path::from_str(".").join_str("a\\b"), "a\\b"); - t!(s: Path::from_str("\\").join_str("a\\b"), "\\a\\b"); - t!(v: Path::from_vec(b!("a\\b\\c")).join(b!("..")), b!("a\\b")); - t!(v: Path::from_vec(b!("\\a\\b\\c")).join(b!("d")), b!("\\a\\b\\c\\d")); + t!(s: Path::new("a\\b\\c").join(".."), "a\\b"); + t!(s: Path::new("\\a\\b\\c").join("d"), "\\a\\b\\c\\d"); + t!(s: Path::new("a\\b").join("c\\d"), "a\\b\\c\\d"); + t!(s: Path::new("a\\b").join("\\c\\d"), "\\c\\d"); + t!(s: Path::new(".").join("a\\b"), "a\\b"); + t!(s: Path::new("\\").join("a\\b"), "\\a\\b"); + t!(v: Path::new(b!("a\\b\\c")).join(b!("..")), b!("a\\b")); + t!(v: Path::new(b!("\\a\\b\\c")).join(b!("d")), b!("\\a\\b\\c\\d")); // full join testing is covered under test_push_path, so no need for // the full set of prefix tests } @@ -1897,8 +1841,8 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let join = Path::from_str($join); + let path = Path::new($path); + let join = Path::new($join); let res = path.join_path(&join); assert_eq!(res.as_str(), Some($exp)); } @@ -1922,14 +1866,14 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let res = path.join_many_str($join); + let path = Path::new($path); + let res = path.join_many($join); assert_eq!(res.as_str(), Some($exp)); } ); (v: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::from_vec($path); + let path = Path::new($path); let res = path.join_many($join); assert_eq!(res.as_vec(), $exp); } @@ -1953,7 +1897,7 @@ mod tests { (s: $path:expr, $op:ident, $arg:expr, $res:expr) => ( { let pstr = $path; - let path = Path::from_str(pstr); + let path = Path::new(pstr); let arg = $arg; let res = path.$op(arg); let exp = $res; @@ -1963,137 +1907,137 @@ mod tests { } ) ) - t!(s: "a\\b\\c", with_dirname_str, "d", "d\\c"); - t!(s: "a\\b\\c", with_dirname_str, "d\\e", "d\\e\\c"); - t!(s: "a\\b\\c", with_dirname_str, "", "c"); - t!(s: "a\\b\\c", with_dirname_str, "\\", "\\c"); - t!(s: "a\\b\\c", with_dirname_str, "/", "\\c"); - t!(s: "a\\b\\c", with_dirname_str, ".", "c"); - t!(s: "a\\b\\c", with_dirname_str, "..", "..\\c"); - t!(s: "\\", with_dirname_str, "foo", "foo"); - t!(s: "\\", with_dirname_str, "", "."); - t!(s: "\\foo", with_dirname_str, "bar", "bar\\foo"); - t!(s: "..", with_dirname_str, "foo", "foo"); - t!(s: "..\\..", with_dirname_str, "foo", "foo"); - t!(s: "..", with_dirname_str, "", "."); - t!(s: "..\\..", with_dirname_str, "", "."); - t!(s: ".", with_dirname_str, "foo", "foo"); - t!(s: "foo", with_dirname_str, "..", "..\\foo"); - t!(s: "foo", with_dirname_str, "..\\..", "..\\..\\foo"); - t!(s: "C:\\a\\b", with_dirname_str, "foo", "foo\\b"); - t!(s: "foo", with_dirname_str, "C:\\a\\b", "C:\\a\\b\\foo"); - t!(s: "C:a\\b", with_dirname_str, "\\\\server\\share", "\\\\server\\share\\b"); - t!(s: "a", with_dirname_str, "\\\\server\\share", "\\\\server\\share\\a"); - t!(s: "a\\b", with_dirname_str, "\\\\?\\", "\\\\?\\b"); - t!(s: "a\\b", with_dirname_str, "C:", "C:b"); - t!(s: "a\\b", with_dirname_str, "C:\\", "C:\\b"); - t!(s: "a\\b", with_dirname_str, "C:/", "C:\\b"); - t!(s: "C:\\", with_dirname_str, "foo", "foo"); - t!(s: "C:", with_dirname_str, "foo", "foo"); - t!(s: ".", with_dirname_str, "C:\\", "C:\\"); - t!(s: ".", with_dirname_str, "C:/", "C:\\"); - t!(s: "\\\\?\\C:\\foo", with_dirname_str, "C:\\", "C:\\foo"); - t!(s: "\\\\?\\C:\\", with_dirname_str, "bar", "bar"); - t!(s: "foo\\bar", with_dirname_str, "\\\\?\\C:\\baz", "\\\\?\\C:\\baz\\bar"); - t!(s: "\\\\?\\foo", with_dirname_str, "C:\\bar", "C:\\bar"); - t!(s: "\\\\?\\a\\foo", with_dirname_str, "C:\\bar", "C:\\bar\\foo"); - t!(s: "\\\\?\\a\\foo/bar", with_dirname_str, "C:\\baz", "C:\\baz\\foo\\bar"); - t!(s: "\\\\?\\UNC\\server\\share\\baz", with_dirname_str, "a", "a\\baz"); - t!(s: "foo\\bar", with_dirname_str, "\\\\?\\UNC\\server\\share\\baz", + t!(s: "a\\b\\c", with_dirname, "d", "d\\c"); + t!(s: "a\\b\\c", with_dirname, "d\\e", "d\\e\\c"); + t!(s: "a\\b\\c", with_dirname, "", "c"); + t!(s: "a\\b\\c", with_dirname, "\\", "\\c"); + t!(s: "a\\b\\c", with_dirname, "/", "\\c"); + t!(s: "a\\b\\c", with_dirname, ".", "c"); + t!(s: "a\\b\\c", with_dirname, "..", "..\\c"); + t!(s: "\\", with_dirname, "foo", "foo"); + t!(s: "\\", with_dirname, "", "."); + t!(s: "\\foo", with_dirname, "bar", "bar\\foo"); + t!(s: "..", with_dirname, "foo", "foo"); + t!(s: "..\\..", with_dirname, "foo", "foo"); + t!(s: "..", with_dirname, "", "."); + t!(s: "..\\..", with_dirname, "", "."); + t!(s: ".", with_dirname, "foo", "foo"); + t!(s: "foo", with_dirname, "..", "..\\foo"); + t!(s: "foo", with_dirname, "..\\..", "..\\..\\foo"); + t!(s: "C:\\a\\b", with_dirname, "foo", "foo\\b"); + t!(s: "foo", with_dirname, "C:\\a\\b", "C:\\a\\b\\foo"); + t!(s: "C:a\\b", with_dirname, "\\\\server\\share", "\\\\server\\share\\b"); + t!(s: "a", with_dirname, "\\\\server\\share", "\\\\server\\share\\a"); + t!(s: "a\\b", with_dirname, "\\\\?\\", "\\\\?\\b"); + t!(s: "a\\b", with_dirname, "C:", "C:b"); + t!(s: "a\\b", with_dirname, "C:\\", "C:\\b"); + t!(s: "a\\b", with_dirname, "C:/", "C:\\b"); + t!(s: "C:\\", with_dirname, "foo", "foo"); + t!(s: "C:", with_dirname, "foo", "foo"); + t!(s: ".", with_dirname, "C:\\", "C:\\"); + t!(s: ".", with_dirname, "C:/", "C:\\"); + t!(s: "\\\\?\\C:\\foo", with_dirname, "C:\\", "C:\\foo"); + t!(s: "\\\\?\\C:\\", with_dirname, "bar", "bar"); + t!(s: "foo\\bar", with_dirname, "\\\\?\\C:\\baz", "\\\\?\\C:\\baz\\bar"); + t!(s: "\\\\?\\foo", with_dirname, "C:\\bar", "C:\\bar"); + t!(s: "\\\\?\\a\\foo", with_dirname, "C:\\bar", "C:\\bar\\foo"); + t!(s: "\\\\?\\a\\foo/bar", with_dirname, "C:\\baz", "C:\\baz\\foo\\bar"); + t!(s: "\\\\?\\UNC\\server\\share\\baz", with_dirname, "a", "a\\baz"); + t!(s: "foo\\bar", with_dirname, "\\\\?\\UNC\\server\\share\\baz", "\\\\?\\UNC\\server\\share\\baz\\bar"); - t!(s: "\\\\.\\foo", with_dirname_str, "bar", "bar"); - t!(s: "\\\\.\\foo\\bar", with_dirname_str, "baz", "baz\\bar"); - t!(s: "\\\\.\\foo\\bar", with_dirname_str, "baz\\", "baz\\bar"); - t!(s: "\\\\.\\foo\\bar", with_dirname_str, "baz/", "baz\\bar"); - - t!(s: "a\\b\\c", with_filename_str, "d", "a\\b\\d"); - t!(s: ".", with_filename_str, "foo", "foo"); - t!(s: "\\a\\b\\c", with_filename_str, "d", "\\a\\b\\d"); - t!(s: "\\", with_filename_str, "foo", "\\foo"); - t!(s: "\\a", with_filename_str, "foo", "\\foo"); - t!(s: "foo", with_filename_str, "bar", "bar"); - t!(s: "\\", with_filename_str, "foo\\", "\\foo"); - t!(s: "\\a", with_filename_str, "foo\\", "\\foo"); - t!(s: "a\\b\\c", with_filename_str, "", "a\\b"); - t!(s: "a\\b\\c", with_filename_str, ".", "a\\b"); - t!(s: "a\\b\\c", with_filename_str, "..", "a"); - t!(s: "\\a", with_filename_str, "", "\\"); - t!(s: "foo", with_filename_str, "", "."); - t!(s: "a\\b\\c", with_filename_str, "d\\e", "a\\b\\d\\e"); - t!(s: "a\\b\\c", with_filename_str, "\\d", "a\\b\\d"); - t!(s: "..", with_filename_str, "foo", "..\\foo"); - t!(s: "..\\..", with_filename_str, "foo", "..\\..\\foo"); - t!(s: "..", with_filename_str, "", ".."); - t!(s: "..\\..", with_filename_str, "", "..\\.."); - t!(s: "C:\\foo\\bar", with_filename_str, "baz", "C:\\foo\\baz"); - t!(s: "C:\\foo", with_filename_str, "bar", "C:\\bar"); - t!(s: "C:\\", with_filename_str, "foo", "C:\\foo"); - t!(s: "C:foo\\bar", with_filename_str, "baz", "C:foo\\baz"); - t!(s: "C:foo", with_filename_str, "bar", "C:bar"); - t!(s: "C:", with_filename_str, "foo", "C:foo"); - t!(s: "C:\\foo", with_filename_str, "", "C:\\"); - t!(s: "C:foo", with_filename_str, "", "C:"); - t!(s: "C:\\foo\\bar", with_filename_str, "..", "C:\\"); - t!(s: "C:\\foo", with_filename_str, "..", "C:\\"); - t!(s: "C:\\", with_filename_str, "..", "C:\\"); - t!(s: "C:foo\\bar", with_filename_str, "..", "C:"); - t!(s: "C:foo", with_filename_str, "..", "C:.."); - t!(s: "C:", with_filename_str, "..", "C:.."); - t!(s: "\\\\server\\share\\foo", with_filename_str, "bar", "\\\\server\\share\\bar"); - t!(s: "\\\\server\\share", with_filename_str, "foo", "\\\\server\\share\\foo"); - t!(s: "\\\\server\\share\\foo", with_filename_str, "", "\\\\server\\share"); - t!(s: "\\\\server\\share", with_filename_str, "", "\\\\server\\share"); - t!(s: "\\\\server\\share\\foo", with_filename_str, "..", "\\\\server\\share"); - t!(s: "\\\\server\\share", with_filename_str, "..", "\\\\server\\share"); - t!(s: "\\\\?\\C:\\foo\\bar", with_filename_str, "baz", "\\\\?\\C:\\foo\\baz"); - t!(s: "\\\\?\\C:\\foo", with_filename_str, "bar", "\\\\?\\C:\\bar"); - t!(s: "\\\\?\\C:\\", with_filename_str, "foo", "\\\\?\\C:\\foo"); - t!(s: "\\\\?\\C:\\foo", with_filename_str, "..", "\\\\?\\C:\\.."); - t!(s: "\\\\?\\foo\\bar", with_filename_str, "baz", "\\\\?\\foo\\baz"); - t!(s: "\\\\?\\foo", with_filename_str, "bar", "\\\\?\\foo\\bar"); - t!(s: "\\\\?\\", with_filename_str, "foo", "\\\\?\\\\foo"); - t!(s: "\\\\?\\foo\\bar", with_filename_str, "..", "\\\\?\\foo\\.."); - t!(s: "\\\\.\\foo\\bar", with_filename_str, "baz", "\\\\.\\foo\\baz"); - t!(s: "\\\\.\\foo", with_filename_str, "bar", "\\\\.\\foo\\bar"); - t!(s: "\\\\.\\foo\\bar", with_filename_str, "..", "\\\\.\\foo\\.."); - - t!(s: "hi\\there.txt", with_filestem_str, "here", "hi\\here.txt"); - t!(s: "hi\\there.txt", with_filestem_str, "", "hi\\.txt"); - t!(s: "hi\\there.txt", with_filestem_str, ".", "hi\\..txt"); - t!(s: "hi\\there.txt", with_filestem_str, "..", "hi\\...txt"); - t!(s: "hi\\there.txt", with_filestem_str, "\\", "hi\\.txt"); - t!(s: "hi\\there.txt", with_filestem_str, "foo\\bar", "hi\\foo\\bar.txt"); - t!(s: "hi\\there.foo.txt", with_filestem_str, "here", "hi\\here.txt"); - t!(s: "hi\\there", with_filestem_str, "here", "hi\\here"); - t!(s: "hi\\there", with_filestem_str, "", "hi"); - t!(s: "hi", with_filestem_str, "", "."); - t!(s: "\\hi", with_filestem_str, "", "\\"); - t!(s: "hi\\there", with_filestem_str, "..", "."); - t!(s: "hi\\there", with_filestem_str, ".", "hi"); - t!(s: "hi\\there.", with_filestem_str, "foo", "hi\\foo."); - t!(s: "hi\\there.", with_filestem_str, "", "hi"); - t!(s: "hi\\there.", with_filestem_str, ".", "."); - t!(s: "hi\\there.", with_filestem_str, "..", "hi\\..."); - t!(s: "\\", with_filestem_str, "foo", "\\foo"); - t!(s: ".", with_filestem_str, "foo", "foo"); - t!(s: "hi\\there..", with_filestem_str, "here", "hi\\here."); - t!(s: "hi\\there..", with_filestem_str, "", "hi"); + t!(s: "\\\\.\\foo", with_dirname, "bar", "bar"); + t!(s: "\\\\.\\foo\\bar", with_dirname, "baz", "baz\\bar"); + t!(s: "\\\\.\\foo\\bar", with_dirname, "baz\\", "baz\\bar"); + t!(s: "\\\\.\\foo\\bar", with_dirname, "baz/", "baz\\bar"); + + t!(s: "a\\b\\c", with_filename, "d", "a\\b\\d"); + t!(s: ".", with_filename, "foo", "foo"); + t!(s: "\\a\\b\\c", with_filename, "d", "\\a\\b\\d"); + t!(s: "\\", with_filename, "foo", "\\foo"); + t!(s: "\\a", with_filename, "foo", "\\foo"); + t!(s: "foo", with_filename, "bar", "bar"); + t!(s: "\\", with_filename, "foo\\", "\\foo"); + t!(s: "\\a", with_filename, "foo\\", "\\foo"); + t!(s: "a\\b\\c", with_filename, "", "a\\b"); + t!(s: "a\\b\\c", with_filename, ".", "a\\b"); + t!(s: "a\\b\\c", with_filename, "..", "a"); + t!(s: "\\a", with_filename, "", "\\"); + t!(s: "foo", with_filename, "", "."); + t!(s: "a\\b\\c", with_filename, "d\\e", "a\\b\\d\\e"); + t!(s: "a\\b\\c", with_filename, "\\d", "a\\b\\d"); + t!(s: "..", with_filename, "foo", "..\\foo"); + t!(s: "..\\..", with_filename, "foo", "..\\..\\foo"); + t!(s: "..", with_filename, "", ".."); + t!(s: "..\\..", with_filename, "", "..\\.."); + t!(s: "C:\\foo\\bar", with_filename, "baz", "C:\\foo\\baz"); + t!(s: "C:\\foo", with_filename, "bar", "C:\\bar"); + t!(s: "C:\\", with_filename, "foo", "C:\\foo"); + t!(s: "C:foo\\bar", with_filename, "baz", "C:foo\\baz"); + t!(s: "C:foo", with_filename, "bar", "C:bar"); + t!(s: "C:", with_filename, "foo", "C:foo"); + t!(s: "C:\\foo", with_filename, "", "C:\\"); + t!(s: "C:foo", with_filename, "", "C:"); + t!(s: "C:\\foo\\bar", with_filename, "..", "C:\\"); + t!(s: "C:\\foo", with_filename, "..", "C:\\"); + t!(s: "C:\\", with_filename, "..", "C:\\"); + t!(s: "C:foo\\bar", with_filename, "..", "C:"); + t!(s: "C:foo", with_filename, "..", "C:.."); + t!(s: "C:", with_filename, "..", "C:.."); + t!(s: "\\\\server\\share\\foo", with_filename, "bar", "\\\\server\\share\\bar"); + t!(s: "\\\\server\\share", with_filename, "foo", "\\\\server\\share\\foo"); + t!(s: "\\\\server\\share\\foo", with_filename, "", "\\\\server\\share"); + t!(s: "\\\\server\\share", with_filename, "", "\\\\server\\share"); + t!(s: "\\\\server\\share\\foo", with_filename, "..", "\\\\server\\share"); + t!(s: "\\\\server\\share", with_filename, "..", "\\\\server\\share"); + t!(s: "\\\\?\\C:\\foo\\bar", with_filename, "baz", "\\\\?\\C:\\foo\\baz"); + t!(s: "\\\\?\\C:\\foo", with_filename, "bar", "\\\\?\\C:\\bar"); + t!(s: "\\\\?\\C:\\", with_filename, "foo", "\\\\?\\C:\\foo"); + t!(s: "\\\\?\\C:\\foo", with_filename, "..", "\\\\?\\C:\\.."); + t!(s: "\\\\?\\foo\\bar", with_filename, "baz", "\\\\?\\foo\\baz"); + t!(s: "\\\\?\\foo", with_filename, "bar", "\\\\?\\foo\\bar"); + t!(s: "\\\\?\\", with_filename, "foo", "\\\\?\\\\foo"); + t!(s: "\\\\?\\foo\\bar", with_filename, "..", "\\\\?\\foo\\.."); + t!(s: "\\\\.\\foo\\bar", with_filename, "baz", "\\\\.\\foo\\baz"); + t!(s: "\\\\.\\foo", with_filename, "bar", "\\\\.\\foo\\bar"); + t!(s: "\\\\.\\foo\\bar", with_filename, "..", "\\\\.\\foo\\.."); + + t!(s: "hi\\there.txt", with_filestem, "here", "hi\\here.txt"); + t!(s: "hi\\there.txt", with_filestem, "", "hi\\.txt"); + t!(s: "hi\\there.txt", with_filestem, ".", "hi\\..txt"); + t!(s: "hi\\there.txt", with_filestem, "..", "hi\\...txt"); + t!(s: "hi\\there.txt", with_filestem, "\\", "hi\\.txt"); + t!(s: "hi\\there.txt", with_filestem, "foo\\bar", "hi\\foo\\bar.txt"); + t!(s: "hi\\there.foo.txt", with_filestem, "here", "hi\\here.txt"); + t!(s: "hi\\there", with_filestem, "here", "hi\\here"); + t!(s: "hi\\there", with_filestem, "", "hi"); + t!(s: "hi", with_filestem, "", "."); + t!(s: "\\hi", with_filestem, "", "\\"); + t!(s: "hi\\there", with_filestem, "..", "."); + t!(s: "hi\\there", with_filestem, ".", "hi"); + t!(s: "hi\\there.", with_filestem, "foo", "hi\\foo."); + t!(s: "hi\\there.", with_filestem, "", "hi"); + t!(s: "hi\\there.", with_filestem, ".", "."); + t!(s: "hi\\there.", with_filestem, "..", "hi\\..."); + t!(s: "\\", with_filestem, "foo", "\\foo"); + t!(s: ".", with_filestem, "foo", "foo"); + t!(s: "hi\\there..", with_filestem, "here", "hi\\here."); + t!(s: "hi\\there..", with_filestem, "", "hi"); // filestem setter calls filename setter internally, no need for extended tests - t!(s: "hi\\there.txt", with_extension_str, "exe", "hi\\there.exe"); - t!(s: "hi\\there.txt", with_extension_str, "", "hi\\there"); - t!(s: "hi\\there.txt", with_extension_str, ".", "hi\\there.."); - t!(s: "hi\\there.txt", with_extension_str, "..", "hi\\there..."); - t!(s: "hi\\there", with_extension_str, "txt", "hi\\there.txt"); - t!(s: "hi\\there", with_extension_str, ".", "hi\\there.."); - t!(s: "hi\\there", with_extension_str, "..", "hi\\there..."); - t!(s: "hi\\there.", with_extension_str, "txt", "hi\\there.txt"); - t!(s: "hi\\.foo", with_extension_str, "txt", "hi\\.foo.txt"); - t!(s: "hi\\there.txt", with_extension_str, ".foo", "hi\\there..foo"); - t!(s: "\\", with_extension_str, "txt", "\\"); - t!(s: "\\", with_extension_str, ".", "\\"); - t!(s: "\\", with_extension_str, "..", "\\"); - t!(s: ".", with_extension_str, "txt", "."); + t!(s: "hi\\there.txt", with_extension, "exe", "hi\\there.exe"); + t!(s: "hi\\there.txt", with_extension, "", "hi\\there"); + t!(s: "hi\\there.txt", with_extension, ".", "hi\\there.."); + t!(s: "hi\\there.txt", with_extension, "..", "hi\\there..."); + t!(s: "hi\\there", with_extension, "txt", "hi\\there.txt"); + t!(s: "hi\\there", with_extension, ".", "hi\\there.."); + t!(s: "hi\\there", with_extension, "..", "hi\\there..."); + t!(s: "hi\\there.", with_extension, "txt", "hi\\there.txt"); + t!(s: "hi\\.foo", with_extension, "txt", "hi\\.foo.txt"); + t!(s: "hi\\there.txt", with_extension, ".foo", "hi\\there..foo"); + t!(s: "\\", with_extension, "txt", "\\"); + t!(s: "\\", with_extension, ".", "\\"); + t!(s: "\\", with_extension, "..", "\\"); + t!(s: ".", with_extension, "txt", "."); // extension setter calls filename setter internally, no need for extended tests } @@ -2104,9 +2048,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::from_str(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::from_str(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ); @@ -2114,9 +2058,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::from_vec(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::from_vec(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ) @@ -2124,36 +2068,36 @@ mod tests { t!(v: b!("a\\b\\c"), set_dirname, with_dirname, b!("d")); t!(v: b!("a\\b\\c"), set_dirname, with_dirname, b!("d\\e")); - t!(s: "a\\b\\c", set_dirname_str, with_dirname_str, "d"); - t!(s: "a\\b\\c", set_dirname_str, with_dirname_str, "d\\e"); - t!(s: "\\", set_dirname_str, with_dirname_str, "foo"); - t!(s: "\\foo", set_dirname_str, with_dirname_str, "bar"); - t!(s: "a\\b\\c", set_dirname_str, with_dirname_str, ""); - t!(s: "..\\..", set_dirname_str, with_dirname_str, "x"); - t!(s: "foo", set_dirname_str, with_dirname_str, "..\\.."); + t!(s: "a\\b\\c", set_dirname, with_dirname, "d"); + t!(s: "a\\b\\c", set_dirname, with_dirname, "d\\e"); + t!(s: "\\", set_dirname, with_dirname, "foo"); + t!(s: "\\foo", set_dirname, with_dirname, "bar"); + t!(s: "a\\b\\c", set_dirname, with_dirname, ""); + t!(s: "..\\..", set_dirname, with_dirname, "x"); + t!(s: "foo", set_dirname, with_dirname, "..\\.."); t!(v: b!("a\\b\\c"), set_filename, with_filename, b!("d")); t!(v: b!("\\"), set_filename, with_filename, b!("foo")); - t!(s: "a\\b\\c", set_filename_str, with_filename_str, "d"); - t!(s: "\\", set_filename_str, with_filename_str, "foo"); - t!(s: ".", set_filename_str, with_filename_str, "foo"); - t!(s: "a\\b", set_filename_str, with_filename_str, ""); - t!(s: "a", set_filename_str, with_filename_str, ""); + t!(s: "a\\b\\c", set_filename, with_filename, "d"); + t!(s: "\\", set_filename, with_filename, "foo"); + t!(s: ".", set_filename, with_filename, "foo"); + t!(s: "a\\b", set_filename, with_filename, ""); + t!(s: "a", set_filename, with_filename, ""); t!(v: b!("hi\\there.txt"), set_filestem, with_filestem, b!("here")); - t!(s: "hi\\there.txt", set_filestem_str, with_filestem_str, "here"); - t!(s: "hi\\there.", set_filestem_str, with_filestem_str, "here"); - t!(s: "hi\\there", set_filestem_str, with_filestem_str, "here"); - t!(s: "hi\\there.txt", set_filestem_str, with_filestem_str, ""); - t!(s: "hi\\there", set_filestem_str, with_filestem_str, ""); + t!(s: "hi\\there.txt", set_filestem, with_filestem, "here"); + t!(s: "hi\\there.", set_filestem, with_filestem, "here"); + t!(s: "hi\\there", set_filestem, with_filestem, "here"); + t!(s: "hi\\there.txt", set_filestem, with_filestem, ""); + t!(s: "hi\\there", set_filestem, with_filestem, ""); t!(v: b!("hi\\there.txt"), set_extension, with_extension, b!("exe")); - t!(s: "hi\\there.txt", set_extension_str, with_extension_str, "exe"); - t!(s: "hi\\there.", set_extension_str, with_extension_str, "txt"); - t!(s: "hi\\there", set_extension_str, with_extension_str, "txt"); - t!(s: "hi\\there.txt", set_extension_str, with_extension_str, ""); - t!(s: "hi\\there", set_extension_str, with_extension_str, ""); - t!(s: ".", set_extension_str, with_extension_str, "txt"); + t!(s: "hi\\there.txt", set_extension, with_extension, "exe"); + t!(s: "hi\\there.", set_extension, with_extension, "txt"); + t!(s: "hi\\there", set_extension, with_extension, "txt"); + t!(s: "hi\\there.txt", set_extension, with_extension, ""); + t!(s: "hi\\there", set_extension, with_extension, ""); + t!(s: ".", set_extension, with_extension, "txt"); // with_ helpers use the setter internally, so the tests for the with_ helpers // will suffice. No need for the full set of prefix tests. @@ -2164,14 +2108,14 @@ mod tests { macro_rules! t( (s: $path:expr, $ext:expr, $exp:expr) => ( { - let mut path = Path::from_str($path); - path.add_extension_str($ext); + let mut path = Path::new($path); + path.add_extension($ext); assert_eq!(path.as_str(), Some($exp)); } ); (v: $path:expr, $ext:expr, $exp:expr) => ( { - let mut path = Path::from_vec($path); + let mut path = Path::new($path); path.add_extension($ext); assert_eq!(path.as_vec(), $exp); } @@ -2221,19 +2165,19 @@ mod tests { ) ) - t!(v: Path::from_vec(b!("a\\b\\c")), Some(b!("c")), b!("a\\b"), Some(b!("c")), None); - t!(s: Path::from_str("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None); - t!(s: Path::from_str("."), None, Some("."), None, None); - t!(s: Path::from_str("\\"), None, Some("\\"), None, None); - t!(s: Path::from_str(".."), None, Some(".."), None, None); - t!(s: Path::from_str("..\\.."), None, Some("..\\.."), None, None); - t!(s: Path::from_str("hi\\there.txt"), Some("there.txt"), Some("hi"), + t!(v: Path::new(b!("a\\b\\c")), Some(b!("c")), b!("a\\b"), Some(b!("c")), None); + t!(s: Path::new("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None); + t!(s: Path::new("."), None, Some("."), None, None); + t!(s: Path::new("\\"), None, Some("\\"), None, None); + t!(s: Path::new(".."), None, Some(".."), None, None); + t!(s: Path::new("..\\.."), None, Some("..\\.."), None, None); + t!(s: Path::new("hi\\there.txt"), Some("there.txt"), Some("hi"), Some("there"), Some("txt")); - t!(s: Path::from_str("hi\\there"), Some("there"), Some("hi"), Some("there"), None); - t!(s: Path::from_str("hi\\there."), Some("there."), Some("hi"), + t!(s: Path::new("hi\\there"), Some("there"), Some("hi"), Some("there"), None); + t!(s: Path::new("hi\\there."), Some("there."), Some("hi"), Some("there"), Some("")); - t!(s: Path::from_str("hi\\.there"), Some(".there"), Some("hi"), Some(".there"), None); - t!(s: Path::from_str("hi\\..there"), Some("..there"), Some("hi"), + t!(s: Path::new("hi\\.there"), Some(".there"), Some("hi"), Some(".there"), None); + t!(s: Path::new("hi\\..there"), Some("..there"), Some("hi"), Some("."), Some("there")); // these are already tested in test_components, so no need for extended tests @@ -2241,12 +2185,12 @@ mod tests { #[test] fn test_dir_file_path() { - t!(s: Path::from_str("hi\\there").dir_path(), "hi"); - t!(s: Path::from_str("hi").dir_path(), "."); - t!(s: Path::from_str("\\hi").dir_path(), "\\"); - t!(s: Path::from_str("\\").dir_path(), "\\"); - t!(s: Path::from_str("..").dir_path(), ".."); - t!(s: Path::from_str("..\\..").dir_path(), "..\\.."); + t!(s: Path::new("hi\\there").dir_path(), "hi"); + t!(s: Path::new("hi").dir_path(), "."); + t!(s: Path::new("\\hi").dir_path(), "\\"); + t!(s: Path::new("\\").dir_path(), "\\"); + t!(s: Path::new("..").dir_path(), ".."); + t!(s: Path::new("..\\..").dir_path(), "..\\.."); macro_rules! t( ($path:expr, $exp:expr) => ( @@ -2258,12 +2202,12 @@ mod tests { ); ) - t!(Path::from_str("hi\\there").file_path(), Some("there")); - t!(Path::from_str("hi").file_path(), Some("hi")); - t!(Path::from_str(".").file_path(), None); - t!(Path::from_str("\\").file_path(), None); - t!(Path::from_str("..").file_path(), None); - t!(Path::from_str("..\\..").file_path(), None); + t!(Path::new("hi\\there").file_path(), Some("there")); + t!(Path::new("hi").file_path(), Some("hi")); + t!(Path::new(".").file_path(), None); + t!(Path::new("\\").file_path(), None); + t!(Path::new("..").file_path(), None); + t!(Path::new("..\\..").file_path(), None); // dir_path and file_path are just dirname and filename interpreted as paths. // No need for extended tests @@ -2274,7 +2218,7 @@ mod tests { macro_rules! t( ($path:expr, $abs:expr, $vol:expr, $cwd:expr, $rel:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let (abs, vol, cwd, rel) = ($abs, $vol, $cwd, $rel); let b = path.is_absolute(); assert!(b == abs, "Path '{}'.is_absolute(): expected {:?}, found {:?}", @@ -2314,8 +2258,8 @@ mod tests { macro_rules! t( (s: $path:expr, $dest:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let dest = Path::from_str($dest); + let path = Path::new($path); + let dest = Path::new($dest); let exp = $exp; let res = path.is_ancestor_of(&dest); assert!(res == exp, @@ -2417,8 +2361,8 @@ mod tests { macro_rules! t( (s: $path:expr, $child:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let child = Path::from_str($child); + let path = Path::new($path); + let child = Path::new($child); assert_eq!(path.ends_with_path(&child), $exp); } ); @@ -2449,8 +2393,8 @@ mod tests { macro_rules! t( (s: $path:expr, $other:expr, $exp:expr) => ( { - let path = Path::from_str($path); - let other = Path::from_str($other); + let path = Path::new($path); + let other = Path::new($other); let res = path.path_relative_from(&other); let exp = $exp; assert!(res.and_then_ref(|x| x.as_str()) == exp, @@ -2583,7 +2527,7 @@ mod tests { macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let comps = path.str_component_iter().map(|x|x.unwrap()).to_owned_vec(); let exp: &[&str] = $exp; assert!(comps.as_slice() == exp, @@ -2598,7 +2542,7 @@ mod tests { ); (v: [$($arg:expr),+], $exp:expr) => ( { - let path = Path::from_vec(b!($($arg),+)); + let path = Path::new(b!($($arg),+)); let comps = path.str_component_iter().map(|x|x.unwrap()).to_owned_vec(); let exp: &[&str] = $exp; assert!(comps.as_slice() == exp, @@ -2658,7 +2602,7 @@ mod tests { macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let comps = path.component_iter().to_owned_vec(); let exp: &[&[u8]] = $exp; assert!(comps.as_slice() == exp, "component_iter: Expected {:?}, found {:?}", @@ -2679,13 +2623,13 @@ mod tests { #[test] fn test_each_parent() { - assert!(Path::from_str("/foo/bar").each_parent(|_| true)); - assert!(!Path::from_str("/foo/bar").each_parent(|_| false)); + assert!(Path::new("/foo/bar").each_parent(|_| true)); + assert!(!Path::new("/foo/bar").each_parent(|_| false)); macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::from_str($path); + let path = Path::new($path); let exp: &[&str] = $exp; let mut comps = exp.iter().map(|&x|x); do path.each_parent |p| { diff --git a/src/libstd/rt/io/file.rs b/src/libstd/rt/io/file.rs index 9fbb897c2a7..39c3c5692f8 100644 --- a/src/libstd/rt/io/file.rs +++ b/src/libstd/rt/io/file.rs @@ -703,7 +703,7 @@ mod test { fn file_test_io_smoke_test() { do run_in_mt_newsched_task { let message = "it's alright. have a good time"; - let filename = &Path::from_str("./tmp/file_rt_io_file_test.txt"); + let filename = &Path::new("./tmp/file_rt_io_file_test.txt"); { let mut write_stream = open(filename, Create, ReadWrite).unwrap(); write_stream.write(message.as_bytes()); @@ -725,7 +725,7 @@ mod test { #[test] fn file_test_io_invalid_path_opened_without_create_should_raise_condition() { do run_in_mt_newsched_task { - let filename = &Path::from_str("./tmp/file_that_does_not_exist.txt"); + let filename = &Path::new("./tmp/file_that_does_not_exist.txt"); let mut called = false; do io_error::cond.trap(|_| { called = true; @@ -740,7 +740,7 @@ mod test { #[test] fn file_test_iounlinking_invalid_path_should_raise_condition() { do run_in_mt_newsched_task { - let filename = &Path::from_str("./tmp/file_another_file_that_does_not_exist.txt"); + let filename = &Path::new("./tmp/file_another_file_that_does_not_exist.txt"); let mut called = false; do io_error::cond.trap(|_| { called = true; @@ -757,7 +757,7 @@ mod test { use str; let message = "ten-four"; let mut read_mem = [0, .. 8]; - let filename = &Path::from_str("./tmp/file_rt_io_file_test_positional.txt"); + let filename = &Path::new("./tmp/file_rt_io_file_test_positional.txt"); { let mut rw_stream = open(filename, Create, ReadWrite).unwrap(); rw_stream.write(message.as_bytes()); @@ -788,7 +788,7 @@ mod test { let set_cursor = 4 as u64; let mut tell_pos_pre_read; let mut tell_pos_post_read; - let filename = &Path::from_str("./tmp/file_rt_io_file_test_seeking.txt"); + let filename = &Path::new("./tmp/file_rt_io_file_test_seeking.txt"); { let mut rw_stream = open(filename, Create, ReadWrite).unwrap(); rw_stream.write(message.as_bytes()); @@ -817,7 +817,7 @@ mod test { let final_msg = "foo-the-bar!!"; let seek_idx = 3; let mut read_mem = [0, .. 13]; - let filename = &Path::from_str("./tmp/file_rt_io_file_test_seek_and_write.txt"); + let filename = &Path::new("./tmp/file_rt_io_file_test_seek_and_write.txt"); { let mut rw_stream = open(filename, Create, ReadWrite).unwrap(); rw_stream.write(initial_msg.as_bytes()); @@ -843,7 +843,7 @@ mod test { let chunk_two = "asdf"; let chunk_three = "zxcv"; let mut read_mem = [0, .. 4]; - let filename = &Path::from_str("./tmp/file_rt_io_file_test_seek_shakedown.txt"); + let filename = &Path::new("./tmp/file_rt_io_file_test_seek_shakedown.txt"); { let mut rw_stream = open(filename, Create, ReadWrite).unwrap(); rw_stream.write(initial_msg.as_bytes()); @@ -873,7 +873,7 @@ mod test { #[test] fn file_test_stat_is_correct_on_is_file() { do run_in_mt_newsched_task { - let filename = &Path::from_str("./tmp/file_stat_correct_on_is_file.txt"); + let filename = &Path::new("./tmp/file_stat_correct_on_is_file.txt"); { let mut fs = open(filename, Create, ReadWrite).unwrap(); let msg = "hw"; @@ -891,7 +891,7 @@ mod test { #[test] fn file_test_stat_is_correct_on_is_dir() { do run_in_mt_newsched_task { - let filename = &Path::from_str("./tmp/file_stat_correct_on_is_dir"); + let filename = &Path::new("./tmp/file_stat_correct_on_is_dir"); mkdir(filename); let stat_res = match stat(filename) { Some(s) => s, @@ -905,7 +905,7 @@ mod test { #[test] fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() { do run_in_mt_newsched_task { - let dir = &Path::from_str("./tmp/fileinfo_false_on_dir"); + let dir = &Path::new("./tmp/fileinfo_false_on_dir"); mkdir(dir); assert!(dir.is_file() == false); rmdir(dir); @@ -915,7 +915,7 @@ mod test { #[test] fn file_test_fileinfo_check_exists_before_and_after_file_creation() { do run_in_mt_newsched_task { - let file = &Path::from_str("./tmp/fileinfo_check_exists_b_and_a.txt"); + let file = &Path::new("./tmp/fileinfo_check_exists_b_and_a.txt"); { let msg = "foo".as_bytes(); let mut w = file.open_writer(Create); @@ -930,7 +930,7 @@ mod test { #[test] fn file_test_directoryinfo_check_exists_before_and_after_mkdir() { do run_in_mt_newsched_task { - let dir = &Path::from_str("./tmp/before_and_after_dir"); + let dir = &Path::new("./tmp/before_and_after_dir"); assert!(!dir.exists()); dir.mkdir(); assert!(dir.exists()); @@ -944,11 +944,11 @@ mod test { fn file_test_directoryinfo_readdir() { use str; do run_in_mt_newsched_task { - let dir = &Path::from_str("./tmp/di_readdir"); + let dir = &Path::new("./tmp/di_readdir"); dir.mkdir(); let prefix = "foo"; for n in range(0,3) { - let f = dir.join_str(format!("{}.txt", n)); + let f = dir.join(format!("{}.txt", n)); let mut w = f.open_writer(Create); let msg_str = (prefix + n.to_str().to_owned()).to_owned(); let msg = msg_str.as_bytes(); diff --git a/src/libstd/rt/io/support.rs b/src/libstd/rt/io/support.rs index a872423c255..31040bc51a1 100644 --- a/src/libstd/rt/io/support.rs +++ b/src/libstd/rt/io/support.rs @@ -35,7 +35,7 @@ mod test { #[test] fn path_like_smoke_test() { let expected = if cfg!(unix) { "/home" } else { "C:\\" }; - let path = Path::from_str(expected); + let path = Path::new(expected); path.path_as_str(|p| assert!(p == expected)); path.path_as_str(|p| assert!(p == expected)); } diff --git a/src/libstd/rt/uv/file.rs b/src/libstd/rt/uv/file.rs index 7756448adf8..cb5054626d4 100644 --- a/src/libstd/rt/uv/file.rs +++ b/src/libstd/rt/uv/file.rs @@ -391,7 +391,7 @@ mod test { let read_mem = vec::from_elem(read_buf_len, 0u8); let read_buf = slice_to_uv_buf(read_mem); let read_buf_ptr: *Buf = &read_buf; - let p = Path::from_str(path_str); + let p = Path::new(path_str); let open_req = FsRequest::new(); do open_req.open(&loop_, &p, create_flags as int, mode as int) |req, uverr| { @@ -405,7 +405,7 @@ mod test { assert!(uverr.is_none()); let loop_ = req.get_loop(); let open_req = FsRequest::new(); - do open_req.open(&loop_, &Path::from_str(path_str), read_flags as int,0) + do open_req.open(&loop_, &Path::new(path_str), read_flags as int,0) |req, uverr| { assert!(uverr.is_none()); let loop_ = req.get_loop(); @@ -431,7 +431,7 @@ mod test { assert!(uverr.is_none()); let loop_ = &req.get_loop(); let unlink_req = FsRequest::new(); - do unlink_req.unlink(loop_, &Path::from_str(path_str)) + do unlink_req.unlink(loop_, &Path::new(path_str)) |_,uverr| { assert!(uverr.is_none()); }; @@ -465,7 +465,7 @@ mod test { let write_buf = slice_to_uv_buf(write_val); // open/create let open_req = FsRequest::new(); - let result = open_req.open_sync(&loop_, &Path::from_str(path_str), + let result = open_req.open_sync(&loop_, &Path::new(path_str), create_flags as int, mode as int); assert!(result.is_ok()); let fd = result.unwrap(); @@ -479,7 +479,7 @@ mod test { assert!(result.is_ok()); // re-open let open_req = FsRequest::new(); - let result = open_req.open_sync(&loop_, &Path::from_str(path_str), + let result = open_req.open_sync(&loop_, &Path::new(path_str), read_flags as int,0); assert!(result.is_ok()); let len = 1028; @@ -503,7 +503,7 @@ mod test { assert!(result.is_ok()); // unlink let unlink_req = FsRequest::new(); - let result = unlink_req.unlink_sync(&loop_, &Path::from_str(path_str)); + let result = unlink_req.unlink_sync(&loop_, &Path::new(path_str)); assert!(result.is_ok()); } else { fail2!("nread was 0.. wudn't expectin' that."); } loop_.close(); diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index a139c4e95ef..d5893d6d014 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -18,6 +18,7 @@ use ops::Drop; use option::*; use ptr; use str; +use str::Str; use result::*; use rt::io::IoError; use rt::io::net::ip::{SocketAddr, IpAddr}; @@ -631,7 +632,7 @@ impl IoFactory for UvIoFactory { None => { let stat = req.get_stat(); Ok(FileStat { - path: Path::from_str(path_str), + path: Path::new(path_str.as_slice()), is_file: stat.is_file(), is_dir: stat.is_dir(), size: stat.st_size, @@ -720,8 +721,8 @@ impl IoFactory for UvIoFactory { let rel_paths = req.get_paths(); let mut paths = ~[]; for r in rel_paths.iter() { - let mut p = Path::from_str(path_str); - p.push_str(*r); + let mut p = Path::new(path_str.as_slice()); + p.push(r.as_slice()); paths.push(p); } Ok(paths) @@ -2179,20 +2180,20 @@ fn file_test_uvio_full_simple_impl() { { let create_fm = Create; let create_fa = ReadWrite; - let mut fd = (*io).fs_open(&Path::from_str(path), create_fm, create_fa).unwrap(); + let mut fd = (*io).fs_open(&Path::new(path), create_fm, create_fa).unwrap(); let write_buf = write_val.as_bytes(); fd.write(write_buf); } { let ro_fm = Open; let ro_fa = Read; - let mut fd = (*io).fs_open(&Path::from_str(path), ro_fm, ro_fa).unwrap(); + let mut fd = (*io).fs_open(&Path::new(path), ro_fm, ro_fa).unwrap(); let mut read_vec = [0, .. 1028]; let nread = fd.read(read_vec).unwrap(); let read_val = str::from_utf8(read_vec.slice(0, nread as uint)); assert!(read_val == write_val.to_owned()); } - (*io).fs_unlink(&Path::from_str(path)); + (*io).fs_unlink(&Path::new(path)); } } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 3f7ce3eae58..0d32efbba88 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -579,7 +579,7 @@ mod tests { let output = str::from_utf8(prog.finish_with_output().output); let parent_dir = os::getcwd(); - let child_dir = Path::from_str(output.trim()); + let child_dir = Path::new(output.trim()); let parent_stat = parent_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap(); @@ -596,7 +596,7 @@ mod tests { let mut prog = run_pwd(Some(&parent_dir)); let output = str::from_utf8(prog.finish_with_output().output); - let child_dir = Path::from_str(output.trim()); + let child_dir = Path::new(output.trim()); let parent_stat = parent_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap(); diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index a91d68366f3..58ff51fe102 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -121,7 +121,7 @@ mod test { fn test_errors_do_not_crash() { // Open /dev/null as a library to get an error, and make sure // that only causes an error, and not a crash. - let path = GenericPath::from_str("/dev/null"); + let path = GenericPath::new("/dev/null"); match DynamicLibrary::open(Some(&path)) { Err(_) => {} Ok(_) => fail2!("Successfully opened the empty library.") diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index ef09315a887..c7ac3e1da9e 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -81,7 +81,7 @@ pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) let file = get_single_str_from_tts(cx, sp, tts, "include!"); let p = parse::new_sub_parser_from_file( cx.parse_sess(), cx.cfg(), - &res_rel_file(cx, sp, &Path::from_str(file)), sp); + &res_rel_file(cx, sp, &Path::new(file)), sp); base::MRExpr(p.parse_expr()) } @@ -89,7 +89,7 @@ pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); - let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path::from_str(file))); + let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path::new(file))); match res { result::Ok(res) => { base::MRExpr(cx.expr_str(sp, res.to_managed())) @@ -103,7 +103,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); - match io::read_whole_file(&res_rel_file(cx, sp, &Path::from_str(file))) { + match io::read_whole_file(&res_rel_file(cx, sp, &Path::new(file))) { result::Ok(src) => { let u8_exprs: ~[@ast::Expr] = src.iter().map(|char| cx.expr_u8(sp, *char)).collect(); base::MRExpr(cx.expr_vec(sp, u8_exprs)) @@ -145,7 +145,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { fn res_rel_file(cx: @ExtCtxt, sp: codemap::Span, arg: &Path) -> Path { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute() { - let mut cu = Path::from_str(cx.codemap().span_to_filename(sp)); + let mut cu = Path::new(cx.codemap().span_to_filename(sp)); cu.pop(); cu.push_path(arg); cu diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ad565fd2ec4..32cd45c86cb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3992,20 +3992,20 @@ impl Parser { outer_attrs: &[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let mut prefix = Path::from_str(self.sess.cm.span_to_filename(*self.span)); + let mut prefix = Path::new(self.sess.cm.span_to_filename(*self.span)); prefix.pop(); let mod_path_stack = &*self.mod_path_stack; - let mod_path = Path::from_str(".").join_many_str(*mod_path_stack); + let mod_path = Path::new(".").join_many(*mod_path_stack); let dir_path = prefix.join_path(&mod_path); let file_path = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { - Some(d) => dir_path.join_str(d), + Some(d) => dir_path.join(d), None => { let mod_name = token::interner_get(id.name).to_owned(); let default_path_str = mod_name + ".rs"; let secondary_path_str = mod_name + "/mod.rs"; - let default_path = dir_path.join_str(default_path_str); - let secondary_path = dir_path.join_str(secondary_path_str); + let default_path = dir_path.join(default_path_str.as_slice()); + let secondary_path = dir_path.join(secondary_path_str.as_slice()); let default_exists = default_path.exists(); let secondary_exists = secondary_path.exists(); match (default_exists, secondary_exists) { diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 8a5cb016a73..6ce289620fb 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -73,8 +73,8 @@ fn read_line() { use std::rt::io::file::FileInfo; use std::rt::io::buffered::BufferedReader; - let path = Path::from_str(env!("CFG_SRC_DIR")) - .join_str("src/test/bench/shootout-k-nucleotide.data"); + let mut path = Path::new(env!("CFG_SRC_DIR")); + path.push("src/test/bench/shootout-k-nucleotide.data"); for _ in range(0, 3) { let mut reader = BufferedReader::new(path.open_reader(Open).unwrap()); diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index addb43c4995..77c3a0e3983 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -122,7 +122,7 @@ fn main() { }; let writer = if os::getenv("RUST_BENCH").is_some() { - io::file_writer(&Path::from_str("./shootout-fasta.data"), + io::file_writer(&Path::new("./shootout-fasta.data"), [io::Truncate, io::Create]).unwrap() } else { io::stdout() diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 58ec5d44071..c0464dcc676 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -164,8 +164,8 @@ fn main() { let rdr = if os::getenv("RUST_BENCH").is_some() { // FIXME: Using this compile-time env variable is a crummy way to // get to this massive data set, but include_bin! chokes on it (#2598) - let path = Path::from_str(env!("CFG_SRC_DIR")) - .join_str("src/test/bench/shootout-k-nucleotide.data"); + let mut path = Path::new(env!("CFG_SRC_DIR")); + path.push("src/test/bench/shootout-k-nucleotide.data"); ~path.open_reader(Open).unwrap() as ~Reader } else { ~stdio::stdin() as ~Reader diff --git a/src/test/run-pass/glob-std.rs b/src/test/run-pass/glob-std.rs index 170645f4404..c86a438344a 100644 --- a/src/test/run-pass/glob-std.rs +++ b/src/test/run-pass/glob-std.rs @@ -20,14 +20,14 @@ use std::{io, os, unstable}; pub fn main() { fn mk_file(path: &str, directory: bool) { if directory { - os::make_dir(&Path::from_str(path), 0xFFFF); + os::make_dir(&Path::new(path), 0xFFFF); } else { - io::mk_file_writer(&Path::from_str(path), [io::Create]); + io::mk_file_writer(&Path::new(path), [io::Create]); } } fn abs_path(path: &str) -> Path { - os::getcwd().join_path(&Path::from_str(path)) + os::getcwd().join_path(&Path::new(path)) } fn glob_vec(pattern: &str) -> ~[Path] { diff --git a/src/test/run-pass/issue-3424.rs b/src/test/run-pass/issue-3424.rs index 01d895d1bcf..f860426ffd2 100644 --- a/src/test/run-pass/issue-3424.rs +++ b/src/test/run-pass/issue-3424.rs @@ -23,7 +23,7 @@ fn tester() { let loader: rsrc_loader = |_path| {result::Ok(~"more blah")}; - let path = path::Path::from_str("blah"); + let path = path::Path::new("blah"); assert!(loader(&path).is_ok()); } diff --git a/src/test/run-pass/rename-directory.rs b/src/test/run-pass/rename-directory.rs index 608624670fc..76a1d32705b 100644 --- a/src/test/run-pass/rename-directory.rs +++ b/src/test/run-pass/rename-directory.rs @@ -25,9 +25,9 @@ fn rename_directory() { let tmpdir = TempDir::new("rename_directory").expect("rename_directory failed"); let tmpdir = tmpdir.path(); - let old_path = tmpdir.join_many_str(["foo", "bar", "baz"]); + let old_path = tmpdir.join_many(["foo", "bar", "baz"]); assert!(os::mkdir_recursive(&old_path, U_RWX)); - let test_file = &old_path.join_str("temp.txt"); + let test_file = &old_path.join("temp.txt"); /* Write the temp input file */ let ostream = do test_file.with_c_str |fromp| { @@ -46,11 +46,11 @@ fn rename_directory() { } assert_eq!(libc::fclose(ostream), (0u as libc::c_int)); - let new_path = tmpdir.join_many_str(["quux", "blat"]); + let new_path = tmpdir.join_many(["quux", "blat"]); assert!(os::mkdir_recursive(&new_path, U_RWX)); - assert!(os::rename_file(&old_path, &new_path.join_str("newdir"))); - assert!(os::path_is_dir(&new_path.join_str("newdir"))); - assert!(os::path_exists(&new_path.join_many_str(["newdir", "temp.txt"]))); + assert!(os::rename_file(&old_path, &new_path.join("newdir"))); + assert!(os::path_is_dir(&new_path.join("newdir"))); + assert!(os::path_exists(&new_path.join_many(["newdir", "temp.txt"]))); } } diff --git a/src/test/run-pass/stat.rs b/src/test/run-pass/stat.rs index 5cd62368aa2..aa0661d49a2 100644 --- a/src/test/run-pass/stat.rs +++ b/src/test/run-pass/stat.rs @@ -18,8 +18,8 @@ use std::io; use std::os; pub fn main() { - let dir = tempfile::TempDir::new_in(&Path::from_str("."), "").unwrap(); - let path = dir.path().join_str("file"); + let dir = tempfile::TempDir::new_in(&Path::new("."), "").unwrap(); + let path = dir.path().join("file"); { match io::file_writer(&path, [io::Create, io::Truncate]) { diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index 80e63396350..837194fcf9f 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -28,7 +28,7 @@ use std::cell::Cell; fn test_tempdir() { let path = { - let p = TempDir::new_in(&Path::from_str("."), "foobar").unwrap(); + let p = TempDir::new_in(&Path::new("."), "foobar").unwrap(); let p = p.path(); assert!(ends_with(p.as_vec(), bytes!("foobar"))); p.clone() @@ -84,7 +84,7 @@ fn test_rm_tempdir() { // Ideally these would be in std::os but then core would need // to depend on std fn recursive_mkdir_rel() { - let path = Path::from_str("frob"); + let path = Path::new("frob"); let cwd = os::getcwd(); debug2!("recursive_mkdir_rel: Making: {} in cwd {} [{:?}]", path.display(), cwd.display(), os::path_exists(&path)); @@ -95,21 +95,21 @@ fn recursive_mkdir_rel() { } fn recursive_mkdir_dot() { - let dot = Path::from_str("."); + let dot = Path::new("."); assert!(os::mkdir_recursive(&dot, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); - let dotdot = Path::from_str(".."); + let dotdot = Path::new(".."); assert!(os::mkdir_recursive(&dotdot, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); } fn recursive_mkdir_rel_2() { - let path = Path::from_str("./frob/baz"); + let path = Path::new("./frob/baz"); let cwd = os::getcwd(); debug2!("recursive_mkdir_rel_2: Making: {} in cwd {} [{:?}]", path.display(), cwd.display(), os::path_exists(&path)); assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); assert!(os::path_is_dir(&path)); assert!(os::path_is_dir(&path.dir_path())); - let path2 = Path::from_str("quux/blat"); + let path2 = Path::new("quux/blat"); debug2!("recursive_mkdir_rel_2: Making: {} in cwd {}", path2.display(), cwd.display()); assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); @@ -124,17 +124,17 @@ pub fn test_rmdir_recursive_ok() { let tmpdir = TempDir::new("test").expect("test_rmdir_recursive_ok: \ couldn't create temp dir"); let tmpdir = tmpdir.path(); - let root = tmpdir.join_str("foo"); + let root = tmpdir.join("foo"); debug2!("making {}", root.display()); assert!(os::make_dir(&root, rwx)); - assert!(os::make_dir(&root.join_str("foo"), rwx)); - assert!(os::make_dir(&root.join_str("foo").join_str("bar"), rwx)); - assert!(os::make_dir(&root.join_str("foo").join_str("bar").join_str("blat"), rwx)); + assert!(os::make_dir(&root.join("foo"), rwx)); + assert!(os::make_dir(&root.join("foo").join("bar"), rwx)); + assert!(os::make_dir(&root.join("foo").join("bar").join("blat"), rwx)); assert!(os::remove_dir_recursive(&root)); assert!(!os::path_exists(&root)); - assert!(!os::path_exists(&root.join_str("bar"))); - assert!(!os::path_exists(&root.join_str("bar").join_str("blat"))); + assert!(!os::path_exists(&root.join("bar"))); + assert!(!os::path_exists(&root.join("bar").join("blat"))); } fn in_tmpdir(f: &fn()) { -- cgit 1.4.1-3-g733a5 From bab7eb20dff32294c65fa28cece552481c40cf0b Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 7 Oct 2013 19:16:58 -0700 Subject: path2: Update based on more review feedback Standardize the is_sep() functions to be the same in both posix and windows, and re-export from path. Update extra::glob to use this. Remove the usage of either, as it's going away. Move the WindowsPath-specific methods out of WindowsPath and make them top-level functions of path::windows instead. This way you cannot accidentally write code that will fail to compile on non-windows architectures without typing ::windows anywhere. Remove GenericPath::from_c_str() and just impl BytesContainer for CString instead. Remove .join_path() and .push_path() and just implement BytesContainer for Path instead. Remove FilenameDisplay and add a boolean flag to Display instead. Remove .each_parent(). It only had one caller, so just inline its definition there. --- src/compiletest/runtest.rs | 6 +- src/libextra/glob.rs | 21 +-- src/librustc/back/rpath.rs | 4 +- src/librustc/metadata/filesearch.rs | 35 +++-- src/librustpkg/package_source.rs | 14 +- src/librustpkg/path_util.rs | 14 +- src/librustpkg/rustpkg.rs | 12 +- src/librustpkg/tests.rs | 4 +- src/librustpkg/util.rs | 2 +- src/librustpkg/version.rs | 2 +- src/libstd/os.rs | 10 +- src/libstd/path/mod.rs | 156 ++++++++--------------- src/libstd/path/posix.rs | 131 ++++++++----------- src/libstd/path/windows.rs | 247 +++++++++++++++++------------------- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/test/run-pass/glob-std.rs | 2 +- 17 files changed, 274 insertions(+), 390 deletions(-) (limited to 'src/libextra') diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 4956be3c959..b1d8d83f9d3 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -189,7 +189,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { let mut expected = match props.pp_exact { Some(ref file) => { - let filepath = testfile.dir_path().join_path(file); + let filepath = testfile.dir_path().join(file); io::read_whole_file_str(&filepath).unwrap() } None => { srcs[srcs.len() - 2u].clone() } @@ -657,7 +657,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path { // what we return here is not particularly important, as it // happens; rustc ignores everything except for the directory. let auxname = output_testname(auxfile); - aux_output_dir_name(config, testfile).join_path(&auxname) + aux_output_dir_name(config, testfile).join(&auxname) } fn make_exe_name(config: &config, testfile: &Path) -> Path { @@ -757,7 +757,7 @@ fn output_testname(testfile: &Path) -> Path { fn output_base_name(config: &config, testfile: &Path) -> Path { config.build_base - .join_path(&output_testname(testfile)) + .join(&output_testname(testfile)) .with_extension(config.stage_id.as_slice()) } diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index 1a6c8e08e3b..83456777c40 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -24,6 +24,7 @@ */ use std::{os, path}; +use std::path::is_sep; use sort; @@ -81,11 +82,7 @@ pub fn glob(pattern: &str) -> GlobIterator { */ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { #[cfg(windows)] - use is_sep = std::path::windows::is_sep2; - #[cfg(not(windows))] - fn is_sep(c: char) -> bool { c <= '\x7F' && ::std::path::posix::is_sep(&(c as u8)) } - #[cfg(windows)] - fn check_windows_verbatim(p: &Path) -> bool { p.is_verbatim() } + fn check_windows_verbatim(p: &Path) -> bool { path::windows::is_verbatim(p) } #[cfg(not(windows))] fn check_windows_verbatim(_: &Path) -> bool { false } @@ -98,7 +95,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { // since we can't very well find all UNC shares with a 1-letter server name. return GlobIterator { root: root, dir_patterns: ~[], options: options, todo: ~[] }; } - root.push_path(pat_root.get_ref()); + root.push(pat_root.get_ref()); } let root_len = pat_root.map_move_default(0u, |p| p.as_vec().len()); @@ -462,7 +459,7 @@ fn in_char_specifiers(specifiers: &[CharSpecifier], c: char, options: MatchOptio /// A helper function to determine if two chars are (possibly case-insensitively) equal. fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool { - if cfg!(windows) && path::windows::is_sep2(a) && path::windows::is_sep2(b) { + if cfg!(windows) && path::windows::is_sep(a) && path::windows::is_sep(b) { true } else if !case_sensitive && a.is_ascii() && b.is_ascii() { // FIXME: work with non-ascii chars properly (issue #1347) @@ -472,16 +469,6 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool { } } -/// A helper function to determine if a char is a path separator on the current platform. -fn is_sep(c: char) -> bool { - if cfg!(windows) { - path::windows::is_sep2(c) - } else { - c <= '\x7F' && path::posix::is_sep(&(c as u8)) - } -} - - /** * Configuration options to modify the behaviour of `Pattern::matches_with(..)` */ diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index b7ae9c1ecb5..0626ec0ece0 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -45,7 +45,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path { let r = filesearch::relative_target_lib_path(sess.opts.target_triple); - let mut p = sess.filesearch.sysroot().join_path(&r); + let mut p = sess.filesearch.sysroot().join(&r); p.push(os::dll_filename("rustrt")); p } @@ -148,7 +148,7 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> ~str { let tlib = filesearch::relative_target_lib_path(target_triple); let mut path = Path::new(install_prefix); - path.push_path(&tlib); + path.push(&tlib); let path = os::make_absolute(&path); // FIXME (#9639): This needs to handle non-utf8 paths path.as_str().expect("non-utf8 component in rpath").to_owned() diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 6335df47d73..2274f7d3c69 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -100,7 +100,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>, } fn get_target_lib_file_path(&self, file: &Path) -> Path { let mut p = self.get_target_lib_path(); - p.push_path(file); + p.push(file); p } } @@ -148,7 +148,7 @@ pub fn relative_target_lib_path(target_triple: &str) -> Path { fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> Path { - sysroot.join_path(&relative_target_lib_path(target_triple)) + sysroot.join(&relative_target_lib_path(target_triple)) } fn make_rustpkg_target_lib_path(dir: &Path, @@ -196,7 +196,7 @@ pub fn rust_path() -> ~[Path] { } None => ~[] }; - let cwd = os::getcwd(); + let mut cwd = os::getcwd(); // now add in default entries let cwd_dot_rust = cwd.join(".rust"); if !env_rust_path.contains(&cwd_dot_rust) { @@ -205,30 +205,27 @@ pub fn rust_path() -> ~[Path] { if !env_rust_path.contains(&cwd) { env_rust_path.push(cwd.clone()); } - do cwd.each_parent() |p| { - if !env_rust_path.contains(&p.join(".rust")) { - push_if_exists(&mut env_rust_path, p); + loop { + let f = cwd.pop(); + if f.is_none() || bytes!("..") == f.unwrap() { + break; } - true - }; + cwd.push(".rust"); + if !env_rust_path.contains(&cwd) && os::path_exists(&cwd) { + env_rust_path.push(cwd.clone()); + } + cwd.pop(); + } let h = os::homedir(); for h in h.iter() { - if !env_rust_path.contains(&h.join(".rust")) { - push_if_exists(&mut env_rust_path, h); + let p = h.join(".rust"); + if !env_rust_path.contains(&p) && os::path_exists(&p) { + env_rust_path.push(p); } } env_rust_path } - -/// Adds p/.rust into vec, only if it exists -fn push_if_exists(vec: &mut ~[Path], p: &Path) { - let maybe_dir = p.join(".rust"); - if os::path_exists(&maybe_dir) { - vec.push(maybe_dir); - } -} - // The name of the directory rustc expects libraries to be located. // On Unix should be "lib", on windows "bin" pub fn libdir() -> ~str { diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 5e242c5376a..874a30394d1 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -95,20 +95,20 @@ impl PkgSrc { // We search for sources under both src/ and build/ , because build/ is where // automatically-checked-out sources go. let mut result = source_workspace.join("src"); - result.push_path(&id.path.dir_path()); + result.push(&id.path.dir_path()); result.push(format!("{}-{}", id.short_name, id.version.to_str())); to_try.push(result); let mut result = source_workspace.join("src"); - result.push_path(&id.path); + result.push(&id.path); to_try.push(result); let mut result = build_dir.join("src"); - result.push_path(&id.path.dir_path()); + result.push(&id.path.dir_path()); result.push_str(format!("{}-{}", id.short_name, id.version.to_str())); to_try.push(result.clone()); output_names.push(result); let mut other_result = build_dir.join("src"); - other_result.push_path(&id.path); + other_result.push(&id.path); to_try.push(other_result.clone()); output_names.push(other_result); @@ -146,7 +146,7 @@ impl PkgSrc { source_workspace: source.clone(), build_in_destination: build_in_destination, destination_workspace: destination, - start_dir: start.join_path(&suffix), + start_dir: start.join(&suffix), id: id, libs: ~[], mains: ~[], @@ -371,7 +371,7 @@ impl PkgSrc { cfgs: &[~str], what: OutputType) { for crate in crates.iter() { - let path = self.start_dir.join_path(&crate.file); + let path = self.start_dir.join(&crate.file); debug2!("build_crates: compiling {}", path.display()); let cfgs = crate.cfgs + cfgs; @@ -416,7 +416,7 @@ impl PkgSrc { debug2!("In declare inputs, self = {}", self.to_str()); for cs in to_do.iter() { for c in cs.iter() { - let path = self.start_dir.join_path(&c.file); + let path = self.start_dir.join(&c.file); debug2!("Declaring input: {}", path.display()); // FIXME (#9639): This needs to handle non-utf8 paths prep.declare_input("file", path.as_str().unwrap(), diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 0f5f1470b6f..0fe3abdefa3 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -68,7 +68,7 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, let mut found = None; do os::walk_dir(&src_dir) |p| { if os::path_is_dir(p) { - if *p == src_dir.join_path(&pkgid.path) || { + if *p == src_dir.join(&pkgid.path) || { let pf = p.filename_str(); do pf.iter().any |&g| { match split_version_general(g, '-') { @@ -196,7 +196,7 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target, prefix = {}", short_name, where, workspace.display(), prefix); let dir_to_search = match where { - Build => target_build_dir(workspace).join_path(path), + Build => target_build_dir(workspace).join(path), Install => target_lib_dir(workspace) }; @@ -273,7 +273,7 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti // Return the filename that matches, which we now know exists // (if result_filename != None) let abs_path = do result_filename.map |result_filename| { - let absolute_path = dir_to_search.join_path(&result_filename); + let absolute_path = dir_to_search.join(&result_filename); debug2!("result_filename = {}", absolute_path.display()); absolute_path }; @@ -329,7 +329,7 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path, // Artifacts in the build directory live in a package-ID-specific subdirectory, // but installed ones don't. let result = match (where, what) { - (Build, _) => target_build_dir(workspace).join_path(&pkgid.path), + (Build, _) => target_build_dir(workspace).join(&pkgid.path), (Install, Lib) => target_lib_dir(workspace), (Install, _) => target_bin_dir(workspace) }; @@ -347,7 +347,7 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path { use conditions::bad_path::cond; let mut result = target_build_dir(workspace); - result.push_path(&pkgid.path); + result.push(&pkgid.path); debug2!("Creating build dir {} for package id {}", result.display(), pkgid.to_str()); if os::path_exists(&result) || os::mkdir_recursive(&result, U_RWX) { @@ -370,7 +370,7 @@ pub fn mk_output_path(what: OutputType, where: Target, // If we're installing, it just goes under ... Install => workspace, // and if we're just building, it goes in a package-specific subdir - Build => workspace.join_path(&pkg_id.path) + Build => workspace.join(&pkg_id.path) }; debug2!("[{:?}:{:?}] mk_output_path: short_name = {}, path = {}", what, where, if what == Lib { short_name_with_version.clone() } else { pkg_id.short_name.clone() }, @@ -388,7 +388,7 @@ pub fn mk_output_path(what: OutputType, where: Target, os::EXE_SUFFIX)) }; if !output_path.is_absolute() { - output_path = os::getcwd().join_path(&output_path); + output_path = os::getcwd().join(&output_path); } debug2!("mk_output_path: returning {}", output_path.display()); output_path diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index e6b93e06073..7b10bf2a551 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -416,15 +416,15 @@ impl CtxMethods for BuildContext { debug2!("build: workspace = {} (in Rust path? {:?} is git dir? {:?} \ pkgid = {} pkgsrc start_dir = {}", workspace.display(), - in_rust_path(&workspace), is_git_dir(&workspace.join_path(&pkgid.path)), + in_rust_path(&workspace), is_git_dir(&workspace.join(&pkgid.path)), pkgid.to_str(), pkg_src.start_dir.display()); // If workspace isn't in the RUST_PATH, and it's a git repo, // then clone it into the first entry in RUST_PATH, and repeat - if !in_rust_path(&workspace) && is_git_dir(&workspace.join_path(&pkgid.path)) { + if !in_rust_path(&workspace) && is_git_dir(&workspace.join(&pkgid.path)) { let mut out_dir = default_workspace().join("src"); - out_dir.push_path(&pkgid.path); - let git_result = source_control::safe_git_clone(&workspace.join_path(&pkgid.path), + out_dir.push(&pkgid.path); + let git_result = source_control::safe_git_clone(&workspace.join(&pkgid.path), &pkgid.version, &out_dir); match git_result { @@ -494,7 +494,7 @@ impl CtxMethods for BuildContext { // We expect that p is relative to the package source's start directory, // so check that assumption debug2!("JustOne: p = {}", p.display()); - assert!(os::path_exists(&pkg_src.start_dir.join_path(p))); + assert!(os::path_exists(&pkg_src.start_dir.join(p))); if is_lib(p) { PkgSrc::push_crate(&mut pkg_src.libs, 0, p); } else if is_main(p) { @@ -553,7 +553,7 @@ impl CtxMethods for BuildContext { debug2!("In declare inputs for {}", id.to_str()); for cs in to_do.iter() { for c in cs.iter() { - let path = pkg_src.start_dir.join_path(&c.file); + let path = pkg_src.start_dir.join(&c.file); debug2!("Recording input: {}", path.display()); // FIXME (#9639): This needs to handle non-utf8 paths inputs.push((~"file", path.as_str().unwrap().to_owned())); diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index cb40c3c0090..4e8bcbb1cec 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -156,7 +156,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st fn init_git_repo(p: &Path) -> TempDir { assert!(p.is_relative()); let tmp = TempDir::new("git_local").expect("couldn't create temp dir"); - let work_dir = tmp.path().join_path(p); + let work_dir = tmp.path().join(p); let work_dir_for_opts = work_dir.clone(); assert!(os::mkdir_recursive(&work_dir, U_RWX)); debug2!("Running: git init in {}", work_dir.display()); @@ -793,7 +793,7 @@ fn test_package_request_version() { == repo.join_many([".rust", "bin", "test_pkg_version"])); let mut dir = target_build_dir(&repo.join(".rust")); - dir.push_path(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3")); + dir.push(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3")); debug2!("dir = {}", dir.display()); assert!(os::path_is_dir(&dir)); assert!(os::path_exists(&dir.join("version-0.3-file.txt"))); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index c5e81e6dc4a..23d9af77c01 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -177,7 +177,7 @@ pub fn compile_input(context: &BuildContext, // not sure if we should support anything else let mut out_dir = target_build_dir(workspace); - out_dir.push_path(&pkg_id.path); + out_dir.push(&pkg_id.path); // Make the output directory if it doesn't exist already assert!(os::mkdir_recursive(&out_dir, U_RWX)); diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index 21abeeb03e3..218f410e4dc 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -98,7 +98,7 @@ pub fn parse_vers(vers: ~str) -> result::Result { pub fn try_getting_local_version(local_path: &Path) -> Option { let rustpath = rust_path(); for rp in rustpath.iter() { - let local_path = rp.join_path(local_path); + let local_path = rp.join(local_path); let git_dir = local_path.join(".git"); if !os::path_is_dir(&git_dir) { continue; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 449888b4e2a..be50f6d1a9f 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -78,7 +78,7 @@ pub fn getcwd() -> Path { fail2!() } - GenericPath::from_c_str(CString::new(buf as *c_char, false)) + Path::new(CString::new(buf as *c_char, false)) } } } @@ -608,7 +608,7 @@ pub fn tmpdir() -> Path { pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool { let r = list_dir(p); r.iter().advance(|q| { - let path = &p.join_path(q); + let path = &p.join(q); f(path) && (!path_is_dir(path) || walk_dir(path, |p| f(p))) }) } @@ -648,7 +648,7 @@ pub fn make_absolute(p: &Path) -> Path { p.clone() } else { let mut ret = getcwd(); - ret.push_path(p); + ret.push(p); ret } } @@ -730,7 +730,7 @@ pub fn list_dir(p: &Path) -> ~[Path] { let mut entry_ptr = readdir(dir_ptr); while (entry_ptr as uint != 0) { let cstr = CString::new(rust_list_dir_val(entry_ptr), false); - paths.push(GenericPath::from_c_str(cstr)); + paths.push(Path::new(cstr)); entry_ptr = readdir(dir_ptr); } closedir(dir_ptr); @@ -800,7 +800,7 @@ pub fn list_dir(p: &Path) -> ~[Path] { * This version prepends each entry with the directory. */ pub fn list_dir_path(p: &Path) -> ~[Path] { - list_dir(p).map(|f| p.join_path(f)) + list_dir(p).map(|f| p.join(f)) } /// Removes a directory at the specified path, after removing diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index ff370e9d7c1..278a4ab36ff 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -30,9 +30,7 @@ no restriction on paths beyond disallowing NUL). ## Usage Usage of this module is fairly straightforward. Unless writing platform-specific -code, `Path` should be used to refer to the platform-native path, and methods -used should be restricted to those defined in `GenericPath`, and those methods -that are declared identically on both `PosixPath` and `WindowsPath`. +code, `Path` should be used to refer to the platform-native path. Creation of a path is typically done with either `Path::new(some_str)` or `Path::new(some_vec)`. This path can be modified with `.push()` and @@ -69,7 +67,6 @@ debug2!("path exists: {}", b); use container::Container; use c_str::CString; use clone::Clone; -use either::{Left, Right}; use fmt; use iter::Iterator; use option::{Option, None, Some}; @@ -121,6 +118,19 @@ pub use StrComponentIter = self::windows::StrComponentIter; #[cfg(windows)] pub use RevStrComponentIter = self::windows::RevStrComponentIter; +/// Typedef for the platform-native separator char func +#[cfg(unix)] +pub use is_sep = self::posix::is_sep; +/// Typedef for the platform-native separator char func +#[cfg(windows)] +pub use is_sep = self::windows::is_sep; +/// Typedef for the platform-native separator byte func +#[cfg(unix)] +pub use is_sep_byte = self::posix::is_sep_byte; +/// Typedef for the platform-native separator byte func +#[cfg(windows)] +pub use is_sep_byte = self::windows::is_sep_byte; + pub mod posix; pub mod windows; @@ -162,19 +172,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe { } } - /// Creates a new Path from a CString. - /// The resulting Path will always be normalized. - /// - /// See individual Path impls for potential restrictions. - #[inline] - fn from_c_str(path: CString) -> Self { - // CStrings can't contain NULs - let v = path.as_bytes(); - // v is NUL-terminated. Strip it off - let v = v.slice_to(v.len()-1); - unsafe { GenericPathUnsafe::new_unchecked(v) } - } - /// Returns the path as a string, if possible. /// If the path is not representable in utf-8, this returns None. #[inline] @@ -195,15 +192,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// This will print the equivalent of `to_display_str()` when used with a {} format parameter. fn display<'a>(&'a self) -> Display<'a, Self> { - Display{ path: self } + Display{ path: self, filename: false } } /// Returns an object that implements `fmt::Default` for printing filenames /// /// This will print the equivalent of `to_filename_display_str()` when used with a {} /// format parameter. If there is no filename, nothing will be printed. - fn filename_display<'a>(&'a self) -> FilenameDisplay<'a, Self> { - FilenameDisplay{ path: self } + fn filename_display<'a>(&'a self) -> Display<'a, Self> { + Display{ path: self, filename: true } } /// Returns the directory component of `self`, as a byte vector (with no trailing separator). @@ -314,13 +311,17 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// Raises the `null_byte` condition if the filestem contains a NUL. fn set_filestem(&mut self, filestem: T) { // borrowck is being a pain here + enum Value { + Checked(T), + Unchecked(~[u8]) + } let val = { match self.filename() { - None => Left(filestem), + None => Checked(filestem), Some(name) => { let dot = '.' as u8; match name.rposition_elem(&dot) { - None | Some(0) => Left(filestem), + None | Some(0) => Checked(filestem), Some(idx) => { let mut v; if contains_nul(filestem.container_as_bytes()) { @@ -336,15 +337,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe { v.push_all(filestem); } v.push_all(name.slice_from(idx)); - Right(v) + Unchecked(v) } } } } }; match val { - Left(v) => self.set_filename(v), - Right(v) => unsafe { self.set_filename_unchecked(v) } + Checked(v) => self.set_filename(v), + Unchecked(v) => unsafe { self.set_filename_unchecked(v) } } } /// Replaces the extension with the given byte vector or string. @@ -545,12 +546,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe { unsafe { self.push_unchecked(path) } } } - /// Pushes a Path onto `self`. - /// If the argument represents an absolute path, it replaces `self`. - #[inline] - fn push_path(&mut self, path: &Self) { - self.push(path.as_vec()) - } /// Pushes multiple paths (as byte vectors or strings) onto `self`. /// See `push` for details. #[inline] @@ -590,14 +585,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe { p.push(path); p } - /// Returns a new Path constructed by joining `self` with the given path. - /// If the given path is absolute, the new Path will represent just that. - #[inline] - fn join_path(&self, path: &Self) -> Self { - let mut p = self.clone(); - p.push_path(path); - p - } /// Returns a new Path constructed by joining `self` with the given paths /// (as byte vectors or strings). /// See `join` for details. @@ -632,21 +619,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// paths refer to separate drives, an absolute path is returned. fn path_relative_from(&self, base: &Self) -> Option; - /// Executes a callback with the receiver and every parent - fn each_parent(&self, f: &fn(&Self) -> bool) -> bool { - let mut p = self.clone(); - loop { - if !f(&p) { - return false; - } - let f = p.pop(); - if f.is_none() || bytes!("..") == f.unwrap() { - break; - } - } - true - } - /// Returns whether the relative path `child` is a suffix of `self`. fn ends_with_path(&self, child: &Self) -> bool; } @@ -674,7 +646,7 @@ pub trait BytesContainer { fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { str::from_utf8_slice_opt(self.container_as_bytes()) } - /// Returns whether the concrete receiver is a string type + /// Returns whether .container_as_str() is guaranteed to not fail // FIXME (#8888): Remove unused arg once :: works #[inline] fn is_str(_: Option) -> bool { false } @@ -703,11 +675,8 @@ pub trait GenericPathUnsafe { /// Helper struct for printing paths with format!() pub struct Display<'self, P> { - priv path: &'self P -} -/// Helper struct for printing filenames with format!() -pub struct FilenameDisplay<'self, P> { - priv path: &'self P + priv path: &'self P, + priv filename: bool } impl<'self, P: GenericPath> fmt::Default for Display<'self, P> { @@ -724,7 +693,14 @@ impl<'self, P: GenericPath> ToStr for Display<'self, P> { /// If the path is not UTF-8, invalid sequences with be replaced with the /// unicode replacement char. This involves allocation. fn to_str(&self) -> ~str { - from_utf8_with_replacement(self.path.as_vec()) + if self.filename { + match self.path.filename() { + None => ~"", + Some(v) => from_utf8_with_replacement(v) + } + } else { + from_utf8_with_replacement(self.path.as_vec()) + } } } @@ -735,47 +711,9 @@ impl<'self, P: GenericPath> Display<'self, P> { /// unicode replacement char. This involves allocation. #[inline] pub fn with_str(&self, f: &fn(&str) -> T) -> T { - match self.path.as_str() { - Some(s) => f(s), - None => { - let s = self.to_str(); - f(s.as_slice()) - } - } - } -} - -impl<'self, P: GenericPath> fmt::Default for FilenameDisplay<'self, P> { - fn fmt(d: &FilenameDisplay

, f: &mut fmt::Formatter) { - do d.with_str |s| { - f.pad(s) - } - } -} - -impl<'self, P: GenericPath> ToStr for FilenameDisplay<'self, P> { - /// Returns the filename as a string. If there is no filename, ~"" will be - /// returned. - /// - /// If the filename is not UTF-8, invalid sequences will be replaced with - /// the unicode replacement char. This involves allocation. - fn to_str(&self) -> ~str { - match self.path.filename() { - None => ~"", - Some(v) => from_utf8_with_replacement(v) - } - } -} - -impl<'self, P: GenericPath> FilenameDisplay<'self, P> { - /// Provides the filename as a string to a closure. If there is no - /// filename, "" will be provided. - /// - /// If the filename is not UTF-8, invalid sequences will be replaced with - /// the unicode replacement char. This involves allocation. - #[inline] - pub fn with_str(&self, f: &fn(&str) -> T) -> T { - match self.path.filename_str() { + let opt = if self.filename { self.path.filename_str() } + else { self.path.as_str() }; + match opt { Some(s) => f(s), None => { let s = self.to_str(); @@ -865,6 +803,14 @@ impl BytesContainer for @[u8] { } } +impl BytesContainer for CString { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + let s = self.as_bytes(); + s.slice_to(s.len()-1) + } +} + #[inline(always)] fn contains_nul(v: &[u8]) -> bool { v.iter().any(|&x| x == 0) @@ -1121,13 +1067,13 @@ mod tests { use c_str::ToCStr; #[test] - fn test_from_c_str() { + fn test_cstring() { let input = "/foo/bar/baz"; - let path: PosixPath = GenericPath::from_c_str(input.to_c_str()); + let path: PosixPath = PosixPath::new(input.to_c_str()); assert_eq!(path.as_vec(), input.as_bytes()); let input = "\\foo\\bar\\baz"; - let path: WindowsPath = GenericPath::from_c_str(input.to_c_str()); + let path: WindowsPath = WindowsPath::new(input.to_c_str()); assert_eq!(path.as_str().unwrap(), input.as_slice()); } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 8acc1346bcc..fdc943fb882 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -48,12 +48,19 @@ pub struct Path { } /// The standard path separator character -pub static sep: u8 = '/' as u8; +pub static sep: char = '/'; +static sep_byte: u8 = sep as u8; /// Returns whether the given byte is a path separator #[inline] -pub fn is_sep(u: &u8) -> bool { - *u == sep +pub fn is_sep_byte(u: &u8) -> bool { + *u as char == sep +} + +/// Returns whether the given char is a path separator +#[inline] +pub fn is_sep(c: char) -> bool { + c == sep } impl Eq for Path { @@ -89,11 +96,29 @@ impl IterBytes for Path { } } +impl BytesContainer for Path { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_vec() + } + #[inline] + fn container_into_owned_bytes(self) -> ~[u8] { + self.into_vec() + } +} + +impl<'self> BytesContainer for &'self Path { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_vec() + } +} + impl GenericPathUnsafe for Path { unsafe fn new_unchecked(path: T) -> Path { let path = Path::normalize(path.container_as_bytes()); assert!(!path.is_empty()); - let idx = path.rposition_elem(&sep); + let idx = path.rposition_elem(&sep_byte); Path{ repr: path, sepidx: idx } } @@ -106,11 +131,11 @@ impl GenericPathUnsafe for Path { None => { let mut v = vec::with_capacity(dirname.len() + self.repr.len() + 1); v.push_all(dirname); - v.push(sep); + v.push(sep_byte); v.push_all(self.repr); self.repr = Path::normalize(v); } - Some(0) if self.repr.len() == 1 && self.repr[0] == sep => { + Some(0) if self.repr.len() == 1 && self.repr[0] == sep_byte => { self.repr = Path::normalize(dirname); } Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => { @@ -127,7 +152,7 @@ impl GenericPathUnsafe for Path { self.repr = Path::normalize(v); } } - self.sepidx = self.repr.rposition_elem(&sep); + self.sepidx = self.repr.rposition_elem(&sep_byte); } unsafe fn set_filename_unchecked(&mut self, filename: T) { @@ -136,7 +161,7 @@ impl GenericPathUnsafe for Path { None if bytes!("..") == self.repr => { let mut v = vec::with_capacity(3 + filename.len()); v.push_all(dot_dot_static); - v.push(sep); + v.push(sep_byte); v.push_all(filename); self.repr = Path::normalize(v); } @@ -146,7 +171,7 @@ impl GenericPathUnsafe for Path { Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => { let mut v = vec::with_capacity(self.repr.len() + 1 + filename.len()); v.push_all(self.repr); - v.push(sep); + v.push(sep_byte); v.push_all(filename); self.repr = Path::normalize(v); } @@ -157,22 +182,22 @@ impl GenericPathUnsafe for Path { self.repr = Path::normalize(v); } } - self.sepidx = self.repr.rposition_elem(&sep); + self.sepidx = self.repr.rposition_elem(&sep_byte); } unsafe fn push_unchecked(&mut self, path: T) { let path = path.container_as_bytes(); if !path.is_empty() { - if path[0] == sep { + if path[0] == sep_byte { self.repr = Path::normalize(path); } else { let mut v = vec::with_capacity(self.repr.len() + path.len() + 1); v.push_all(self.repr); - v.push(sep); + v.push(sep_byte); v.push_all(path); self.repr = Path::normalize(v); } - self.sepidx = self.repr.rposition_elem(&sep); + self.sepidx = self.repr.rposition_elem(&sep_byte); } } } @@ -228,7 +253,7 @@ impl GenericPath for Path { } else { self.repr.truncate(idx); } - self.sepidx = self.repr.rposition_elem(&sep); + self.sepidx = self.repr.rposition_elem(&sep_byte); Some(v) } } @@ -244,7 +269,7 @@ impl GenericPath for Path { #[inline] fn is_absolute(&self) -> bool { - self.repr[0] == sep + self.repr[0] == sep_byte } fn is_ancestor_of(&self, other: &Path) -> bool { @@ -305,7 +330,7 @@ impl GenericPath for Path { } } } - Some(Path::new(comps.connect_vec(&sep))) + Some(Path::new(comps.connect_vec(&sep_byte))) } } @@ -347,14 +372,14 @@ impl Path { fn normalize+CopyableVector>(v: V) -> ~[u8] { // borrowck is being very picky let val = { - let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == sep; + let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == sep_byte; let v_ = if is_abs { v.as_slice().slice_from(1) } else { v.as_slice() }; let comps = normalize_helper(v_, is_abs); match comps { None => None, Some(comps) => { if is_abs && comps.is_empty() { - Some(~[sep]) + Some(~[sep_byte]) } else { let n = if is_abs { comps.len() } else { comps.len() - 1} + comps.iter().map(|v| v.len()).sum(); @@ -367,7 +392,7 @@ impl Path { } } for comp in it { - v.push(sep); + v.push(sep_byte); v.push_all(comp); } Some(v) @@ -386,10 +411,10 @@ impl Path { /// /a/b/c and a/b/c yield the same set of components. /// A path of "/" yields no components. A path of "." yields one component. pub fn component_iter<'a>(&'a self) -> ComponentIter<'a> { - let v = if self.repr[0] == sep { + let v = if self.repr[0] == sep_byte { self.repr.slice_from(1) } else { self.repr.as_slice() }; - let mut ret = v.split_iter(is_sep); + let mut ret = v.split_iter(is_sep_byte); if v.is_empty() { // consume the empty "" component ret.next(); @@ -400,10 +425,10 @@ impl Path { /// Returns an iterator that yields each component of the path in reverse. /// See component_iter() for details. pub fn rev_component_iter<'a>(&'a self) -> RevComponentIter<'a> { - let v = if self.repr[0] == sep { + let v = if self.repr[0] == sep_byte { self.repr.slice_from(1) } else { self.repr.as_slice() }; - let mut ret = v.rsplit_iter(is_sep); + let mut ret = v.rsplit_iter(is_sep_byte); if v.is_empty() { // consume the empty "" component ret.next(); @@ -432,7 +457,7 @@ fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<~[&'a [u8]]> { let mut comps: ~[&'a [u8]] = ~[]; let mut n_up = 0u; let mut changed = false; - for comp in v.split_iter(is_sep) { + for comp in v.split_iter(is_sep_byte) { if comp.is_empty() { changed = true } else if comp == bytes!(".") { changed = true } else if comp == bytes!("..") { @@ -928,7 +953,7 @@ mod tests { { let mut p = Path::new($path); let push = Path::new($push); - p.push_path(&push); + p.push(&push); assert_eq!(p.as_str(), Some($exp)); } ) @@ -1049,7 +1074,7 @@ mod tests { { let path = Path::new($path); let join = Path::new($join); - let res = path.join_path(&join); + let res = path.join(&join); assert_eq!(res.as_str(), Some($exp)); } ) @@ -1598,58 +1623,4 @@ mod tests { // str_component_iter is a wrapper around component_iter, so no need to do // the full set of tests } - - #[test] - fn test_each_parent() { - assert!(Path::new("/foo/bar").each_parent(|_| true)); - assert!(!Path::new("/foo/bar").each_parent(|_| false)); - - macro_rules! t( - (s: $path:expr, $exp:expr) => ( - { - let path = Path::new($path); - let exp: &[&str] = $exp; - let mut comps = exp.iter().map(|&x|x); - do path.each_parent |p| { - let p = p.as_str(); - assert!(p.is_some()); - let e = comps.next(); - assert!(e.is_some()); - assert_eq!(p.unwrap(), e.unwrap()); - true - }; - assert!(comps.next().is_none()); - } - ); - (v: $path:expr, $exp:expr) => ( - { - let path = Path::new($path); - let exp: &[&[u8]] = $exp; - let mut comps = exp.iter().map(|&x|x); - do path.each_parent |p| { - let p = p.as_vec(); - let e = comps.next(); - assert!(e.is_some()); - assert_eq!(p, e.unwrap()); - true - }; - assert!(comps.next().is_none()); - } - ) - ) - - t!(s: "/foo/bar", ["/foo/bar", "/foo", "/"]); - t!(s: "/foo/bar/baz", ["/foo/bar/baz", "/foo/bar", "/foo", "/"]); - t!(s: "/foo", ["/foo", "/"]); - t!(s: "/", ["/"]); - t!(s: "foo/bar/baz", ["foo/bar/baz", "foo/bar", "foo", "."]); - t!(s: "foo/bar", ["foo/bar", "foo", "."]); - t!(s: "foo", ["foo", "."]); - t!(s: ".", ["."]); - t!(s: "..", [".."]); - t!(s: "../../foo", ["../../foo", "../.."]); - - t!(v: b!("foo/bar", 0x80), [b!("foo/bar", 0x80), b!("foo"), b!(".")]); - t!(v: b!(0xff, "/bar"), [b!(0xff, "/bar"), b!(0xff), b!(".")]); - } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 86c4bb6f8a3..5f8e1dc58fa 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -121,6 +121,44 @@ impl IterBytes for Path { } } +impl BytesContainer for Path { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_vec() + } + #[inline] + fn container_into_owned_bytes(self) -> ~[u8] { + self.into_vec() + } + #[inline] + fn container_as_str<'a>(&'a self) -> &'a str { + self.as_str().unwrap() + } + #[inline] + fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { + self.as_str() + } + #[inline] + fn is_str(_: Option) -> bool { true } +} + +impl<'self> BytesContainer for &'self Path { + #[inline] + fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + self.as_vec() + } + #[inline] + fn container_as_str<'a>(&'a self) -> &'a str { + self.as_str().unwrap() + } + #[inline] + fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { + self.as_str() + } + #[inline] + fn is_str(_: Option<&'self Path>) -> bool { true } +} + impl GenericPathUnsafe for Path { /// See `GenericPathUnsafe::from_vec_unchecked`. /// @@ -235,7 +273,7 @@ impl GenericPathUnsafe for Path { fn is_vol_abs(path: &str, prefix: Option) -> bool { // assume prefix is Some(DiskPrefix) let rest = path.slice_from(prefix_len(prefix)); - !rest.is_empty() && rest[0].is_ascii() && is_sep2(rest[0] as char) + !rest.is_empty() && rest[0].is_ascii() && is_sep(rest[0] as char) } fn shares_volume(me: &Path, path: &str) -> bool { // path is assumed to have a prefix of Some(DiskPrefix) @@ -246,8 +284,8 @@ impl GenericPathUnsafe for Path { } } fn is_sep_(prefix: Option, u: u8) -> bool { - u.is_ascii() && if prefix_is_verbatim(prefix) { is_sep(u as char) } - else { is_sep2(u as char) } + if prefix_is_verbatim(prefix) { is_sep_verbatim(u as char) } + else { is_sep(u as char) } } fn replace_path(me: &mut Path, path: &str, prefix: Option) { @@ -262,7 +300,7 @@ impl GenericPathUnsafe for Path { fn append_path(me: &mut Path, path: &str) { // appends a path that has no prefix // if me is verbatim, we need to pre-normalize the new path - let path_ = if me.is_verbatim() { Path::normalize__(path, None) } + let path_ = if is_verbatim(me) { Path::normalize__(path, None) } else { None }; let pathlen = path_.map_default(path.len(), |p| p.len()); let mut s = str::with_capacity(me.repr.len() + 1 + pathlen); @@ -291,7 +329,7 @@ impl GenericPathUnsafe for Path { } None if !path.is_empty() && is_sep_(self.prefix, path[0]) => { // volume-relative path - if self.prefix().is_some() { + if self.prefix.is_some() { // truncate self down to the prefix, then append let n = self.prefix_len(); self.repr.truncate(n); @@ -418,11 +456,6 @@ impl GenericPath for Path { self.filename_str().map_move(|s| unsafe { GenericPathUnsafe::new_unchecked(s) }) } - #[inline] - fn push_path(&mut self, path: &Path) { - self.push(path.as_str().unwrap()) - } - #[inline] fn pop(&mut self) -> Option<~[u8]> { self.pop_str().map_move(|s| s.into_bytes()) @@ -463,7 +496,7 @@ impl GenericPath for Path { } _ => self.repr.slice_to(self.prefix_len()) })) - } else if self.is_vol_relative() { + } else if is_vol_relative(self) { Some(Path::new(self.repr.slice_to(1))) } else { None @@ -493,14 +526,14 @@ impl GenericPath for Path { #[inline] fn is_relative(&self) -> bool { - self.prefix.is_none() && !self.is_vol_relative() + self.prefix.is_none() && !is_vol_relative(self) } fn is_ancestor_of(&self, other: &Path) -> bool { if !self.equiv_prefix(other) { false } else if self.is_absolute() != other.is_absolute() || - self.is_vol_relative() != other.is_vol_relative() { + is_vol_relative(self) != is_vol_relative(other) { false } else { let mut ita = self.str_component_iter().map(|x|x.unwrap()); @@ -544,8 +577,8 @@ impl GenericPath for Path { } else { None } - } else if self.is_vol_relative() != base.is_vol_relative() { - if self.is_vol_relative() { + } else if is_vol_relative(self) != is_vol_relative(base) { + if is_vol_relative(self) { Some(self.clone()) } else { None @@ -555,8 +588,8 @@ impl GenericPath for Path { let mut itb = base.str_component_iter().map(|x|x.unwrap()); let mut comps = ~[]; - let a_verb = self.is_verbatim(); - let b_verb = base.is_verbatim(); + let a_verb = is_verbatim(self); + let b_verb = is_verbatim(base); loop { match (ita.next(), itb.next()) { (None, None) => break, @@ -598,20 +631,6 @@ impl GenericPath for Path { } } - fn each_parent(&self, f: &fn(&Path) -> bool) -> bool { - let mut p = self.clone(); - loop { - if !f(&p) { - return false; - } - let f = p.pop(); - if f.is_none() || (!p.is_verbatim() && bytes!("..") == f.unwrap()) { - break; - } - } - true - } - fn ends_with_path(&self, child: &Path) -> bool { if !child.is_relative() { return false; } let mut selfit = self.str_component_iter().invert(); @@ -694,34 +713,6 @@ impl Path { self.rev_str_component_iter().map(convert) } - /// Returns whether the path is considered "volume-relative", which means a path - /// that looks like "\foo". Paths of this form are relative to the current volume, - /// but absolute within that volume. - #[inline] - pub fn is_vol_relative(&self) -> bool { - self.prefix.is_none() && self.repr[0] == sep as u8 - } - - /// Returns whether the path is considered "cwd-relative", which means a path - /// with a volume prefix that is not absolute. This look like "C:foo.txt". Paths - /// of this form are relative to the cwd on the given volume. - #[inline] - pub fn is_cwd_relative(&self) -> bool { - self.prefix == Some(DiskPrefix) && !self.is_absolute() - } - - /// Returns the PathPrefix for this Path - #[inline] - pub fn prefix(&self) -> Option { - self.prefix - } - - /// Returns whether the prefix is a verbatim prefix, i.e. \\?\ - #[inline] - pub fn is_verbatim(&self) -> bool { - prefix_is_verbatim(self.prefix) - } - fn equiv_prefix(&self, other: &Path) -> bool { match (self.prefix, other.prefix) { (Some(DiskPrefix), Some(VerbatimDiskPrefix)) => { @@ -866,8 +857,8 @@ impl Path { let s = if self.has_nonsemantic_trailing_slash() { self.repr.slice_to(self.repr.len()-1) } else { self.repr.as_slice() }; - let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep2 } - else { is_sep }); + let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } + else { is_sep_verbatim }); let prefixlen = self.prefix_len(); self.sepidx = idx.and_then(|x| if x < prefixlen { None } else { Some(x) }); } @@ -893,7 +884,7 @@ impl Path { } fn has_nonsemantic_trailing_slash(&self) -> bool { - self.is_verbatim() && self.repr.len() > self.prefix_len()+1 && + is_verbatim(self) && self.repr.len() > self.prefix_len()+1 && self.repr[self.repr.len()-1] == sep as u8 } @@ -905,23 +896,65 @@ impl Path { } } +/// Returns whether the path is considered "volume-relative", which means a path +/// that looks like "\foo". Paths of this form are relative to the current volume, +/// but absolute within that volume. +#[inline] +pub fn is_vol_relative(path: &Path) -> bool { + path.prefix.is_none() && is_sep_byte(&path.repr[0]) +} + +/// Returns whether the path is considered "cwd-relative", which means a path +/// with a volume prefix that is not absolute. This look like "C:foo.txt". Paths +/// of this form are relative to the cwd on the given volume. +#[inline] +pub fn is_cwd_relative(path: &Path) -> bool { + path.prefix == Some(DiskPrefix) && !path.is_absolute() +} + +/// Returns the PathPrefix for this Path +#[inline] +pub fn prefix(path: &Path) -> Option { + path.prefix +} + +/// Returns whether the Path's prefix is a verbatim prefix, i.e. \\?\ +#[inline] +pub fn is_verbatim(path: &Path) -> bool { + prefix_is_verbatim(path.prefix) +} + /// The standard path separator character pub static sep: char = '\\'; /// The alternative path separator character pub static sep2: char = '/'; -/// Returns whether the given byte is a path separator. -/// Only allows the primary separator '\'; use is_sep2 to allow '/'. +/// Returns whether the given char is a path separator. +/// Allows both the primary separator '\' and the alternative separator '/'. #[inline] pub fn is_sep(c: char) -> bool { + c == sep || c == sep2 +} + +/// Returns whether the given char is a path separator. +/// Only allows the primary separator '\'; use is_sep to allow '/'. +#[inline] +pub fn is_sep_verbatim(c: char) -> bool { c == sep } /// Returns whether the given byte is a path separator. /// Allows both the primary separator '\' and the alternative separator '/'. #[inline] -pub fn is_sep2(c: char) -> bool { - c == sep || c == sep2 +pub fn is_sep_byte(u: &u8) -> bool { + *u as char == sep || *u as char == sep2 +} + +/// Returns whether the given byte is a path separator. +/// Only allows the primary separator '\'; use is_sep_byte to allow '/'. +#[inline] +pub fn is_sep_byte_verbatim(u: &u8) -> bool { + *u as char == sep } /// Prefix types for Path @@ -953,7 +986,7 @@ pub fn parse_prefix<'a>(mut path: &'a str) -> Option { if path.starts_with("UNC\\") { // \\?\UNC\server\share path = path.slice_from(4); - let (idx_a, idx_b) = match parse_two_comps(path, is_sep) { + let (idx_a, idx_b) = match parse_two_comps(path, is_sep_verbatim) { Some(x) => x, None => (path.len(), 0) }; @@ -977,7 +1010,7 @@ pub fn parse_prefix<'a>(mut path: &'a str) -> Option { let idx = path.find('\\').unwrap_or(path.len()); return Some(DeviceNSPrefix(idx)); } - match parse_two_comps(path, is_sep2) { + match parse_two_comps(path, is_sep) { Some((idx_a, idx_b)) if idx_a > 0 && idx_b > 0 => { // \\server\share return Some(UNCPrefix(idx_a, idx_b)); @@ -1006,14 +1039,14 @@ pub fn parse_prefix<'a>(mut path: &'a str) -> Option { // None result means the string didn't need normalizing fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool,Option<~[&'a str]>) { - let f = if !prefix_is_verbatim(prefix) { is_sep2 } else { is_sep }; + let f = if !prefix_is_verbatim(prefix) { is_sep } else { is_sep_verbatim }; let is_abs = s.len() > prefix_len(prefix) && f(s.char_at(prefix_len(prefix))); let s_ = s.slice_from(prefix_len(prefix)); let s_ = if is_abs { s_.slice_from(1) } else { s_ }; if is_abs && s_.is_empty() { return (is_abs, match prefix { - Some(DiskPrefix) | None => (if is_sep(s.char_at(prefix_len(prefix))) { None } + Some(DiskPrefix) | None => (if is_sep_verbatim(s.char_at(prefix_len(prefix))) { None } else { Some(~[]) }), Some(_) => Some(~[]), // need to trim the trailing separator }); @@ -1036,7 +1069,7 @@ fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool,Option< } else { comps.push(comp) } } if !changed && !prefix_is_verbatim(prefix) { - changed = s.find(is_sep2).is_some(); + changed = s.find(is_sep).is_some(); } if changed { if comps.is_empty() && !is_abs && prefix.is_none() { @@ -1078,8 +1111,8 @@ fn prefix_len(p: Option) -> uint { } fn prefix_is_sep(p: Option, c: u8) -> bool { - c.is_ascii() && if !prefix_is_verbatim(p) { is_sep2(c as char) } - else { is_sep(c as char) } + c.is_ascii() && if !prefix_is_verbatim(p) { is_sep(c as char) } + else { is_sep_verbatim(c as char) } } // Stat support @@ -1636,9 +1669,9 @@ mod tests { // we do want to check one odd case though to ensure the prefix is re-parsed let mut p = Path::new("\\\\?\\C:"); - assert_eq!(p.prefix(), Some(VerbatimPrefix(2))); + assert_eq!(prefix(&p), Some(VerbatimPrefix(2))); p.push("foo"); - assert_eq!(p.prefix(), Some(VerbatimDiskPrefix)); + assert_eq!(prefix(&p), Some(VerbatimDiskPrefix)); assert_eq!(p.as_str(), Some("\\\\?\\C:\\foo")); // and another with verbatim non-normalized paths @@ -1654,7 +1687,7 @@ mod tests { { let mut p = Path::new($path); let push = Path::new($push); - p.push_path(&push); + p.push(&push); assert_eq!(p.as_str(), Some($exp)); } ) @@ -1837,7 +1870,7 @@ mod tests { { let path = Path::new($path); let join = Path::new($join); - let res = path.join_path(&join); + let res = path.join(&join); assert_eq!(res.as_str(), Some($exp)); } ) @@ -1849,7 +1882,7 @@ mod tests { t!(s: "a\\b", "\\c\\d", "\\c\\d"); t!(s: ".", "a\\b", "a\\b"); t!(s: "\\", "a\\b", "\\a\\b"); - // join_path is implemented using push_path, so there's no need for + // join is implemented using push, so there's no need for // the full set of prefix tests } @@ -2217,11 +2250,11 @@ mod tests { let b = path.is_absolute(); assert!(b == abs, "Path '{}'.is_absolute(): expected {:?}, found {:?}", path.as_str().unwrap(), abs, b); - let b = path.is_vol_relative(); - assert!(b == vol, "Path '{}'.is_vol_relative(): expected {:?}, found {:?}", + let b = is_vol_relative(&path); + assert!(b == vol, "is_vol_relative('{}'): expected {:?}, found {:?}", path.as_str().unwrap(), vol, b); - let b = path.is_cwd_relative(); - assert!(b == cwd, "Path '{}'.is_cwd_relative(): expected {:?}, found {:?}", + let b = is_cwd_relative(&path); + assert!(b == cwd, "is_cwd_relative('{}'): expected {:?}, found {:?}", path.as_str().unwrap(), cwd, b); let b = path.is_relative(); assert!(b == rel, "Path '{}'.is_relativf(): expected {:?}, found {:?}", @@ -2614,54 +2647,4 @@ mod tests { t!(s: ".", [b!(".")]); // since this is really a wrapper around str_component_iter, those tests suffice } - - #[test] - fn test_each_parent() { - assert!(Path::new("/foo/bar").each_parent(|_| true)); - assert!(!Path::new("/foo/bar").each_parent(|_| false)); - - macro_rules! t( - (s: $path:expr, $exp:expr) => ( - { - let path = Path::new($path); - let exp: &[&str] = $exp; - let mut comps = exp.iter().map(|&x|x); - do path.each_parent |p| { - let p = p.as_str(); - assert!(p.is_some()); - let e = comps.next(); - assert!(e.is_some()); - assert_eq!(p.unwrap(), e.unwrap()); - true - }; - assert!(comps.next().is_none()); - } - ) - ) - - t!(s: "\\foo\\bar", ["\\foo\\bar", "\\foo", "\\"]); - t!(s: "\\foo\\bar\\baz", ["\\foo\\bar\\baz", "\\foo\\bar", "\\foo", "\\"]); - t!(s: "\\foo", ["\\foo", "\\"]); - t!(s: "\\", ["\\"]); - t!(s: "foo\\bar\\baz", ["foo\\bar\\baz", "foo\\bar", "foo", "."]); - t!(s: "foo\\bar", ["foo\\bar", "foo", "."]); - t!(s: "foo", ["foo", "."]); - t!(s: ".", ["."]); - t!(s: "..", [".."]); - t!(s: "..\\..\\foo", ["..\\..\\foo", "..\\.."]); - t!(s: "C:\\a\\b", ["C:\\a\\b", "C:\\a", "C:\\"]); - t!(s: "C:\\", ["C:\\"]); - t!(s: "C:a\\b", ["C:a\\b", "C:a", "C:"]); - t!(s: "C:", ["C:"]); - t!(s: "C:..\\..\\a", ["C:..\\..\\a", "C:..\\.."]); - t!(s: "C:..", ["C:.."]); - t!(s: "\\\\a\\b\\c", ["\\\\a\\b\\c", "\\\\a\\b"]); - t!(s: "\\\\a\\b", ["\\\\a\\b"]); - t!(s: "\\\\?\\a\\b\\c", ["\\\\?\\a\\b\\c", "\\\\?\\a\\b", "\\\\?\\a"]); - t!(s: "\\\\?\\C:\\a\\b", ["\\\\?\\C:\\a\\b", "\\\\?\\C:\\a", "\\\\?\\C:\\"]); - t!(s: "\\\\?\\UNC\\a\\b\\c", ["\\\\?\\UNC\\a\\b\\c", "\\\\?\\UNC\\a\\b"]); - t!(s: "\\\\.\\a\\b\\c", ["\\\\.\\a\\b\\c", "\\\\.\\a\\b", "\\\\.\\a"]); - t!(s: "\\\\?\\a\\..\\b\\.\\c/d", ["\\\\?\\a\\..\\b\\.\\c/d", "\\\\?\\a\\..\\b\\.", - "\\\\?\\a\\..\\b", "\\\\?\\a\\..", "\\\\?\\a"]); - } } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index c7ac3e1da9e..1c13beb790d 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -147,7 +147,7 @@ fn res_rel_file(cx: @ExtCtxt, sp: codemap::Span, arg: &Path) -> Path { if !arg.is_absolute() { let mut cu = Path::new(cx.codemap().span_to_filename(sp)); cu.pop(); - cu.push_path(arg); + cu.push(arg); cu } else { arg.clone() diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3e1a008f6ca..c776e5bfd38 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3996,7 +3996,7 @@ impl Parser { prefix.pop(); let mod_path_stack = &*self.mod_path_stack; let mod_path = Path::new(".").join_many(*mod_path_stack); - let dir_path = prefix.join_path(&mod_path); + let dir_path = prefix.join(&mod_path); let file_path = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { Some(d) => dir_path.join(d), diff --git a/src/test/run-pass/glob-std.rs b/src/test/run-pass/glob-std.rs index c86a438344a..acb2dde99ad 100644 --- a/src/test/run-pass/glob-std.rs +++ b/src/test/run-pass/glob-std.rs @@ -27,7 +27,7 @@ pub fn main() { } fn abs_path(path: &str) -> Path { - os::getcwd().join_path(&Path::new(path)) + os::getcwd().join(&Path::new(path)) } fn glob_vec(pattern: &str) -> ~[Path] { -- cgit 1.4.1-3-g733a5 From 6eade9e9143e496167d66298e8bbac5d9dfa3e19 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 15 Oct 2013 23:32:14 -0700 Subject: path2: Update for latest master Also fix some issues that crept into earlier commits during the conflict resoution for the rebase. --- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 4 ++-- src/libextra/glob.rs | 6 +++--- src/librustpkg/package_source.rs | 21 ++++++++++++--------- src/librustpkg/path_util.rs | 4 ++-- src/librustpkg/rustpkg.rs | 14 +++++++------- src/librustpkg/source_control.rs | 4 +++- src/librustpkg/tests.rs | 37 ++++++++++++++++++++----------------- src/librustpkg/util.rs | 6 +++--- src/librustpkg/workspace.rs | 2 +- src/libstd/os.rs | 4 ++-- src/libstd/path/posix.rs | 4 ++-- src/libstd/path/windows.rs | 27 ++++++++++++++++++--------- 13 files changed, 76 insertions(+), 59 deletions(-) (limited to 'src/libextra') diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index efe681ce830..541aa082f51 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -164,7 +164,7 @@ fn parse_pp_exact(line: &str, testfile: &Path) -> Option { Some(s) => Some(Path::new(s)), None => { if parse_name_directive(line, "pp-exact") { - testfile.filename().map_move(|s| Path::new(s)) + testfile.filename().map(|s| Path::new(s)) } else { None } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 9c6edb8d566..627a80ace69 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -663,7 +663,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path { fn make_exe_name(config: &config, testfile: &Path) -> Path { let mut f = output_base_name(config, testfile); if !os::EXE_SUFFIX.is_empty() { - match f.filename().map_move(|s| s + os::EXE_SUFFIX.as_bytes()) { + match f.filename().map(|s| s + os::EXE_SUFFIX.as_bytes()) { Some(v) => f.set_filename(v), None => () } @@ -752,7 +752,7 @@ fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path { fn aux_output_dir_name(config: &config, testfile: &Path) -> Path { let mut f = output_base_name(config, testfile); - match f.filename().map_move(|s| s + bytes!(".libaux")) { + match f.filename().map(|s| s + bytes!(".libaux")) { Some(v) => f.set_filename(v), None => () } diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index 83456777c40..031545c1cd2 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -98,7 +98,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator { root.push(pat_root.get_ref()); } - let root_len = pat_root.map_move_default(0u, |p| p.as_vec().len()); + let root_len = pat_root.map_default(0u, |p| p.as_vec().len()); let dir_patterns = pattern.slice_from(root_len.min(&pattern.len())) .split_terminator_iter(is_sep).map(|s| Pattern::new(s)).to_owned_vec(); @@ -303,7 +303,7 @@ impl Pattern { */ pub fn matches_path(&self, path: &Path) -> bool { // FIXME (#9639): This needs to handle non-utf8 paths - do path.as_str().map_move_default(false) |s| { + do path.as_str().map_default(false) |s| { self.matches(s) } } @@ -321,7 +321,7 @@ impl Pattern { */ pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool { // FIXME (#9639): This needs to handle non-utf8 paths - do path.as_str().map_move_default(false) |s| { + do path.as_str().map_default(false) |s| { self.matches_with(s, options) } } diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 874a30394d1..fba6cba9116 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -104,7 +104,7 @@ impl PkgSrc { let mut result = build_dir.join("src"); result.push(&id.path.dir_path()); - result.push_str(format!("{}-{}", id.short_name, id.version.to_str())); + result.push(format!("{}-{}", id.short_name, id.version.to_str())); to_try.push(result.clone()); output_names.push(result); let mut other_result = build_dir.join("src"); @@ -174,17 +174,19 @@ impl PkgSrc { } match ok_d { Some(ref d) => { - if d.is_parent_of(&id.path) - || d.is_parent_of(&versionize(&id.path, &id.version)) { + if d.is_ancestor_of(&id.path) + || d.is_ancestor_of(&versionize(&id.path, &id.version)) { // Strip off the package ID source_workspace = d.clone(); - for _ in id.path.components().iter() { - source_workspace = source_workspace.pop(); + for _ in id.path.component_iter() { + source_workspace.pop(); } // Strip off the src/ part - source_workspace = source_workspace.pop(); + source_workspace.pop(); // Strip off the build/ part to get the workspace - destination_workspace = source_workspace.pop().pop(); + destination_workspace = source_workspace.clone(); + destination_workspace.pop(); + destination_workspace.pop(); } break; } @@ -244,9 +246,10 @@ impl PkgSrc { pub fn fetch_git(local: &Path, pkgid: &PkgId) -> Option { use conditions::git_checkout_failed::cond; + let cwd = os::getcwd(); debug2!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}", pkgid.to_str(), pkgid.path.display(), - os::getcwd().display(), + cwd.display(), os::path_exists(&pkgid.path)); match safe_git_clone(&pkgid.path, &pkgid.version, local) { @@ -400,7 +403,7 @@ impl PkgSrc { // into account. I'm not sure if the workcache really likes seeing the // output as "Some(\"path\")". But I don't know what to do about it. // FIXME (#9639): This needs to handle non-utf8 paths - let result = result.map(|p|p.as_str().unwrap()); + let result = result.as_ref().map(|p|p.as_str().unwrap()); debug2!("Result of compiling {} was {}", subpath.display(), result.to_str()); result.to_str() } diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 69c3f6e0f1c..f5b2251a2a6 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -462,7 +462,7 @@ pub fn versionize(p: &Path, v: &Version) -> Path { pub fn chmod_read_only(p: &Path) -> bool { #[fixed_stack_segment]; unsafe { - do p.to_str().with_c_str |src_buf| { + do p.with_c_str |src_buf| { libc::chmod(src_buf, S_IRUSR as libc::c_int) == 0 as libc::c_int } } @@ -472,7 +472,7 @@ pub fn chmod_read_only(p: &Path) -> bool { pub fn chmod_read_only(p: &Path) -> bool { #[fixed_stack_segment]; unsafe { - do p.to_str().with_c_str |src_buf| { + do p.with_c_str |src_buf| { libc::chmod(src_buf, S_IRUSR as libc::mode_t) == 0 as libc::c_int } diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index 7b10bf2a551..985dcd805ce 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -247,8 +247,9 @@ impl CtxMethods for BuildContext { dest_ws = determine_destination(os::getcwd(), self.context.use_rust_path_hack, workspace); - let mut pkg_src = PkgSrc::new(workspace.clone(), false, pkgid.clone()); - dest_ws = Some(self.build(&mut pkg_src, what)); + let mut pkg_src = PkgSrc::new(workspace.clone(), dest_ws.clone(), + false, pkgid.clone()); + self.build(&mut pkg_src, what); true }; // n.b. If this builds multiple packages, it only returns the workspace for @@ -430,7 +431,7 @@ impl CtxMethods for BuildContext { match git_result { CheckedOutSources => make_read_only(&out_dir), // FIXME (#9639): This needs to handle non-utf8 paths - _ => cond.raise((pkgid.path.as_str().unwrap(), out_dir.clone())) + _ => cond.raise((pkgid.path.as_str().unwrap().to_owned(), out_dir.clone())) }; let default_ws = default_workspace(); debug2!("Calling build recursively with {:?} and {:?}", default_ws.display(), @@ -562,7 +563,7 @@ impl CtxMethods for BuildContext { let result = self.install_no_build(pkg_src.build_workspace(), &pkg_src.destination_workspace, - &id).map(|s| Path::new(*s)); + &id).map(|s| Path::new(s.as_slice())); debug2!("install: id = {}, about to call discover_outputs, {:?}", id.to_str(), result.map(|p| p.display().to_str())); installed_files = installed_files + result; @@ -580,7 +581,7 @@ impl CtxMethods for BuildContext { use conditions::copy_failed::cond; debug2!("install_no_build: assuming {} comes from {} with target {}", - id.to_str(), build_workspace.to_str(), target_workspace.to_str()); + id.to_str(), build_workspace.display(), target_workspace.display()); // Now copy stuff into the install dirs let maybe_executable = built_executable_in_workspace(id, build_workspace); @@ -631,8 +632,7 @@ impl CtxMethods for BuildContext { let mut target_lib = sub_target_lib .clone().expect(format!("I built {} but apparently \ didn't install it!", lib.display())); - let target_lib = target_lib - .set_filename(lib.filename().expect("weird target lib")); + target_lib.set_filename(lib.filename().expect("weird target lib")); if !(os::mkdir_recursive(&target_lib.dir_path(), U_RWX) && os::copy_file(lib, &target_lib)) { cond.raise(((*lib).clone(), target_lib.clone())); diff --git a/src/librustpkg/source_control.rs b/src/librustpkg/source_control.rs index 2fc925a8a6a..3c879af34cf 100644 --- a/src/librustpkg/source_control.rs +++ b/src/librustpkg/source_control.rs @@ -107,7 +107,9 @@ pub fn make_read_only(target: &Path) { pub fn git_clone_url(source: &str, target: &Path, v: &Version) { use conditions::git_checkout_failed::cond; - let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]); + // FIXME (#9639): This needs to handle non-utf8 paths + let outp = run::process_output("git", [~"clone", source.to_owned(), + target.as_str().unwrap().to_owned()]); if outp.status != 0 { debug2!("{}", str::from_utf8_owned(outp.output.clone())); debug2!("{}", str::from_utf8_owned(outp.error)); diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 4e8bcbb1cec..d367399c0bf 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -88,7 +88,7 @@ fn writeFile(file_path: &Path, contents: &str) { fn mk_emptier_workspace(tag: &str) -> TempDir { let workspace = TempDir::new(tag).expect("couldn't create temp dir"); - let package_dir = workspace.path().push("src"); + let package_dir = workspace.path().join("src"); assert!(os::mkdir_recursive(&package_dir, U_RWX)); workspace } @@ -110,9 +110,10 @@ fn mk_workspace(workspace: &Path, short_name: &Path, version: &Version) -> Path fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) { let workspace_dir = mk_empty_workspace(short_name, version, "temp_workspace"); + // FIXME (#9639): This needs to handle non-utf8 paths let package_dir = workspace_dir.path().join_many([~"src", format!("{}-{}", - short_name.to_str(), + short_name.as_str().unwrap(), version.to_str())]); debug2!("Created {} and does it exist? {:?}", package_dir.display(), @@ -912,7 +913,8 @@ fn rust_path_test() { // FIXME (#9639): This needs to handle non-utf8 paths command_line_test_with_env([~"install", ~"foo"], &cwd, - Some(~[(~"RUST_PATH", dir_for_path.path().as_str().unwrap())])); + Some(~[(~"RUST_PATH", + dir_for_path.path().as_str().unwrap().to_owned())])); assert_executable_exists(dir_for_path.path(), "foo"); } @@ -1078,7 +1080,7 @@ fn do_rebuild_dep_dates_change() { command_line_test([~"build", ~"foo"], workspace); let bar_lib_name = lib_output_file_name(workspace, "bar"); let bar_date = datestamp(&bar_lib_name); - debug2!("Datestamp on {} is {:?}", bar_lib_name.to_str(), bar_date); + debug2!("Datestamp on {} is {:?}", bar_lib_name.display(), bar_date); touch_source_file(workspace, &dep_id); command_line_test([~"build", ~"foo"], workspace); let new_bar_date = datestamp(&bar_lib_name); @@ -1326,6 +1328,7 @@ fn rust_path_hack_test(hack_flag: bool) { let workspace = workspace.path(); let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = dest_workspace.path(); + let foo_path = workspace.join_many(["src", "foo-0.1"]); let rust_path = Some(~[(~"RUST_PATH", format!("{}:{}", dest_workspace.as_str().unwrap(), @@ -1568,7 +1571,7 @@ fn dash_S() { let workspace = workspace.path(); let test_sys = test_sysroot(); // FIXME (#9639): This needs to handle non-utf8 paths - command_line_test([test_sysroot().as_str().unwrap().to_owned(), + command_line_test([test_sys.as_str().unwrap().to_owned(), ~"build", ~"-S", ~"foo"], @@ -1809,7 +1812,7 @@ fn test_recursive_deps() { let c_id = PkgId::new("c"); let b_workspace = create_local_package_with_dep(&b_id, &c_id); let b_workspace = b_workspace.path(); - writeFile(&b_workspace.join_many(["src", "c-0.1", "lib.rs"])), + writeFile(&b_workspace.join_many(["src", "c-0.1", "lib.rs"]), "pub fn g() {}"); let a_workspace = create_local_package(&a_id); let a_workspace = a_workspace.path(); @@ -1879,7 +1882,7 @@ fn test_target_specific_install_dir() { ~"install", ~"foo"], workspace); - assert!(os::path_is_dir(&workspace.join_many(["lib", host_triple()]))); + assert!(os::path_is_dir(&workspace.join_many([~"lib", host_triple()]))); assert_lib_exists(workspace, &Path::new("foo"), NoVersion); assert!(os::list_dir(&workspace.join("lib")).len() == 1); assert!(os::path_is_dir(&workspace.join("bin"))); @@ -2051,7 +2054,7 @@ fn test_installed_read_only() { let repo = init_git_repo(&temp_pkg_id.path); let repo = repo.path(); debug2!("repo = {}", repo.display()); - let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test-pkg"]); + let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); debug2!("repo_subdir = {}", repo_subdir.display()); writeFile(&repo_subdir.join("main.rs"), @@ -2077,8 +2080,8 @@ fn test_installed_read_only() { assert!(is_rwx(&built_lib)); // Make sure sources are (a) under "build" and (b) read-only - let src1 = target_build_dir(&ws).join_many_str(["src", temp_pkg_id.to_str(), "main.rs"]); - let src2 = target_build_dir(&ws).join_many_str(["src", temp_pkg_id.to_str(), "lib.rs"]); + let src1 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"main.rs"]); + let src2 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"lib.rs"]); assert!(os::path_exists(&src1)); assert!(os::path_exists(&src2)); assert!(is_read_only(&src1)); @@ -2091,9 +2094,9 @@ fn test_installed_local_changes() { let repo = init_git_repo(&temp_pkg_id.path); let repo = repo.path(); debug2!("repo = {}", repo.display()); - let repo_subdir = repo.join_many_str(["mockgithub.com", "catamorphism", "test-pkg"]); + let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); debug2!("repo_subdir = {}", repo_subdir.display()); - assert!(os::mkdir_recursive(&repo.join_many_str([".rust", "src"]), U_RWX)); + assert!(os::mkdir_recursive(&repo.join_many([".rust", "src"]), U_RWX)); writeFile(&repo_subdir.join("main.rs"), "fn main() { let _x = (); }"); @@ -2109,10 +2112,10 @@ fn test_installed_local_changes() { // Now start a new workspace and clone it into it let hacking_workspace = mk_emptier_workspace("hacking_workspace"); let hacking_workspace = hacking_workspace.path(); - let target_dir = hacking_workspace.join_many_str(["src", - "mockgithub.com", - "catamorphism", - "test-pkg-0.1"]); + let target_dir = hacking_workspace.join_many(["src", + "mockgithub.com", + "catamorphism", + "test-pkg-0.1"]); debug2!("---- git clone {} {}", repo_subdir.display(), target_dir.display()); let c_res = safe_git_clone(&repo_subdir, &NoVersion, &target_dir); @@ -2159,7 +2162,7 @@ fn test_compile_error() { let foo_id = PkgId::new("foo"); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - let main_crate = foo_workspace.join_many_str(["src", "foo-0.1", "main.rs"]); + let main_crate = foo_workspace.join_many(["src", "foo-0.1", "main.rs"]); // Write something bogus writeFile(&main_crate, "pub fn main() { if 42 != ~\"the answer\" { fail!(); } }"); let result = command_line_test_partial([~"build", ~"foo"], foo_workspace); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 23d9af77c01..66c1aaea1ed 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -482,9 +482,9 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> { dep.as_str().unwrap(), digest_only_date(dep)); // Also, add an additional search path - debug2!("Installed {} into {}", dep.display(), - dep.dir_path().display()); - (self.save)(dep.dir_path()); + let dep_dir = dep.dir_path(); + debug2!("Installed {} into {}", dep.display(), dep_dir.display()); + (self.save)(dep_dir); } for &(ref what, ref dep) in inputs_disc.iter() { if *what == ~"file" { diff --git a/src/librustpkg/workspace.rs b/src/librustpkg/workspace.rs index a24767f1e68..13d70f15332 100644 --- a/src/librustpkg/workspace.rs +++ b/src/librustpkg/workspace.rs @@ -63,7 +63,7 @@ pub fn cwd_to_workspace() -> Option<(Path, PkgId)> { let srcpath = path.join("src"); if srcpath.is_ancestor_of(&cwd) { let rel = cwd.path_relative_from(&srcpath); - let rel_s = rel.and_then_ref(|p|p.as_str()); + let rel_s = rel.as_ref().and_then(|p|p.as_str()); if rel_s.is_some() { return Some((path, PkgId::new(rel_s.unwrap()))); } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 8701365d321..348bfd5c61a 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -509,11 +509,11 @@ pub fn self_exe_path() -> Option { use os::win32::fill_utf16_buf_and_decode; do fill_utf16_buf_and_decode() |buf, sz| { libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz) - }.map_move(|s| s.into_bytes()) + }.map(|s| s.into_bytes()) } } - load_self().and_then(|path| Path::new_opt(path).map(|p| { p.pop(); p })) + load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p })) } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 5eea65a5b91..271937dfcf2 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -791,7 +791,7 @@ mod tests { (s: $path:expr, $op:ident, $exp:expr, opt) => ( { let path = Path::new($path); - let left = path.$op().map(|&x| str::from_utf8_slice(x)); + let left = path.$op().map(|x| str::from_utf8_slice(x)); assert_eq!(left, $exp); } ); @@ -1313,7 +1313,7 @@ mod tests { let path = Path::new($path); let other = Path::new($other); let res = path.path_relative_from(&other); - assert_eq!(res.and_then_ref(|x| x.as_str()), $exp); + assert_eq!(res.as_ref().and_then(|x| x.as_str()), $exp); } ) ) diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 9576e62f439..0ee0d9c79d1 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -258,7 +258,7 @@ impl GenericPathUnsafe for Path { // if me is verbatim, we need to pre-normalize the new path let path_ = if is_verbatim(me) { Path::normalize__(path, None) } else { None }; - let pathlen = path_.map_default(path.len(), |p| p.len()); + let pathlen = path_.as_ref().map_default(path.len(), |p| p.len()); let mut s = str::with_capacity(me.repr.len() + 1 + pathlen); s.push_str(me.repr); let plen = me.prefix_len(); @@ -368,7 +368,7 @@ impl GenericPath for Path { #[inline] fn filename<'a>(&'a self) -> Option<&'a [u8]> { - self.filename_str().map_move(|x| x.as_bytes()) + self.filename_str().map(|x| x.as_bytes()) } /// See `GenericPath::filename_str` for info. @@ -388,13 +388,13 @@ impl GenericPath for Path { #[inline] fn filestem_str<'a>(&'a self) -> Option<&'a str> { // filestem() returns a byte vector that's guaranteed valid UTF-8 - self.filestem().map_move(cast::transmute) + self.filestem().map(cast::transmute) } #[inline] fn extension_str<'a>(&'a self) -> Option<&'a str> { // extension() returns a byte vector that's guaranteed valid UTF-8 - self.extension().map_move(cast::transmute) + self.extension().map(cast::transmute) } fn dir_path(&self) -> Path { @@ -728,16 +728,25 @@ impl Path { DiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; let mut s = s.slice_to(len).to_owned(); - s[0] = s[0].to_ascii().to_upper().to_byte(); + unsafe { + str::raw::as_owned_vec(&mut s)[0] = + s[0].to_ascii().to_upper().to_byte(); + } if is_abs { - s[2] = sep as u8; // normalize C:/ to C:\ + // normalize C:/ to C:\ + unsafe { + str::raw::as_owned_vec(&mut s)[2] = sep as u8; + } } Some(s) } VerbatimDiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; let mut s = s.slice_to(len).to_owned(); - s[4] = s[4].to_ascii().to_upper().to_byte(); + unsafe { + str::raw::as_owned_vec(&mut s)[4] = + s[4].to_ascii().to_upper().to_byte(); + } Some(s) } _ => { @@ -2204,10 +2213,10 @@ mod tests { let other = Path::new($other); let res = path.path_relative_from(&other); let exp = $exp; - assert!(res.and_then_ref(|x| x.as_str()) == exp, + assert!(res.as_ref().and_then(|x| x.as_str()) == exp, "`{}`.path_relative_from(`{}`): Expected {:?}, got {:?}", path.as_str().unwrap(), other.as_str().unwrap(), exp, - res.and_then_ref(|x| x.as_str())); + res.as_ref().and_then(|x| x.as_str())); } ) ) -- cgit 1.4.1-3-g733a5