path2: Update for latest master

Also fix some issues that crept into earlier commits during the conflict
resoution for the rebase.
This commit is contained in:
Kevin Ballard 2013-10-15 23:32:14 -07:00
parent 40b324f0de
commit 6eade9e914
13 changed files with 76 additions and 59 deletions

View File

@ -164,7 +164,7 @@ fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
Some(s) => Some(Path::new(s)), Some(s) => Some(Path::new(s)),
None => { None => {
if parse_name_directive(line, "pp-exact") { if parse_name_directive(line, "pp-exact") {
testfile.filename().map_move(|s| Path::new(s)) testfile.filename().map(|s| Path::new(s))
} else { } else {
None None
} }

View File

@ -663,7 +663,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
fn make_exe_name(config: &config, testfile: &Path) -> Path { fn make_exe_name(config: &config, testfile: &Path) -> Path {
let mut f = output_base_name(config, testfile); let mut f = output_base_name(config, testfile);
if !os::EXE_SUFFIX.is_empty() { 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), Some(v) => f.set_filename(v),
None => () 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 { fn aux_output_dir_name(config: &config, testfile: &Path) -> Path {
let mut f = output_base_name(config, testfile); 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), Some(v) => f.set_filename(v),
None => () None => ()
} }

View File

@ -98,7 +98,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
root.push(pat_root.get_ref()); 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())) let dir_patterns = pattern.slice_from(root_len.min(&pattern.len()))
.split_terminator_iter(is_sep).map(|s| Pattern::new(s)).to_owned_vec(); .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 { pub fn matches_path(&self, path: &Path) -> bool {
// FIXME (#9639): This needs to handle non-utf8 paths // 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) self.matches(s)
} }
} }
@ -321,7 +321,7 @@ impl Pattern {
*/ */
pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool { pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool {
// FIXME (#9639): This needs to handle non-utf8 paths // 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) self.matches_with(s, options)
} }
} }

View File

