]> git.lizzy.rs Git - rust.git/commitdiff
Make WindowsPath::new("C:foo").root_path() return Some("C:")
authorKevin Ballard <kevin@sb.org>
Sat, 18 Jan 2014 07:07:53 +0000 (23:07 -0800)
committerKevin Ballard <kevin@sb.org>
Sat, 18 Jan 2014 07:07:53 +0000 (23:07 -0800)
src/libstd/path/mod.rs
src/libstd/path/windows.rs

index 354cc10f022a67adddb4adcebf0c9ce4577b8482..dd245ec4f1a09b3cc06b08e2837611489fa4a97c 100644 (file)
@@ -386,7 +386,7 @@ fn dir_path(&self) -> Self {
 
     /// Returns a Path that represents the filesystem root that `self` is rooted in.
     ///
-    /// If `self` is not absolute, or vol-relative in the case of Windows, this returns None.
+    /// If `self` is not absolute, or vol/cwd-relative in the case of Windows, this returns None.
     fn root_path(&self) -> Option<Self>;
 
     /// Pushes a path (as a byte vector or string) onto `self`.
index a42fdabef88927e308b79c2f59852de4e20e506c..2d9d787d72de57a80d1c68737605754ac0635937 100644 (file)
@@ -432,9 +432,12 @@ fn pop(&mut self) -> bool {
     }
 
     fn root_path(&self) -> Option<Path> {
-        if self.is_absolute() {
+        if self.prefix.is_some() {
             Some(Path::new(match self.prefix {
-                Some(VerbatimDiskPrefix)|Some(DiskPrefix) => {
+                Some(DiskPrefix) if self.is_absolute() => {
+                    self.repr.slice_to(self.prefix_len()+1)
+                }
+                Some(VerbatimDiskPrefix) => {
                     self.repr.slice_to(self.prefix_len()+1)
                 }
                 _ => self.repr.slice_to(self.prefix_len())
@@ -1683,7 +1686,7 @@ macro_rules! t(
     fn test_root_path() {
         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("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")));