8224908: Revert: 8216553: JrtFileSystemProvider getPath(URI) omits /modules element from file path
Reviewed-by: darcy, kbarrett
This commit is contained in:
parent
b71c30f1b8
commit
4e83c1c4dc
@ -190,10 +190,10 @@ public final class JrtFileSystemProvider extends FileSystemProvider {
|
|||||||
throw new IllegalArgumentException("Fragment component present");
|
throw new IllegalArgumentException("Fragment component present");
|
||||||
}
|
}
|
||||||
String path = uri.getPath();
|
String path = uri.getPath();
|
||||||
if (path == null || path.charAt(0) != '/' || path.contains("..")) {
|
if (path == null || path.charAt(0) != '/') {
|
||||||
throw new IllegalArgumentException("Invalid path component");
|
throw new IllegalArgumentException("Invalid path component");
|
||||||
}
|
}
|
||||||
return getTheFileSystem().getPath("/modules" + path);
|
return getTheFileSystem().getPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileSystem getTheFileSystem() {
|
private FileSystem getTheFileSystem() {
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
package jdk.internal.jrtfs;
|
package jdk.internal.jrtfs;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOError;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -171,16 +170,7 @@ final class JrtPath implements Path {
|
|||||||
@Override
|
@Override
|
||||||
public final URI toUri() {
|
public final URI toUri() {
|
||||||
try {
|
try {
|
||||||
String p = toAbsolutePath().path;
|
return new URI("jrt", toAbsolutePath().path, null);
|
||||||
if (!p.startsWith("/modules") || p.contains("..")) {
|
|
||||||
throw new IOError(new RuntimeException(p + " cannot be represented as URI"));
|
|
||||||
}
|
|
||||||
|
|
||||||
p = p.substring("/modules".length());
|
|
||||||
if (p.isEmpty()) {
|
|
||||||
p = "/";
|
|
||||||
}
|
|
||||||
return new URI("jrt", p, null);
|
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
throw new AssertionError(ex);
|
throw new AssertionError(ex);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOError;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
@ -272,60 +271,17 @@ public class Basic {
|
|||||||
Path top = fs.getPath("/");
|
Path top = fs.getPath("/");
|
||||||
try (Stream<Path> stream = Files.walk(top)) {
|
try (Stream<Path> stream = Files.walk(top)) {
|
||||||
stream.forEach(path -> {
|
stream.forEach(path -> {
|
||||||
String pathStr = path.toAbsolutePath().toString();
|
URI u = path.toUri();
|
||||||
URI u = null;
|
|
||||||
try {
|
|
||||||
u = path.toUri();
|
|
||||||
} catch (IOError e) {
|
|
||||||
assertFalse(pathStr.startsWith("/modules"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(u.getScheme().equalsIgnoreCase("jrt"));
|
assertTrue(u.getScheme().equalsIgnoreCase("jrt"));
|
||||||
assertFalse(u.isOpaque());
|
assertFalse(u.isOpaque());
|
||||||
assertTrue(u.getAuthority() == null);
|
assertTrue(u.getAuthority() == null);
|
||||||
|
assertEquals(u.getPath(), path.toAbsolutePath().toString());
|
||||||
pathStr = pathStr.substring("/modules".length());
|
|
||||||
if (pathStr.isEmpty()) {
|
|
||||||
pathStr = "/";
|
|
||||||
}
|
|
||||||
assertEquals(u.getPath(), pathStr);
|
|
||||||
Path p = Paths.get(u);
|
Path p = Paths.get(u);
|
||||||
assertEquals(p, path);
|
assertEquals(p, path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @bug 8216553: JrtFIleSystemProvider getPath(URI) omits /modules element from file path
|
|
||||||
@Test
|
|
||||||
public void testPathToURIConversion() throws Exception {
|
|
||||||
var uri = URI.create("jrt:/java.base/module-info.class");
|
|
||||||
var path = Path.of(uri);
|
|
||||||
assertTrue(Files.exists(path));
|
|
||||||
|
|
||||||
uri = URI.create("jrt:/java.base/../java.base/module-info.class");
|
|
||||||
boolean seenIAE = false;
|
|
||||||
try {
|
|
||||||
Path.of(uri);
|
|
||||||
} catch (IllegalArgumentException iaExp) {
|
|
||||||
seenIAE = true;
|
|
||||||
}
|
|
||||||
assertTrue(seenIAE);
|
|
||||||
|
|
||||||
// check round-trip
|
|
||||||
var jrtfs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
|
||||||
assertTrue(Files.exists(jrtfs.getPath(path.toString())));
|
|
||||||
|
|
||||||
path = jrtfs.getPath("/modules/../modules/java.base/");
|
|
||||||
boolean seenIOError = false;
|
|
||||||
try {
|
|
||||||
path.toUri();
|
|
||||||
} catch (IOError ioError) {
|
|
||||||
seenIOError = true;
|
|
||||||
}
|
|
||||||
assertTrue(seenIOError);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDirectoryNames() throws Exception {
|
public void testDirectoryNames() throws Exception {
|
||||||
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||||
|
@ -377,9 +377,9 @@ public class JarTask extends AbstractTask<JarTask> {
|
|||||||
private final Pattern jarEntry = Pattern.compile(".*!/(?:META-INF/sym/[^/]+/)?(.*)");
|
private final Pattern jarEntry = Pattern.compile(".*!/(?:META-INF/sym/[^/]+/)?(.*)");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A jrt: URL is of the form jrt:/<module>/<package>/<file>
|
* A jrt: URL is of the form jrt:/modules/<module>/<package>/<file>
|
||||||
*/
|
*/
|
||||||
private final Pattern jrtEntry = Pattern.compile("/([^/]+)/(.*)");
|
private final Pattern jrtEntry = Pattern.compile("/modules/([^/]+)/(.*)");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A file: URL is of the form file:/path/to/{modules,patches}/<module>/<package>/<file>
|
* A file: URL is of the form file:/path/to/{modules,patches}/<module>/<package>/<file>
|
||||||
|
Loading…
Reference in New Issue
Block a user