src/windows/classes/sun/nio/fs/WindowsPath.java

Print this page

        

@@ -96,10 +96,30 @@
     }
 
     /**
      * Creates a Path from a given path that is known to be normalized.
      */
+    static WindowsPath createFromNormalizedPath(
+                                                WindowsPath parent, String fullPathName, String lastPathName, 
+                                                BasicFileAttributes attrs)
+    {
+            if (attrs == null) {
+                return new WindowsPath(parent.getFileSystem(),
+                                       parent.type,
+                                       parent.root,
+                                       fullPathName);
+            } else {
+                return new WindowsPathWithAttributes(parent.getFileSystem(),
+                                       parent.type,
+                                       parent.root,
+                                       fullPathName,lastPathName,parent,
+                                                     attrs);
+            }
+    }
+    /**
+     * Creates a Path from a given path that is known to be normalized.
+     */
     static WindowsPath createFromNormalizedPath(WindowsFileSystem fs,
                                                 String path,
                                                 BasicFileAttributes attrs)
     {
         try {

@@ -113,10 +133,11 @@
             } else {
                 return new WindowsPathWithAttributes(fs,
                                                      result.type(),
                                                      result.root(),
                                                      result.path(),
+                        null,null,
                                                      attrs);
             }
         } catch (InvalidPathException x) {
             throw new AssertionError(x.getMessage());
         }

@@ -129,42 +150,67 @@
                                                 String path)
     {
         return createFromNormalizedPath(fs, path, null);
     }
 
+
     /**
      * Special implementation with attached/cached attributes (used to quicken
      * file tree traveral)
      */
     private static class WindowsPathWithAttributes
         extends WindowsPath implements BasicFileAttributesHolder
     {
-        final WeakReference<BasicFileAttributes> ref;
+        final BasicFileAttributes ref;
+        private final String fileName;
+        private final WindowsPath parent;
 
         WindowsPathWithAttributes(WindowsFileSystem fs,
                                   WindowsPathType type,
                                   String root,
                                   String path,
+                                  String fileName,
+                                  WindowsPath parent,
                                   BasicFileAttributes attrs)
         {
             super(fs, type, root, path);
-            ref = new WeakReference<BasicFileAttributes>(attrs);
+            ref =attrs;
+            this.fileName = fileName;
+            this.parent = parent;
         }
 
         @Override
         public BasicFileAttributes get() {
-            return ref.get();
+            return ref;
         }
 
         @Override
         public void invalidate() {
-            ref.clear();
+//            ref.clear();
         }
 
+
         // no need to override equals/hashCode.
+
+        @Override
+        public Path getFileName() {
+            if (fileName != null) {
+                return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", fileName);        
     }
+            return super.getFileName();
+        }
 
+        @Override
+        public WindowsPath getParent() {
+            if (parent != null) {
+                return parent;
+            }
+            return super.getParent();
+        }
+        
+    }
+
     // use this message when throwing exceptions
     String getPathForExceptionMessage() {
         return path;
     }
 

@@ -315,16 +361,16 @@
         if (len == 0)
             return this;
         // represents root component only
         if (root.length() == len)
             return null;
-        int off = path.lastIndexOf('\\');
+        int off = path.lastIndexOf('\\', len);
         if (off < root.length())
             off = root.length();
         else
             off++;
-        return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off));
+        return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off, len));
     }
 
     @Override
     public WindowsPath getParent() {
         // represents root component only

@@ -835,10 +881,11 @@
         checkRead();
         String rp = WindowsLinkSupport.getRealPath(this, Util.followLinks(options));
         return createFromNormalizedPath(getFileSystem(), rp);
     }
 
+
     @Override
     public WatchKey register(WatchService watcher,
                              WatchEvent.Kind<?>[] events,
                              WatchEvent.Modifier... modifiers)
         throws IOException