Skip to content

Commit 6466aa7

Browse files
committed
reimplemted VFS.parsePath() calls after c.o.t.polyglot.FileSystems.DeniedIOFileSystem
1 parent 681c425 commit 6466aa7

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/utils/test/VirtualFileSystemTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ public void parseURIPath() throws Exception {
197197

198198
for (FileSystem fs : new FileSystem[]{rwHostIOVFS, rHostIOVFS, noHostIOVFS}) {
199199
checkException(UnsupportedOperationException.class, () -> fs.parsePath(URI.create("http://testvfs.org")), "only file uri is supported");
200-
checkException(UnsupportedOperationException.class, () -> fs.parsePath(URI.create("http:/" + VFS_MOUNT_POINT + File.separator + "dir1")), "only file uri is supported");
201-
checkException(UnsupportedOperationException.class, () -> fs.parsePath(URI.create("http://" + VFS_MOUNT_POINT + File.separator + "dir1")), "only file uri is supported");
202200
}
203201
}
204202

graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/VirtualFileSystem.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.nio.file.attribute.BasicFileAttributes;
6666
import java.nio.file.attribute.FileAttribute;
6767
import java.nio.file.attribute.FileTime;
68+
import java.nio.file.spi.FileSystemProvider;
6869
import java.util.ArrayList;
6970
import java.util.HashMap;
7071
import java.util.Iterator;
@@ -690,22 +691,31 @@ void extractResources(Path resourcesDirectory) throws IOException {
690691
}
691692
}
692693

694+
private FileSystemProvider defaultFileSystemProvider;
695+
696+
private FileSystemProvider getDefaultFileSystem() {
697+
if (defaultFileSystemProvider == null) {
698+
for (FileSystemProvider provider : FileSystemProvider.installedProviders()) {
699+
if ("file".equals(provider.getScheme())) {
700+
defaultFileSystemProvider = provider;
701+
}
702+
}
703+
}
704+
return defaultFileSystemProvider;
705+
}
706+
707+
Path getPath(URI uri) {
708+
return getDefaultFileSystem().getPath(uri);
709+
}
710+
693711
@Override
694712
@Deprecated
695713
public Path parsePath(URI uri) {
714+
// similar as in c.o.t.polyglot.FileSystems.DeniedIOFileSystem
696715
if (uri.getScheme().equals("file")) {
697-
// rather do not use Paths.get(URI) as it looks up the file system provider
698-
// by scheme and can use a non default file system provider
699-
Path ret = Paths.get(uri.getPath());
700-
if (!pathIsInVfs(ret)) {
701-
if (delegate != null) {
702-
ret = delegate.parsePath(uri);
703-
finest("VFS.parsePath delegated '%s' -> '%s'", uri, ret);
704-
return ret;
705-
}
706-
}
707-
finest("VFS.parsePath '%s' -> '%s'", uri, ret);
708-
return ret;
716+
Path path = getDefaultFileSystem().getPath(uri);
717+
finest("VFS.parsePath '%s' -> '%s'", uri, path);
718+
return path;
709719
} else {
710720
String msg = "Unsupported URI scheme '%s'";
711721
finer(msg, uri.getScheme());
@@ -716,16 +726,8 @@ public Path parsePath(URI uri) {
716726
@Override
717727
@Deprecated
718728
public Path parsePath(String path) {
719-
// It's safe to use the Paths.get(String)
720-
// as it always uses the default file system.
729+
// same as in c.o.t.polyglot.FileSystems.DeniedIOFileSystem
721730
Path p = Paths.get(path);
722-
if (!pathIsInVfs(p)) {
723-
if (delegate != null) {
724-
Path ret = delegate.parsePath(path);
725-
finest("VFS.parsePath delegated '%s' -> '%s'", path, ret);
726-
return ret;
727-
}
728-
}
729731
finer("VFS.parsePath '%s' -> '%s'", path, p);
730732
return p;
731733
}

0 commit comments

Comments
 (0)