Skip to content

Commit 82fa61b

Browse files
fangerertimfel
authored andcommitted
Cleanup extract dir
(cherry picked from commit 896024c)
1 parent ab0291d commit 82fa61b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public static void main(String[] args) throws IOException {
102102
throw e;
103103
}
104104
}
105+
} finally {
106+
vfs.close();
105107
}
106108
}
107109

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@
5151
import java.nio.channels.SeekableByteChannel;
5252
import java.nio.file.AccessMode;
5353
import java.nio.file.DirectoryStream;
54+
import java.nio.file.FileVisitResult;
5455
import java.nio.file.Files;
5556
import java.nio.file.LinkOption;
5657
import java.nio.file.NotDirectoryException;
5758
import java.nio.file.OpenOption;
5859
import java.nio.file.Path;
5960
import java.nio.file.Paths;
61+
import java.nio.file.SimpleFileVisitor;
6062
import java.nio.file.StandardOpenOption;
63+
import java.nio.file.attribute.BasicFileAttributes;
6164
import java.nio.file.attribute.FileAttribute;
6265
import java.nio.file.attribute.FileTime;
6366
import java.util.ArrayList;
@@ -74,7 +77,7 @@
7477

7578
import org.graalvm.polyglot.io.FileSystem;
7679

77-
public final class VirtualFileSystem implements FileSystem {
80+
public final class VirtualFileSystem implements FileSystem, AutoCloseable {
7881

7982
/*
8083
* Root of the virtual filesystem in the resources.
@@ -165,6 +168,28 @@ public VirtualFileSystem(Predicate<Path> extractFilter) {
165168
}
166169
}
167170

171+
public void close() {
172+
if (extractDir != null) {
173+
try {
174+
Files.walkFileTree(extractDir, new SimpleFileVisitor<Path>() {
175+
@Override
176+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
177+
Files.delete(file);
178+
return FileVisitResult.CONTINUE;
179+
}
180+
181+
@Override
182+
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
183+
Files.delete(dir);
184+
return FileVisitResult.CONTINUE;
185+
}
186+
});
187+
} catch (IOException e) {
188+
System.err.format("Could not delete temp directory '%s': %s", extractDir, e);
189+
}
190+
}
191+
}
192+
168193
public static boolean isWindows() {
169194
return System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows");
170195
}

0 commit comments

Comments
 (0)