Skip to content

Commit ae1e244

Browse files
committed
avoid redundant path.normalize() calls in VFS
1 parent 81f3581 commit ae1e244

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -679,28 +679,23 @@ public void currentWorkingDirectory() throws Exception {
679679
resetCWD(fs);
680680
}
681681

682-
if (fs == noHostIOVFS) {
683-
checkException(SecurityException.class, () -> fs.setCurrentWorkingDirectory(realFSFile));
684-
checkException(SecurityException.class, () -> fs.setCurrentWorkingDirectory(realFSDir));
685-
} else {
686-
checkException(IllegalArgumentException.class, () -> fs.setCurrentWorkingDirectory(realFSFile));
687-
try {
688-
// support non existing working dir
689-
Path nonExistingDir = realFSDir.resolve("does-not-exist");
690-
fs.setCurrentWorkingDirectory(nonExistingDir);
691-
assertEquals(nonExistingDir, fs.toAbsolutePath(Path.of("dir")).getParent());
692-
693-
fs.setCurrentWorkingDirectory(realFSDir);
694-
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
695-
696-
fs.setCurrentWorkingDirectory(Path.of(VFS_ROOT + "../" + realFSDir.toString()));
697-
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
698-
699-
fs.setCurrentWorkingDirectory(Path.of(realFSDir.toString() + "/..".repeat(realFSDir.getNameCount()) + VFS_ROOT));
700-
assertEquals(VFS_ROOT_PATH.resolve("dir1"), fs.toAbsolutePath(Path.of("dir1")));
701-
} finally {
702-
resetCWD(fs);
703-
}
682+
checkException(IllegalArgumentException.class, () -> fs.setCurrentWorkingDirectory(realFSFile));
683+
try {
684+
// support non existing working dir
685+
Path nonExistingDir = realFSDir.resolve("does-not-exist");
686+
fs.setCurrentWorkingDirectory(nonExistingDir);
687+
assertEquals(nonExistingDir, fs.toAbsolutePath(Path.of("dir")).getParent());
688+
689+
fs.setCurrentWorkingDirectory(realFSDir);
690+
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
691+
692+
fs.setCurrentWorkingDirectory(Path.of(VFS_ROOT + "../" + realFSDir.toString()));
693+
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
694+
695+
fs.setCurrentWorkingDirectory(Path.of(realFSDir.toString() + "/..".repeat(realFSDir.getNameCount()) + VFS_ROOT));
696+
assertEquals(VFS_ROOT_PATH.resolve("dir1"), fs.toAbsolutePath(Path.of("dir1")));
697+
} finally {
698+
resetCWD(fs);
704699
}
705700
}
706701
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,16 @@ private BaseEntry getEntry(Path inputPath) throws IOException {
439439
warn("VFS.getEntry: no entries after init");
440440
}
441441
}
442-
Path path = resolveVFSRelative(inputPath).normalize();
442+
Path path = resolveVFSRelative(inputPath);
443443
return vfsEntries.get(toCaseComparable(path.toString()));
444444
}
445445

446+
/**
447+
* Determines if the given path belongs to the VFS. The path should be already normalized
448+
*/
446449
private boolean pathIsInVfs(Path path) {
447-
return toCaseComparable(path.normalize().toString()).startsWith(mountPointLowerCase);
450+
assert path.toString().equals(path.normalize().toString());
451+
return toCaseComparable(path.toString()).startsWith(mountPointLowerCase);
448452
}
449453

450454
/**
@@ -909,9 +913,8 @@ public Path toRealPath(Path p, LinkOption... linkOptions) throws IOException {
909913
result = path;
910914
}
911915
}
912-
Path ret = result.normalize();
913-
finer("VFS.toRealPath '%s' -> '%s'", path, ret);
914-
return ret;
916+
finer("VFS.toRealPath '%s' -> '%s'", path, result);
917+
return result;
915918
}
916919
}
917920

0 commit comments

Comments
 (0)