Skip to content

Commit a03b323

Browse files
fangerertimfel
authored andcommitted
Use Predicate instead of DirectoryStream.Filter
(cherry picked from commit 9c84384)
1 parent a79f0f1 commit a03b323

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

graalpython/lib-graalpython/modules/standalone/templates/VirtualFileSystem.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
import java.util.Map;
7171
import java.util.Set;
7272
import java.util.TreeMap;
73+
import java.util.function.Predicate;
74+
7375
import org.graalvm.polyglot.io.FileSystem;
7476

7577
public final class VirtualFileSystem implements FileSystem {
@@ -120,8 +122,16 @@ private static final record Entry(boolean isFile, Object data) {};
120122
* If that file or directory actually exists, it will not be accessible.
121123
*/
122124
private final Path mountPoint;
125+
126+
/**
127+
* The temporary directory where to extract files/directories to.
128+
*/
123129
private final Path extractDir;
124-
private final DirectoryStream.Filter<Path> extractFilter;
130+
131+
/**
132+
* A filter to determine if a path should be extracted (see {@link #shouldExtract(Path)}).
133+
*/
134+
private final Predicate<Path> extractFilter;
125135
private static final boolean caseInsensitive = isWindows();
126136

127137
public VirtualFileSystem() {
@@ -134,7 +144,7 @@ public VirtualFileSystem() {
134144
* {@link #toAbsolutePath(Path) absolute path} is computed. This argument may be {@code null}
135145
* causing that no extraction will happen.
136146
*/
137-
public VirtualFileSystem(DirectoryStream.Filter<Path> extractFilter) {
147+
public VirtualFileSystem(Predicate<Path> extractFilter) {
138148
String mp = System.getenv("GRAALPY_VFS_MOUNT_POINT");
139149
if (mp == null) {
140150
mp = isWindows() ? "X:\\graalpy_vfs" : "/graalpy_vfs";
@@ -323,15 +333,10 @@ private Entry file(Path path) throws IOException {
323333
}
324334

325335
/**
326-
* Determines if the given platform path should be extracted to a temp directory. This is
327-
* determined by the provided filter accepts the path.
336+
* Uses {@link #extractFilter} to determine if the given platform path should be extracted.
328337
*/
329338
private boolean shouldExtract(Path path) {
330-
try {
331-
return extractFilter != null && extractFilter.accept(path);
332-
} catch (IOException e) {
333-
throw new IllegalStateException(e);
334-
}
339+
return extractFilter != null && extractFilter.test(path);
335340
}
336341

337342
/**

0 commit comments

Comments
 (0)