Skip to content

Commit d04e5a6

Browse files
committed
fix: remove temp directory and file on jvm exit
1 parent 765fe47 commit d04e5a6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/java/me/fponzi/tlaplusformatter/SANYWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public static TreeNode load(File file) throws IOException, SanyFrontendException
3535

3636
// Set a unique tmpdir to avoid race-condition in SANY
3737
// TODO: RM once https://github.com/tlaplus/tlaplus/issues/688 is fixed
38-
System.setProperty("java.io.tmpdir", sanyTempDir().toString());
38+
var tmpDir = sanyTempDir();
39+
tmpDir.deleteOnExit();
40+
System.setProperty("java.io.tmpdir", tmpDir.toString());
3941

4042
var specObj = new SpecObj(file.getAbsolutePath(), filenameResolver);
4143
loadSpecObject(specObj, file, errBuf);

src/main/java/me/fponzi/tlaplusformatter/TLAPlusFormatter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ private void verifyAstPreservation() throws IOException {
115115
*/
116116
private static File storeForVerification(String content, File originalSpec) throws IOException {
117117
File parentDir = originalSpec.getAbsoluteFile().getParentFile();
118-
File tmpDir = java.nio.file.Files.createTempDirectory("sany-verify").toFile();
118+
File tmpDir = Files.createTempDirectory("sany-verify").toFile();
119+
tmpDir.deleteOnExit();
119120
// Copy sibling .tla files so SANY can resolve EXTENDS
120121
File[] siblings = parentDir.listFiles((dir, name) -> name.endsWith(".tla"));
121122
if (siblings != null) {
122123
for (File sibling : siblings) {
123-
java.nio.file.Files.copy(
124+
Files.copy(
124125
sibling.toPath(),
125126
new File(tmpDir, sibling.getName()).toPath(),
126127
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
@@ -154,6 +155,8 @@ private static File storeToTmp(String spec) throws IOException {
154155
try (java.io.FileWriter writer = new java.io.FileWriter(tmpFile, StandardCharsets.UTF_8)) {
155156
writer.write(spec);
156157
}
158+
tmpFile.deleteOnExit();
159+
tmpFolder.deleteOnExit();
157160
return tmpFile;
158161
}
159162

0 commit comments

Comments
 (0)