@@ -134,8 +134,9 @@ public static final class Builder {
134
134
return s .endsWith (".so" ) || s .endsWith (".dylib" ) || s .endsWith (".pyd" ) || s .endsWith (".dll" ) || s .endsWith (".ttf" );
135
135
};
136
136
137
- private String windowsMountPoint = "X:\\ graalpy_vfs" ;
138
- private String unixMountPoint = "/graalpy_vfs" ;
137
+ private static final String DEFAULT_WINDOWS_MOUNT_POINT = "X:\\ graalpy_vfs" ;
138
+ private String DEFAULT_UNIX_MOUNT_POINT = "/graalpy_vfs" ;
139
+ private Path mountPoint ;
139
140
private Predicate <Path > extractFilter = DEFAULT_EXTRACT_FILTER ;
140
141
private HostIO allowHostIO = HostIO .READ_WRITE ;
141
142
private boolean caseInsensitive = isWindows ();
@@ -171,7 +172,9 @@ public Builder allowHostIO(HostIO b) {
171
172
* will not be accessible.
172
173
*/
173
174
public Builder windowsMountPoint (String s ) {
174
- windowsMountPoint = s ;
175
+ if (isWindows ()) {
176
+ mountPoint = getMountPointAsPath (s );
177
+ }
175
178
return this ;
176
179
}
177
180
@@ -184,7 +187,9 @@ public Builder windowsMountPoint(String s) {
184
187
* will not be accessible.
185
188
*/
186
189
public Builder unixMountPoint (String s ) {
187
- unixMountPoint = s ;
190
+ if (!isWindows ()) {
191
+ mountPoint = getMountPointAsPath (s );
192
+ }
188
193
return this ;
189
194
}
190
195
@@ -219,10 +224,21 @@ public Builder extractFilter(Predicate<Path> filter) {
219
224
}
220
225
221
226
public VirtualFileSystem build () {
222
- return new VirtualFileSystem (extractFilter , windowsMountPoint , unixMountPoint , allowHostIO , resourceLoadingClass , caseInsensitive );
227
+ if (mountPoint == null ) {
228
+ mountPoint = isWindows () ? Path .of (DEFAULT_WINDOWS_MOUNT_POINT ) : Path .of (DEFAULT_UNIX_MOUNT_POINT );
229
+ }
230
+ return new VirtualFileSystem (extractFilter , mountPoint , allowHostIO , resourceLoadingClass , caseInsensitive );
223
231
}
224
232
}
225
233
234
+ private static Path getMountPointAsPath (String mp ) {
235
+ Path mountPoint = Path .of (mp );
236
+ if (mp .endsWith (PLATFORM_SEPARATOR ) || !mountPoint .isAbsolute ()) {
237
+ throw new IllegalArgumentException (String .format ("Virtual filesystem mount point must be set to an absolute path without a trailing separator: '%s'" , mp ));
238
+ }
239
+ return mountPoint ;
240
+ }
241
+
226
242
public static Builder newBuilder () {
227
243
return new Builder ();
228
244
}
@@ -353,8 +369,7 @@ private void removeExtractDir() {
353
369
* causing that no extraction will happen.
354
370
*/
355
371
VirtualFileSystem (Predicate <Path > extractFilter ,
356
- String windowsMountPoint ,
357
- String unixMountPoint ,
372
+ Path mountPoint ,
358
373
HostIO allowHostIO ,
359
374
Class <?> resourceLoadingClass ,
360
375
boolean caseInsensitive ) {
@@ -365,15 +380,9 @@ private void removeExtractDir() {
365
380
}
366
381
367
382
this .caseInsensitive = caseInsensitive ;
368
- String mp = System .getenv ("GRAALPY_VFS_MOUNT_POINT" );
369
- if (mp == null ) {
370
- mp = isWindows () ? windowsMountPoint : unixMountPoint ;
371
- }
372
- this .mountPoint = Path .of (mp );
373
- this .mountPointLowerCase = mp .toLowerCase (Locale .ROOT );
374
- if (mp .endsWith (PLATFORM_SEPARATOR ) || !mountPoint .isAbsolute ()) {
375
- throw new IllegalArgumentException ("GRAALPY_VFS_MOUNT_POINT must be set to an absolute path without a trailing separator" );
376
- }
383
+ this .mountPoint = mountPoint ;
384
+
385
+ this .mountPointLowerCase = mountPoint .toString ().toLowerCase (Locale .ROOT );
377
386
378
387
fine ("VirtualFilesystem %s, allowHostIO: %s, resourceLoadingClass: %s, caseInsensitive: %s, extractOnStartup: %s%s" ,
379
388
mountPoint , allowHostIO .toString (), this .resourceLoadingClass .getName (), caseInsensitive , extractOnStartup , extractFilter != null ? "" : ", extractFilter: null" );
0 commit comments