Skip to content

Commit 6060f3f

Browse files
committed
delegate VFS.copy only if both paths are not from VFS
1 parent f14be98 commit 6060f3f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.nio.file.AccessMode;
6060
import java.nio.file.DirectoryStream;
6161
import java.nio.file.Files;
62+
import java.nio.file.LinkOption;
6263
import java.nio.file.NoSuchFileException;
6364
import java.nio.file.NotDirectoryException;
6465
import java.nio.file.OpenOption;
@@ -83,6 +84,7 @@
8384
import static org.graalvm.python.embedding.utils.VirtualFileSystem.HostIO.READ_WRITE;
8485
import static org.junit.Assert.assertEquals;
8586
import static org.junit.Assert.assertFalse;
87+
import static org.junit.Assert.assertNotNull;
8688
import static org.junit.Assert.assertTrue;
8789
import static org.junit.Assert.fail;
8890

@@ -901,9 +903,22 @@ public void copy() throws Exception {
901903

902904
Path realFSPath5 = realFSPath.getParent().resolve("fromvfs2");
903905
assertFalse(Files.exists(realFSPath5));
904-
withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("file1"), Path.of("../" + realFSPath5.toString())));
905-
assertTrue(Files.exists(realFSPath5));
906-
newByteChannelRealFS(rwHostIOVFS, realFSPath5, "text1");
906+
// NoSuchFileException: no such file or directory: '/test_mount_point/does-no-exist'
907+
checkException(NoSuchFileException.class, () -> rwHostIOVFS.copy(VFS_ROOT_PATH.resolve("does-no-exist"), realFSPath5));
908+
assertFalse(Files.exists(realFSPath5));
909+
910+
Path realFSPath6 = realFSPath.getParent().resolve("fromvfs3");
911+
assertFalse(Files.exists(realFSPath6));
912+
// SecurityException: Operation is not allowed for: realFSPath
913+
checkException(SecurityException.class, () -> rHostIOVFS.copy(VFS_ROOT_PATH.resolve("file1"), realFSPath6));
914+
assertFalse(Files.exists(realFSPath6));
915+
916+
Path realFSPath7 = realFSPath.getParent().resolve("fromvfs3");
917+
assertFalse(Files.exists(realFSPath7));
918+
withCWD(rwHostIOVFS, VFS_ROOT_PATH, (fs) -> fs.copy(Path.of("file1"), Path.of("../" + realFSPath7.toString())));
919+
assertTrue(Files.exists(realFSPath7));
920+
newByteChannelRealFS(rwHostIOVFS, realFSPath7, "text1");
921+
907922
}
908923

909924
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,10 +981,10 @@ public void copy(Path s, Path t, CopyOption... options) throws IOException {
981981
Path source = toAbsolutePathInternal(s);
982982
Path target = toAbsolutePathInternal(t);
983983
if (pathIsInVfs(target)) {
984-
throw securityException("VFS.move", String.format("read-only filesystem, can't copy '%s' to '%s'", source, target));
984+
throw securityException("VFS.copy", String.format("read-only filesystem, can't copy '%s' to '%s'", source, target));
985985
} else {
986986
try {
987-
if (allowHostIO == READ_WRITE && pathIsInVfs(source)) {
987+
if (pathIsInVfs(source)) {
988988
FileSystem.super.copy(source, target, options);
989989
} else {
990990
delegate.copy(source, target, options);

0 commit comments

Comments
 (0)