提交 cb4ed117 编写于 作者: 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
上级 31a53f27
......@@ -157,7 +157,7 @@ public class ZipPath extends Path {
@Override
public ZipPath toRealPath(boolean resolveLinks) throws IOException {
ZipPath realPath = new ZipPath(zfs, getResolvedPath());
ZipPath realPath = new ZipPath(zfs, getResolvedPath()).toAbsolutePath();
realPath.checkAccess();
return realPath;
}
......@@ -472,8 +472,11 @@ public class ZipPath extends Path {
int n = offsets[i];
int len = (i == offsets.length - 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;
}
if (len == 2 && path[n] == '.' && path[n + 1] == '.') {
if (lastMOff >= 0) {
m = lastM[lastMOff--]; // retreat
......@@ -726,6 +729,8 @@ public class ZipPath extends Path {
@Override
public boolean isSameFile(Path other) throws IOException {
if (this.equals(other))
return true;
if (other == null ||
this.getFileSystem() != other.getFileSystem())
return false;
......
......@@ -193,6 +193,17 @@ public class PathOps {
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() {
if (!(exc instanceof InvalidPathException)) {
out.println("InvalidPathException not thrown as expected");
......@@ -344,7 +355,12 @@ public class PathOps {
.normalize("foo");
test("/foo/bar/gus/../..")
.normalize("/foo");
test("/./.")
.normalize("/");
test("/.")
.normalize("/");
test("/./abc")
.normalize("/abc");
// invalid
test("foo\u0000bar")
.invalid();
......@@ -365,6 +381,10 @@ public class PathOps {
.root("/")
.parent("/foo")
.name("bar");
// isSameFile
test("/fileDoesNotExist")
.isSameFile("/fileDoesNotExist");
}
static void npes() {
......
......@@ -28,6 +28,7 @@ import java.nio.file.*;
import java.nio.file.attribute.*;
import java.net.*;
import java.util.*;
import java.util.zip.*;
import static java.nio.file.StandardOpenOption.*;
import static java.nio.file.StandardCopyOption.*;
......@@ -42,7 +43,8 @@ public class ZipFSTester {
FileSystem fs = null;
try {
fs = newZipFileSystem(Paths.get(args[0]), new HashMap<String, Object>());
test(fs);
test0(fs);
test1(fs);
test2(fs); // more tests
} finally {
if (fs != null)
......@@ -50,11 +52,31 @@ public class ZipFSTester {
}
}
static void test(FileSystem fs)
static void test0(FileSystem fs)
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
Path tmpfsPath = getTempPath();
Map<String, Object> env = new HashMap<String, Object>();
......
......@@ -21,7 +21,7 @@
# questions.
#
# @test
# @bug 6990846
# @bug 6990846 7009092 7009085
# @summary Test ZipFileSystem demo
# @build Basic PathOps ZipFSTester
# @run shell basic.sh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册