提交 b2fd1c85 编写于 作者: S sherman

7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs

7009092: (zipfs) ZipPath.isSameFile() should always return true if this Path and the given Path are equal.
7009085: (zipfs) ZipPath.normalize("/./.") returns null.
7009102: (zipfs) ZipPath.toRealPath() should always return absolute path.
Summary: zip filesystem provider update
Reviewed-by: alanb
上级 4c8403fd
...@@ -157,7 +157,7 @@ public class ZipPath extends Path { ...@@ -157,7 +157,7 @@ public class ZipPath extends Path {
@Override @Override
public ZipPath toRealPath(boolean resolveLinks) throws IOException { public ZipPath toRealPath(boolean resolveLinks) throws IOException {
ZipPath realPath = new ZipPath(zfs, getResolvedPath()); ZipPath realPath = new ZipPath(zfs, getResolvedPath()).toAbsolutePath();
realPath.checkAccess(); realPath.checkAccess();
return realPath; return realPath;
} }
...@@ -472,8 +472,11 @@ public class ZipPath extends Path { ...@@ -472,8 +472,11 @@ public class ZipPath extends Path {
int n = offsets[i]; int n = offsets[i];
int len = (i == offsets.length - 1)? int len = (i == offsets.length - 1)?
(path.length - n):(offsets[i + 1] - n - 1); (path.length - n):(offsets[i + 1] - n - 1);
if (len == 1 && path[n] == (byte)'.') if (len == 1 && path[n] == (byte)'.') {
if (m == 0 && path[0] == '/') // absolute path
to[m++] = '/';
continue; continue;
}
if (len == 2 && path[n] == '.' && path[n + 1] == '.') { if (len == 2 && path[n] == '.' && path[n + 1] == '.') {
if (lastMOff >= 0) { if (lastMOff >= 0) {
m = lastM[lastMOff--]; // retreat m = lastM[lastMOff--]; // retreat
...@@ -726,6 +729,8 @@ public class ZipPath extends Path { ...@@ -726,6 +729,8 @@ public class ZipPath extends Path {
@Override @Override
public boolean isSameFile(Path other) throws IOException { public boolean isSameFile(Path other) throws IOException {
if (this.equals(other))
return true;
if (other == null || if (other == null ||
this.getFileSystem() != other.getFileSystem()) this.getFileSystem() != other.getFileSystem())
return false; return false;
......
...@@ -193,6 +193,17 @@ public class PathOps { ...@@ -193,6 +193,17 @@ public class PathOps {
return this; return this;
} }
PathOps isSameFile(String target) {
try {
out.println("check two paths are same");
checkPath();
check(path.isSameFile(test(target).path()), true);
} catch (IOException ioe) {
fail();
}
return this;
}
PathOps invalid() { PathOps invalid() {
if (!(exc instanceof InvalidPathException)) { if (!(exc instanceof InvalidPathException)) {
out.println("InvalidPathException not thrown as expected"); out.println("InvalidPathException not thrown as expected");
...@@ -344,7 +355,12 @@ public class PathOps { ...@@ -344,7 +355,12 @@ public class PathOps {
.normalize("foo"); .normalize("foo");
test("/foo/bar/gus/../..") test("/foo/bar/gus/../..")
.normalize("/foo"); .normalize("/foo");
test("/./.")
.normalize("/");
test("/.")
.normalize("/");
test("/./abc")
.normalize("/abc");
// invalid // invalid
test("foo\u0000bar") test("foo\u0000bar")
.invalid(); .invalid();
...@@ -365,6 +381,10 @@ public class PathOps { ...@@ -365,6 +381,10 @@ public class PathOps {
.root("/") .root("/")
.parent("/foo") .parent("/foo")
.name("bar"); .name("bar");
// isSameFile
test("/fileDoesNotExist")
.isSameFile("/fileDoesNotExist");
} }
static void npes() { static void npes() {
......
...@@ -28,6 +28,7 @@ import java.nio.file.*; ...@@ -28,6 +28,7 @@ import java.nio.file.*;
import java.nio.file.attribute.*; import java.nio.file.attribute.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.util.zip.*;
import static java.nio.file.StandardOpenOption.*; import static java.nio.file.StandardOpenOption.*;
import static java.nio.file.StandardCopyOption.*; import static java.nio.file.StandardCopyOption.*;
...@@ -42,7 +43,8 @@ public class ZipFSTester { ...@@ -42,7 +43,8 @@ public class ZipFSTester {
FileSystem fs = null; FileSystem fs = null;
try { try {
fs = newZipFileSystem(Paths.get(args[0]), new HashMap<String, Object>()); fs = newZipFileSystem(Paths.get(args[0]), new HashMap<String, Object>());
test(fs); test0(fs);
test1(fs);
test2(fs); // more tests test2(fs); // more tests
} finally { } finally {
if (fs != null) if (fs != null)
...@@ -50,11 +52,31 @@ public class ZipFSTester { ...@@ -50,11 +52,31 @@ public class ZipFSTester {
} }
} }
static void test(FileSystem fs) static void test0(FileSystem fs)
throws Exception throws Exception
{ {
Random rdm = new Random(); List<String> list = new LinkedList<>();
try (ZipFile zf = new ZipFile(fs.toString())) {
Enumeration<? extends ZipEntry> zes = zf.entries();
while (zes.hasMoreElements()) {
list.add(zes.nextElement().getName());
}
for (String pname : list) {
Path path = fs.getPath(pname);
if (!path.exists())
throw new RuntimeException("path existence check failed!");
while ((path = path.getParent()) != null) {
if (!path.exists())
throw new RuntimeException("parent existence check failed!");
}
}
}
}
static void test1(FileSystem fs)
throws Exception
{
Random rdm = new Random();
// clone a fs and test on it // clone a fs and test on it
Path tmpfsPath = getTempPath(); Path tmpfsPath = getTempPath();
Map<String, Object> env = new HashMap<String, Object>(); Map<String, Object> env = new HashMap<String, Object>();
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# questions. # questions.
# #
# @test # @test
# @bug 6990846 # @bug 6990846 7009092 7009085
# @summary Test ZipFileSystem demo # @summary Test ZipFileSystem demo
# @build Basic PathOps ZipFSTester # @build Basic PathOps ZipFSTester
# @run shell basic.sh # @run shell basic.sh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册