Skip to content

Commit 74a74c8

Browse files
committed
only cleanup temp files owned by current user
1 parent b339017 commit 74a74c8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/test/SubprocessUtil.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
import java.io.File;
2929
import java.io.IOException;
3030
import java.io.InputStreamReader;
31+
import java.nio.file.FileSystems;
3132
import java.nio.file.Files;
3233
import java.nio.file.Path;
3334
import java.nio.file.attribute.FileTime;
35+
import java.nio.file.attribute.UserPrincipal;
3436
import java.time.Duration;
3537
import java.time.Instant;
3638
import java.time.temporal.ChronoUnit;
@@ -598,13 +600,15 @@ private static int findMainClassIndex(List<String> commandLine) {
598600
}
599601

600602
/**
601-
* Manages temporary files with a given prefix and suffix.
603+
* Manages temporary files with a given prefix and suffix. When new files are created, temporary
604+
* files older than 2 hours are deleted.
602605
*/
603606
public static class TemporaryFiles {
604607
private final Path dir;
605608
private final FileTime maxAge;
606609
private final String prefix;
607610
private final String suffix;
611+
private final UserPrincipal user;
608612

609613
public TemporaryFiles(String prefix, String suffix) {
610614
this.dir = Path.of(System.getProperty("java.io.tmpdir"));
@@ -613,6 +617,11 @@ public TemporaryFiles(String prefix, String suffix) {
613617
FileTime.from(Instant.now().minus(2, ChronoUnit.HOURS));
614618
this.prefix = prefix;
615619
this.suffix = suffix;
620+
try {
621+
this.user = FileSystems.getDefault().getUserPrincipalLookupService().lookupPrincipalByName(System.getProperty("user.name"));
622+
} catch (IOException e) {
623+
throw new AssertionError(e);
624+
}
616625
}
617626

618627
/**
@@ -640,7 +649,7 @@ private void removeOldFiles() {
640649
try {
641650
Files.list(dir).filter(this::match).forEach(p -> {
642651
try {
643-
if (Files.getLastModifiedTime(p).compareTo(maxAge) < 0) {
652+
if (Files.getOwner(p).equals(user) && Files.getLastModifiedTime(p).compareTo(maxAge) < 0) {
644653
Files.delete(p);
645654
if (DEBUG) {
646655
System.out.println("deleted " + p);

0 commit comments

Comments
 (0)