Skip to content

Commit 84464f2

Browse files
committed
removed VirtualFileSytem.getPrefix() and added VirtualFileSytem.getMountPoint() instead
1 parent 2ff0e68 commit 84464f2

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,27 @@ public void defaultValues() throws Exception {
7272
VirtualFileSystem vfs = VirtualFileSystem.create();
7373
VirtualFileSystem vfs2 = VirtualFileSystem.newBuilder().build();
7474

75-
assertEquals(vfs.getPrefix(), vfs2.getPrefix());
76-
assertEquals(vfs.getFileListPath(), vfs2.getFileListPath());
75+
assertEquals(vfs.getMountPoint(), vfs2.getMountPoint());
76+
assertEquals(vfs.vfsHomePath(), vfs2.vfsHomePath());
77+
assertEquals(vfs.vfsProjPath(), vfs2.vfsProjPath());
78+
assertEquals(vfs.vfsVenvPath(), vfs2.vfsVenvPath());
79+
80+
assertEquals(IS_WINDOWS ? "X:\\graalpy_vfs" : "/graalpy_vfs", vfs.getMountPoint());
81+
assertEquals(IS_WINDOWS ? "X:\\graalpy_vfs\\home" : "/graalpy_vfs/home", vfs.vfsHomePath());
82+
assertEquals(IS_WINDOWS ? "X:\\graalpy_vfs\\proj" : "/graalpy_vfs/proj", vfs.vfsProjPath());
83+
assertEquals(IS_WINDOWS ? "X:\\graalpy_vfs\\venv" : "/graalpy_vfs/venv", vfs.vfsVenvPath());
84+
}
85+
86+
@Test
87+
public void mountPoints() throws Exception {
88+
VirtualFileSystem vfs = VirtualFileSystem.newBuilder().//
89+
unixMountPoint(VFS_MOUNT_POINT).//
90+
windowsMountPoint(VFS_WIN_MOUNT_POINT).build();
91+
92+
assertEquals(VFS_MOUNT_POINT, vfs.getMountPoint());
93+
assertEquals(IS_WINDOWS ? VFS_WIN_MOUNT_POINT + "\\home" : VFS_UNIX_MOUNT_POINT + "/home", vfs.vfsHomePath());
94+
assertEquals(IS_WINDOWS ? VFS_WIN_MOUNT_POINT + "\\proj" : VFS_UNIX_MOUNT_POINT + "/proj", vfs.vfsProjPath());
95+
assertEquals(IS_WINDOWS ? VFS_WIN_MOUNT_POINT + "\\venv" : VFS_UNIX_MOUNT_POINT + "/venv", vfs.vfsVenvPath());
7796
}
7897

7998
@Test
@@ -393,7 +412,6 @@ public Context getContext(Function<VirtualFileSystem.Builder, VirtualFileSystem.
393412
return cachedContext;
394413
}
395414
VirtualFileSystem.Builder builder = VirtualFileSystem.newBuilder().//
396-
// vfsPrefix(VFS_PREFIX).//
397415
unixMountPoint(VFS_MOUNT_POINT).//
398416
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
399417
resourceLoadingClass(VirtualFileSystemTest.class);

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ public Builder allowHostIO(HostIO b) {
132132

133133
/**
134134
* The mount point for the virtual filesystem on Windows. This mount point shadows any real
135-
* filesystem, so should be chosen to avoid clashes with the users machine.
135+
* filesystem, so should be chosen to avoid clashes with the users machine, e.g. if set to
136+
* "X:\graalpy_vfs", then a resource with path /org.graalvm.python.vfs/xyz/abc is visible as
137+
* "X:\graalpy_vfs\xyz\abc". This needs to be an absolute path with platform-specific
138+
* separators without any trailing separator. If that file or directory actually exists, it
139+
* will not be accessible.
136140
*/
137141
public Builder windowsMountPoint(String s) {
138142
windowsMountPoint = s;
@@ -141,7 +145,11 @@ public Builder windowsMountPoint(String s) {
141145

142146
/**
143147
* The mount point for the virtual filesystem on Unices. This mount point shadows any real
144-
* filesystem, so should be chosen to avoid clashes with the users machine.
148+
* filesystem, so should be chosen to avoid clashes with the users machine, e.g. if set to
149+
* "/graalpy_vfs", then a resource with path /org.graalvm.python.vfs/xyz/abc is visible as
150+
* "/graalpy_vfs/xyz/abc". This needs to be an absolute path with platform-specific
151+
* separators without any trailing separator. If that file or directory actually exists, it
152+
* will not be accessible.
145153
*/
146154
public Builder unixMountPoint(String s) {
147155
unixMountPoint = s;
@@ -259,7 +267,7 @@ public DirEntry(String platformPath) {
259267

260268
/*
261269
* Determines where the virtual filesystem lives in the real filesystem, e.g. if set to
262-
* "X:\graalpy_vfs", then a resource with path /vfs/xyz/abc is visible as
270+
* "X:\graalpy_vfs", then a resource with path /org.graalvm.python.vfs/xyz/abc is visible as
263271
* "X:\graalpy_vfs\xyz\abc". This needs to be an absolute path with platform-specific separators
264272
* without any trailing separator. If that file or directory actually exists, it will not be
265273
* accessible.
@@ -493,12 +501,14 @@ private BaseEntry getEntry(Path inputPath) throws IOException {
493501
return vfsEntries.get(toCaseComparable(path.toString()));
494502
}
495503

496-
public String getPrefix() {
497-
return this.vfsPrefix;
498-
}
499-
500-
public String getFileListPath() {
501-
return this.filesListPath;
504+
/**
505+
* The mount point for the virtual filesystem.
506+
*
507+
* @see Builder#windowsMountPoint(String)
508+
* @see Builder#unixMountPoint(String)
509+
*/
510+
public String getMountPoint() {
511+
return this.mountPoint.toString();
502512
}
503513

504514
private boolean pathIsInVfs(Path path) {
@@ -514,8 +524,8 @@ private boolean shouldExtract(Path path) {
514524

515525
/**
516526
* Extracts a file or directory from the resource to the temporary directory and returns the
517-
* path to the extracted file. Inexisting parent directories will also be created (recursively).
518-
* If the extracted file or directory already exists, nothing will be done.
527+
* path to the extracted file. Nonexistent parent directories will also be created
528+
* (recursively). If the extracted file or directory already exists, nothing will be done.
519529
*/
520530
private Path getExtractedPath(Path path) {
521531
assert extractDir != null;

0 commit comments

Comments
 (0)