Skip to content

Commit d5bfd25

Browse files
committed
added DeniedIOFS to VFS
1 parent ae1e244 commit d5bfd25

File tree

2 files changed

+189
-147
lines changed

2 files changed

+189
-147
lines changed

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import java.nio.file.attribute.FileAttribute;
6666
import java.nio.file.attribute.FileTime;
6767
import java.util.ArrayList;
68-
import java.util.Collections;
6968
import java.util.HashSet;
7069
import java.util.Iterator;
7170
import java.util.List;
@@ -156,7 +155,7 @@ public void toRealPath() throws Exception {
156155
assertEquals(VFS_ROOT_PATH.resolve("dir1"), rwHostIOVFS.toRealPath(Path.of(realFSDir.toString() + "/..".repeat(realFSDir.getNameCount()) + VFS_ROOT).resolve("dir1")));
157156
}
158157

159-
private void toRealPathVFS(FileSystem fs, String pathPrefix) throws IOException {
158+
private static void toRealPathVFS(FileSystem fs, String pathPrefix) throws IOException {
160159
// check regular resource dir
161160
assertEquals(Path.of(VFS_ROOT + "dir1"), fs.toRealPath(Path.of(pathPrefix + "dir1/../dir1")));
162161
// check regular resource file
@@ -330,7 +329,7 @@ public void checkAccess() throws Exception {
330329
checkException(SecurityException.class, () -> noHostIOVFS.checkAccess(realFSPath, Set.of(AccessMode.READ)), "expected error for no host io fs");
331330
}
332331

333-
private void checkAccessVFS(FileSystem fs, String pathPrefix) throws IOException {
332+
private static void checkAccessVFS(FileSystem fs, String pathPrefix) throws IOException {
334333
// check regular resource dir
335334
fs.checkAccess(Path.of(pathPrefix + "dir1"), Set.of(AccessMode.READ));
336335
// check regular resource file
@@ -418,7 +417,7 @@ public void delete() throws Exception {
418417
});
419418
}
420419

421-
private void deleteVFS(FileSystem fs, String pathPrefix) {
420+
private static void deleteVFS(FileSystem fs, String pathPrefix) {
422421
checkDelete(fs, pathPrefix + "file1");
423422
checkDelete(fs, pathPrefix + "dir1");
424423
checkDelete(fs, pathPrefix + "extractme");
@@ -457,7 +456,7 @@ public void newByteChannel() throws Exception {
457456
}
458457
}
459458

460-
private void newByteChannelVFS(FileSystem fs, String pathPrefix) throws IOException {
459+
private static void newByteChannelVFS(FileSystem fs, String pathPrefix) throws IOException {
461460
Path path = Path.of(pathPrefix + "file1");
462461
for (StandardOpenOption o : StandardOpenOption.values()) {
463462
if (o == StandardOpenOption.READ) {
@@ -479,7 +478,7 @@ private void newByteChannelVFS(FileSystem fs, String pathPrefix) throws IOExcept
479478
checkCanOnlyRead(fs, path, StandardOpenOption.READ, StandardOpenOption.WRITE);
480479
}
481480

482-
private void newByteChannelRealFS(FileSystem fs, Path path, String expectedText) throws IOException {
481+
private static void newByteChannelRealFS(FileSystem fs, Path path, String expectedText) throws IOException {
483482
SeekableByteChannel bch = fs.newByteChannel(path, Set.of(StandardOpenOption.READ));
484483
ByteBuffer buffer = ByteBuffer.allocate(expectedText.length());
485484
bch.read(buffer);
@@ -580,7 +579,7 @@ public void libsExtract() throws Exception {
580579
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
581580
extractFilter(p -> p.getFileName().toString().endsWith(".tso")).//
582581
resourceLoadingClass(VirtualFileSystemTest.class).build());
583-
Path p = fs.toAbsolutePath(VFS_ROOT_PATH.resolve("site-packages/testpkg/file.tso"));
582+
Path p = fs.toRealPath(VFS_ROOT_PATH.resolve("site-packages/testpkg/file.tso"));
584583
checkExtractedFile(p, null);
585584
Path extractedRoot = p.getParent().getParent().getParent();
586585

@@ -592,7 +591,7 @@ public void libsExtract() throws Exception {
592591
checkExtractedFile(extractedRoot.resolve("site-packages/testpkg.libs/dir/dir/file1.tso"), null);
593592
checkExtractedFile(extractedRoot.resolve("site-packages/testpkg.libs/dir/dir/file2.tso"), null);
594593

595-
p = fs.toAbsolutePath(VFS_ROOT_PATH.resolve("site-packages/testpkg-nolibs/file.tso"));
594+
p = fs.toRealPath(VFS_ROOT_PATH.resolve("site-packages/testpkg-nolibs/file.tso"));
596595
checkExtractedFile(p, null);
597596
}
598597

@@ -667,33 +666,33 @@ public void currentWorkingDirectory() throws Exception {
667666
checkException(IllegalArgumentException.class, () -> fs.setCurrentWorkingDirectory(VFS_ROOT_PATH.resolve("file1")));
668667

669668
try {
670-
// support non existing working dir
671669
Path nonExistingDir = VFS_ROOT_PATH.resolve("does-not-exist");
672670
fs.setCurrentWorkingDirectory(nonExistingDir);
673671
assertEquals(nonExistingDir, fs.toAbsolutePath(Path.of("dir")).getParent());
674672

675673
Path vfsDir = VFS_ROOT_PATH.resolve("dir1");
676674
fs.setCurrentWorkingDirectory(vfsDir);
677675
assertEquals(vfsDir, fs.toAbsolutePath(Path.of("dir")).getParent());
678-
} finally {
679-
resetCWD(fs);
680-
}
681676

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());
677+
fs.setCurrentWorkingDirectory(Path.of(realFSDir.toString() + "/..".repeat(realFSDir.getNameCount()) + VFS_ROOT));
678+
assertEquals(VFS_ROOT_PATH.resolve("dir1"), fs.toAbsolutePath(Path.of("dir1")));
688679

689-
fs.setCurrentWorkingDirectory(realFSDir);
690-
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
680+
if (fs == noHostIOVFS) {
681+
fs.setCurrentWorkingDirectory(realFSFile);
682+
assertEquals(VFS_ROOT_PATH, fs.toAbsolutePath(Path.of(realFSFile.toString() + "/..".repeat(realFSFile.getNameCount()) + VFS_ROOT)));
683+
} else {
684+
checkException(IllegalArgumentException.class, () -> fs.setCurrentWorkingDirectory(realFSFile));
691685

692-
fs.setCurrentWorkingDirectory(Path.of(VFS_ROOT + "../" + realFSDir.toString()));
693-
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
686+
nonExistingDir = realFSDir.resolve("does-not-exist");
687+
fs.setCurrentWorkingDirectory(nonExistingDir);
688+
assertEquals(nonExistingDir, fs.toAbsolutePath(Path.of("dir")).getParent());
694689

695-
fs.setCurrentWorkingDirectory(Path.of(realFSDir.toString() + "/..".repeat(realFSDir.getNameCount()) + VFS_ROOT));
696-
assertEquals(VFS_ROOT_PATH.resolve("dir1"), fs.toAbsolutePath(Path.of("dir1")));
690+
fs.setCurrentWorkingDirectory(realFSDir);
691+
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
692+
693+
fs.setCurrentWorkingDirectory(Path.of(VFS_ROOT + "../" + realFSDir.toString()));
694+
assertEquals(realFSDir, fs.toAbsolutePath(Path.of("dir")).getParent());
695+
}
697696
} finally {
698697
resetCWD(fs);
699698
}

0 commit comments

Comments
 (0)