Skip to content

Commit

Permalink
8265078: jpackage tests on Windows leave large temp files
Browse files Browse the repository at this point in the history
Reviewed-by: asemenyuk, kcr
  • Loading branch information
Andy Herrick committed Apr 14, 2021
1 parent 05f851e commit e167577
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
Expand All @@ -56,6 +57,8 @@
public class IOUtils {

public static void deleteRecursive(Path directory) throws IOException {
final AtomicReference<IOException> exception = new AtomicReference<>();

if (!Files.exists(directory)) {
return;
}
Expand All @@ -67,7 +70,11 @@ public FileVisitResult visitFile(Path file,
if (Platform.getPlatform() == Platform.WINDOWS) {
Files.setAttribute(file, "dos:readonly", false);
}
Files.delete(file);
try {
Files.delete(file);
} catch (IOException ex) {
exception.compareAndSet(null, ex);
}
return FileVisitResult.CONTINUE;
}

Expand All @@ -83,10 +90,17 @@ public FileVisitResult preVisitDirectory(Path dir,
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
Files.delete(dir);
try {
Files.delete(dir);
} catch (IOException ex) {
exception.compareAndSet(null, ex);
}
return FileVisitResult.CONTINUE;
}
});
if (exception.get() != null) {
throw exception.get();
}
}

public static void copyRecursive(Path src, Path dest) throws IOException {
Expand Down
11 changes: 11 additions & 0 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public Executor setRemovePath(boolean value) {
return this;
}

public Executor setWindowsTmpDir(String tmp) {
TKit.assertTrue(TKit.isWindows(),
"setWindowsTmpDir is only valid on Windows platform");
winTmpDir = tmp;
return this;
}

/**
* Configures this instance to save full output that command will produce.
* This function is mutual exclusive with
Expand Down Expand Up @@ -279,6 +286,9 @@ private Result runExecutable() throws IOException, InterruptedException {
command.add(executablePath().toString());
command.addAll(args);
ProcessBuilder builder = new ProcessBuilder(command);
if (winTmpDir != null) {
builder.environment().put("TMP", winTmpDir);
}
StringBuilder sb = new StringBuilder(getPrintableCommandLine());
if (withSavedOutput()) {
builder.redirectErrorStream(true);
Expand Down Expand Up @@ -426,6 +436,7 @@ private static void trace(String msg) {
private Set<SaveOutputType> saveOutputType;
private Path directory;
private boolean removePath;
private String winTmpDir = null;

private static enum SaveOutputType {
NONE, FULL, FIRST_LINE, DUMP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ private Executor createExecutor() {
exec.setToolProvider(JavaTool.JPACKAGE);
} else {
exec.setExecutable(JavaTool.JPACKAGE);
if (TKit.isWindows()) {
exec.setWindowsTmpDir(System.getProperty("java.io.tmpdir"));
}
}

return exec;
Expand Down

1 comment on commit e167577

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.