@ -104,7 +104,7 @@ impl PkgSrc {
let mut result = build_dir.join("src"); let mut result = build_dir.join("src");
result.push(&id.path.dir_path()); 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()); to_try.push(result.clone());
output_names.push(result); output_names.push(result);
let mut other_result = build_dir.join("src"); let mut other_result = build_dir.join("src");
@ -174,17 +174,19 @@ impl PkgSrc {
} }
match ok_d { match ok_d {
Some(ref d) => { Some(ref d) => {
if d.is_parent_of(&id.path) if d.is_ancestor_of(&id.path)
|| d.is_parent_of(&versionize(&id.path, &id.version)) { || d.is_ancestor_of(&versionize(&id.path, &id.version)) {
// Strip off the package ID // Strip off the package ID
source_workspace = d.clone(); source_workspace = d.clone();
for _ in id.path.components().iter() { for _ in id.path.component_iter() {
source_workspace = source_workspace.pop(); source_workspace.pop();
} }
// Strip off the src/ part // Strip off the src/ part
source_workspace = source_workspace.pop(); source_workspace.pop();
// Strip off the build/<target-triple> part to get the workspace // Strip off the build/<target-triple> part to get the workspace
destination_workspace = source_workspace.pop().pop(); destination_workspace = source_workspace.clone();
destination_workspace.pop();
destination_workspace.pop();
} }
break; break;
} }
@ -244,9 +246,10 @@ impl PkgSrc {
pub fn fetch_git(local: &Path, pkgid: &PkgId) -> Option<Path> { pub fn fetch_git(local: &Path, pkgid: &PkgId) -> Option<Path> {
use conditions::git_checkout_failed::cond; use conditions::git_checkout_failed::cond;
let cwd = os::getcwd();
debug2!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}", debug2!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}",
pkgid.to_str(), pkgid.path.display(), pkgid.to_str(), pkgid.path.display(),
os::getcwd().display(), cwd.display(),
os::path_exists(&pkgid.path)); os::path_exists(&pkgid.path));
match safe_git_clone(&pkgid.path, &pkgid.version, local) { 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 // 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. // output as "Some(\"path\")". But I don't know what to do about it.
// FIXME (#9639): This needs to handle non-utf8 paths // 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()); debug2!("Result of compiling {} was {}", subpath.display(), result.to_str());
result.to_str() result.to_str()
} }

View File

@ -462,7 +462,7 @@ pub fn versionize(p: &Path, v: &Version) -> Path {
pub fn chmod_read_only(p: &Path) -> bool { pub fn chmod_read_only(p: &Path) -> bool {
#[fixed_stack_segment]; #[fixed_stack_segment];
unsafe { 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 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 { pub fn chmod_read_only(p: &Path) -> bool {
#[fixed_stack_segment]; #[fixed_stack_segment];
unsafe { 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 libc::chmod(src_buf, S_IRUSR as libc::mode_t) == 0
as libc::c_int as libc::c_int
} }

View File

@ -247,8 +247,9 @@ impl CtxMethods for BuildContext {
dest_ws = determine_destination(os::getcwd(), dest_ws = determine_destination(os::getcwd(),
self.context.use_rust_path_hack, self.context.use_rust_path_hack,
workspace); workspace);
let mut pkg_src = PkgSrc::new(workspace.clone(), false, pkgid.clone()); let mut pkg_src = PkgSrc::new(workspace.clone(), dest_ws.clone(),
dest_ws = Some(self.build(&mut pkg_src, what)); false, pkgid.clone());
self.build(&mut pkg_src, what);
true true
}; };
// n.b. If this builds multiple packages, it only returns the workspace for // n.b. If this builds multiple packages, it only returns the workspace for
@ -430,7 +431,7 @@ impl CtxMethods for BuildContext {
match git_result { match git_result {
CheckedOutSources => make_read_only(&out_dir), CheckedOutSources => make_read_only(&out_dir),
// FIXME (#9639): This needs to handle non-utf8 paths // 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(); let default_ws = default_workspace();
debug2!("Calling build recursively with {:?} and {:?}", default_ws.display(), 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(), let result = self.install_no_build(pkg_src.build_workspace(),
&pkg_src.destination_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, {:?}", debug2!("install: id = {}, about to call discover_outputs, {:?}",
id.to_str(), result.map(|p| p.display().to_str())); id.to_str(), result.map(|p| p.display().to_str()));
installed_files = installed_files + result; installed_files = installed_files + result;
@ -580,7 +581,7 @@ impl CtxMethods for BuildContext {
use conditions::copy_failed::cond; use conditions::copy_failed::cond;
debug2!("install_no_build: assuming {} comes from {} with target {}", 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 // Now copy stuff into the install dirs
let maybe_executable = built_executable_in_workspace(id, build_workspace); 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 let mut target_lib = sub_target_lib
.clone().expect(format!("I built {} but apparently \ .clone().expect(format!("I built {} but apparently \
didn't install it!", lib.display())); didn't install it!", lib.display()));
let target_lib = target_lib target_lib.set_filename(lib.filename().expect("weird target lib"));
.set_filename(lib.filename().expect("weird target lib"));
if !(os::mkdir_recursive(&target_lib.dir_path(), U_RWX) && if !(os::mkdir_recursive(&target_lib.dir_path(), U_RWX) &&
os::copy_file(lib, &target_lib)) { os::copy_file(lib, &target_lib)) {
cond.raise(((*lib).clone(), target_lib.clone())); cond.raise(((*lib).clone(), target_lib.clone()));

View File

@ -107,7 +107,9 @@ pub fn make_read_only(target: &Path) {
pub fn git_clone_url(source: &str, target: &Path, v: &Version) { pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
use conditions::git_checkout_failed::cond; 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 { if outp.status != 0 {
debug2!("{}", str::from_utf8_owned(outp.output.clone())); debug2!("{}", str::from_utf8_owned(outp.output.clone()));
debug2!("{}", str::from_utf8_owned(outp.error)); debug2!("{}", str::from_utf8_owned(outp.error));

View File

@ -88,7 +88,7 @@ fn writeFile(file_path: &Path, contents: &str) {
fn mk_emptier_workspace(tag: &str) -> TempDir { fn mk_emptier_workspace(tag: &str) -> TempDir {
let workspace = TempDir::new(tag).expect("couldn't create temp dir"); 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)); assert!(os::mkdir_recursive(&package_dir, U_RWX));
workspace 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) { fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) {
let workspace_dir = mk_empty_workspace(short_name, version, "temp_workspace"); 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", let package_dir = workspace_dir.path().join_many([~"src",
format!("{}-{}", format!("{}-{}",
short_name.to_str(), short_name.as_str().unwrap(),
version.to_str())]); version.to_str())]);
debug2!("Created {} and does it exist? {:?}", package_dir.display(), 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 // FIXME (#9639): This needs to handle non-utf8 paths
command_line_test_with_env([~"install", ~"foo"], command_line_test_with_env([~"install", ~"foo"],
&cwd, &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"); assert_executable_exists(dir_for_path.path(), "foo");
} }
@ -1078,7 +1080,7 @@ fn do_rebuild_dep_dates_change() {
command_line_test([~"build", ~"foo"], workspace); command_line_test([~"build", ~"foo"], workspace);
let bar_lib_name = lib_output_file_name(workspace, "bar"); let bar_lib_name = lib_output_file_name(workspace, "bar");
let bar_date = datestamp(&bar_lib_name); 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); touch_source_file(workspace, &dep_id);
command_line_test([~"build", ~"foo"], workspace); command_line_test([~"build", ~"foo"], workspace);
let new_bar_date = datestamp(&bar_lib_name); 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 workspace = workspace.path();
let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path(); let dest_workspace = dest_workspace.path();
let foo_path = workspace.join_many(["src", "foo-0.1"]);
let rust_path = Some(~[(~"RUST_PATH", let rust_path = Some(~[(~"RUST_PATH",
format!("{}:{}", format!("{}:{}",
dest_workspace.as_str().unwrap(), dest_workspace.as_str().unwrap(),
@ -1568,7 +1571,7 @@ fn dash_S() {
let workspace = workspace.path(); let workspace = workspace.path();
let test_sys = test_sysroot(); let test_sys = test_sysroot();
// FIXME (#9639): This needs to handle non-utf8 paths // 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", ~"build",
~"-S", ~"-S",
~"foo"], ~"foo"],
@ -1809,7 +1812,7 @@ fn test_recursive_deps() {
let c_id = PkgId::new("c"); let c_id = PkgId::new("c");
let b_workspace = create_local_package_with_dep(&b_id, &c_id); let b_workspace = create_local_package_with_dep(&b_id, &c_id);
let b_workspace = b_workspace.path(); 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() {}"); "pub fn g() {}");
let a_workspace = create_local_package(&a_id); let a_workspace = create_local_package(&a_id);
let a_workspace = a_workspace.path(); let a_workspace = a_workspace.path();
@ -1879,7 +1882,7 @@ fn test_target_specific_install_dir() {
~"install", ~"install",
~"foo"], ~"foo"],
workspace); 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_lib_exists(workspace, &Path::new("foo"), NoVersion);
assert!(os::list_dir(&workspace.join("lib")).len() == 1); assert!(os::list_dir(&workspace.join("lib")).len() == 1);
assert!(os::path_is_dir(&workspace.join("bin"))); 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 = init_git_repo(&temp_pkg_id.path);
let repo = repo.path(); let repo = repo.path();
debug2!("repo = {}", repo.display()); 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()); debug2!("repo_subdir = {}", repo_subdir.display());
writeFile(&repo_subdir.join("main.rs"), writeFile(&repo_subdir.join("main.rs"),
@ -2077,8 +2080,8 @@ fn test_installed_read_only() {
assert!(is_rwx(&built_lib)); assert!(is_rwx(&built_lib));
// Make sure sources are (a) under "build" and (b) read-only // 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 src1 = target_build_dir(&ws).join_many([~"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 src2 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"lib.rs"]);
assert!(os::path_exists(&src1)); assert!(os::path_exists(&src1));
assert!(os::path_exists(&src2)); assert!(os::path_exists(&src2));
assert!(is_read_only(&src1)); 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 = init_git_repo(&temp_pkg_id.path);
let repo = repo.path(); let repo = repo.path();
debug2!("repo = {}", repo.display()); 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()); 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"), writeFile(&repo_subdir.join("main.rs"),
"fn main() { let _x = (); }"); "fn main() { let _x = (); }");
@ -2109,7 +2112,7 @@ fn test_installed_local_changes() {
// Now start a new workspace and clone it into it // Now start a new workspace and clone it into it
let hacking_workspace = mk_emptier_workspace("hacking_workspace"); let hacking_workspace = mk_emptier_workspace("hacking_workspace");
let hacking_workspace = hacking_workspace.path(); let hacking_workspace = hacking_workspace.path();
let target_dir = hacking_workspace.join_many_str(["src", let target_dir = hacking_workspace.join_many(["src",
"mockgithub.com", "mockgithub.com",
"catamorphism", "catamorphism",
"test-pkg-0.1"]); "test-pkg-0.1"]);
@ -2159,7 +2162,7 @@ fn test_compile_error() {
let foo_id = PkgId::new("foo"); let foo_id = PkgId::new("foo");
let foo_workspace = create_local_package(&foo_id); let foo_workspace = create_local_package(&foo_id);
let foo_workspace = foo_workspace.path(); 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 // Write something bogus
writeFile(&main_crate, "pub fn main() { if 42 != ~\"the answer\" { fail!(); } }"); writeFile(&main_crate, "pub fn main() { if 42 != ~\"the answer\" { fail!(); } }");
let result = command_line_test_partial([~"build", ~"foo"], foo_workspace); let result = command_line_test_partial([~"build", ~"foo"], foo_workspace);

View File

@ -482,9 +482,9 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> {
dep.as_str().unwrap(), dep.as_str().unwrap(),
digest_only_date(dep)); digest_only_date(dep));
// Also, add an additional search path // Also, add an additional search path
debug2!("Installed {} into {}", dep.display(), let dep_dir = dep.dir_path();
dep.dir_path().display()); debug2!("Installed {} into {}", dep.display(), dep_dir.display());
(self.save)(dep.dir_path()); (self.save)(dep_dir);
} }
for &(ref what, ref dep) in inputs_disc.iter() { for &(ref what, ref dep) in inputs_disc.iter() {
if *what == ~"file" { if *what == ~"file" {

View File

@ -63,7 +63,7 @@ pub fn cwd_to_workspace() -> Option<(Path, PkgId)> {
let srcpath = path.join("src"); let srcpath = path.join("src");
if srcpath.is_ancestor_of(&cwd) { if srcpath.is_ancestor_of(&cwd) {
let rel = cwd.path_relative_from(&srcpath); 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() { if rel_s.is_some() {
return Some((path, PkgId::new(rel_s.unwrap()))); return Some((path, PkgId::new(rel_s.unwrap())));
} }

View File

@ -509,11 +509,11 @@ pub fn self_exe_path() -> Option<Path> {
use os::win32::fill_utf16_buf_and_decode; use os::win32::fill_utf16_buf_and_decode;
do fill_utf16_buf_and_decode() |buf, sz| { do fill_utf16_buf_and_decode() |buf, sz| {
libc::GetModuleFileNameW(0u as libc::DWORD, 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 }))
} }

View File

@ -791,7 +791,7 @@ mod tests {
(s: $path:expr, $op:ident, $exp:expr, opt) => ( (s: $path:expr, $op:ident, $exp:expr, opt) => (
{ {
let path = Path::new($path); 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); assert_eq!(left, $exp);
} }
); );
@ -1313,7 +1313,7 @@ mod tests {
let path = Path::new($path); let path = Path::new($path);
let other = Path::new($other); let other = Path::new($other);
let res = path.path_relative_from(&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);
} }
) )
) )

View File

@ -258,7 +258,7 @@ impl GenericPathUnsafe for Path {
// if me is verbatim, we need to pre-normalize the new path // if me is verbatim, we need to pre-normalize the new path
let path_ = if is_verbatim(me) { Path::normalize__(path, None) } let path_ = if is_verbatim(me) { Path::normalize__(path, None) }
else { 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); let mut s = str::with_capacity(me.repr.len() + 1 + pathlen);
s.push_str(me.repr); s.push_str(me.repr);
let plen = me.prefix_len(); let plen = me.prefix_len();
@ -368,7 +368,7 @@ impl GenericPath for Path {
#[inline] #[inline]
fn filename<'a>(&'a self) -> Option<&'a [u8]> { 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. /// See `GenericPath::filename_str` for info.
@ -388,13 +388,13 @@ impl GenericPath for Path {
#[inline] #[inline]
fn filestem_str<'a>(&'a self) -> Option<&'a str> { fn filestem_str<'a>(&'a self) -> Option<&'a str> {
// filestem() returns a byte vector that's guaranteed valid UTF-8 // filestem() returns a byte vector that's guaranteed valid UTF-8
self.filestem().map_move(cast::transmute) self.filestem().map(cast::transmute)
} }
#[inline] #[inline]
fn extension_str<'a>(&'a self) -> Option<&'a str> { fn extension_str<'a>(&'a self) -> Option<&'a str> {
// extension() returns a byte vector that's guaranteed valid UTF-8 // 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 { fn dir_path(&self) -> Path {
@ -728,16 +728,25 @@ impl Path {
DiskPrefix => { DiskPrefix => {
let len = prefix_len(prefix) + is_abs as uint; let len = prefix_len(prefix) + is_abs as uint;
let mut s = s.slice_to(len).to_owned(); 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 { 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) Some(s)
} }
VerbatimDiskPrefix => { VerbatimDiskPrefix => {
let len = prefix_len(prefix) + is_abs as uint; let len = prefix_len(prefix) + is_abs as uint;
let mut s = s.slice_to(len).to_owned(); 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) Some(s)
} }
_ => { _ => {
@ -2204,10 +2213,10 @@ mod tests {
let other = Path::new($other); let other = Path::new($other);
let res = path.path_relative_from(&other); let res = path.path_relative_from(&other);
let exp = $exp; 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_relative_from(`{}`): Expected {:?}, got {:?}",
path.as_str().unwrap(), other.as_str().unwrap(), exp, 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()));
} }
) )
) )