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