zipfs and relative paths
Joel Uckelman
uckelman at nomic.net
Sun Nov 29 11:48:24 PST 2009
Thus spake Alan Bateman:
> Joel,
>
> Thanks for the patches. I'll review them in the next few days and push
> them to the nio/nio/jdk repository.
>
> -Alan.
Here's one more:
* getParent() returned null instead of "/" for single-element absolute paths
("/foo").
-------------- next part --------------
# HG changeset patch
# User Joel Uckelman <uckelman at nomic.net>
# Date 1259523988 -3600
# Node ID 073e75b34c3d2fdb8c49d0ce259e9cedf85f1cc9
# Parent 46fe5da2beaaee6f28f02dfcb673725b4df7c4b5
getParent() returned null instead of "/" for single-element absolute paths
("/foo").
diff --git a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
--- a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
+++ b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
@@ -269,14 +269,24 @@
@Override
public ZipFilePath getParent() {
- int count = getNameCount();
- if (count == 0 || count == 1) {
+ final int count = getNameCount();
+
+ // a root has no parent
+ if (count == 0) {
return null;
}
+
+ // a single-name path
+ if (count == 1) {
+ // has the root as its parent if absolute, and no parent otherwise
+ return isAbsolute() ?
+ new ZipFilePath(this.fileSystem, new byte[]{path[0]}) : null;
+ }
+
+ // all other paths have a parent
int position = offsets.get(count - 1);
String parent = subString(0, position - 1);
return new ZipFilePath(this.fileSystem, parent.getBytes());
-
}
public ZipFilePath getParentEntry() {
More information about the nio-dev
mailing list