Skip to content

Commit 70589ab

Browse files
committed
create VFS entries only up to the mount point
1 parent 8e72702 commit 70589ab

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,19 @@ public void defaultValues() {
9999
@Test
100100
public void mountPoints() {
101101
VirtualFileSystem fs = VirtualFileSystem.newBuilder().//
102-
unixMountPoint(VFS_MOUNT_POINT).//
102+
unixMountPoint(VFS_UNIX_MOUNT_POINT).//
103103
windowsMountPoint(VFS_WIN_MOUNT_POINT).build();
104104

105105
assertEquals(VFS_MOUNT_POINT, fs.getMountPoint());
106+
107+
String multiPathUnixMountPoint = "/test/mount/point";
108+
String multiPathWinMountPoint = "X:\\test\\win\\mount\\point";
109+
VirtualFileSystem vfs = VirtualFileSystem.newBuilder().//
110+
unixMountPoint(multiPathUnixMountPoint).//
111+
windowsMountPoint(multiPathWinMountPoint).//
112+
resourceLoadingClass(VirtualFileSystemTest.class).build();
113+
Context ctx = addTestOptions(GraalPyResources.contextBuilder(vfs)).build();
114+
ctx.eval(PYTHON, "from os import listdir; listdir('" + (IS_WINDOWS ? multiPathWinMountPoint.replace("\\", "\\\\") : multiPathUnixMountPoint) + "')");
106115
}
107116

108117
private static void checkExtractedFile(Path extractedFile, String[] expectedContens) throws IOException {
@@ -391,7 +400,6 @@ private void eval(String s) {
391400

392401
private void eval(String s, Function<VirtualFileSystem.Builder, VirtualFileSystem.Builder> builderFunction) {
393402
String src = patchMountPoint(s);
394-
395403
getContext(builderFunction).eval(PYTHON, src);
396404
}
397405

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,7 @@ public synchronized String format(LogRecord lr) {
101101
/*
102102
* Root of the virtual filesystem in the resources.
103103
*/
104-
private static final String VFS_ROOT;
105-
static {
106-
String root = System.getProperty("org.graalvm.python.vfs.root");
107-
if (root != null && !root.trim().isEmpty()) {
108-
VFS_ROOT = root;
109-
info("VFS.VFS_ROOT override to'%s'", VFS_ROOT);
110-
} else {
111-
VFS_ROOT = "/org.graalvm.python.vfs";
112-
}
113-
}
104+
private static final String VFS_ROOT = "/org.graalvm.python.vfs";
114105

115106
static final String VFS_HOME = "home";
116107
static final String VFS_VENV = "venv";
@@ -378,9 +369,9 @@ private void initEntries() throws IOException {
378369
}
379370

380371
String platformPath = resourcePathToPlatformPath(line);
381-
int i = 0;
372+
int i = mountPoint.toString().length();
382373
DirEntry parent = null;
383-
while ((i = platformPath.indexOf(PLATFORM_SEPARATOR, i)) != -1) {
374+
do {
384375
String dir = platformPath.substring(0, i);
385376
String dirKey = toCaseComparable(dir);
386377
DirEntry dirEntry = (DirEntry) vfsEntries.get(dirKey);
@@ -394,7 +385,8 @@ private void initEntries() throws IOException {
394385
}
395386
parent = dirEntry;
396387
i++;
397-
}
388+
} while ((i = platformPath.indexOf(PLATFORM_SEPARATOR, i)) != -1);
389+
398390
assert parent != null;
399391
if (!platformPath.endsWith(PLATFORM_SEPARATOR)) {
400392
FileEntry fileEntry = new FileEntry(platformPath);

0 commit comments

Comments
 (0)