From a036a18117059e3fbcc06b7e6fbc2f8c67c74d4e Mon Sep 17 00:00:00 2001 From: Yi Hu Date: Tue, 31 Oct 2023 15:51:59 -0400 Subject: [PATCH] Delete on exit beam-artifact temp file (#29219) --- .../org/apache/beam/runners/core/construction/External.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java index 534a2b5fe0e6..93a1ade474a5 100644 --- a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java +++ b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java @@ -19,6 +19,7 @@ import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; @@ -391,7 +392,8 @@ private static List resolveArtifacts( .build()) .getReplacementsList()) { Path path = Files.createTempFile("beam-artifact", ""); - try (FileOutputStream fout = new FileOutputStream(path.toFile())) { + File artifactFile = path.toFile(); + try (FileOutputStream fout = new FileOutputStream(artifactFile)) { for (Iterator it = retrievalStub.getArtifact( ArtifactApi.GetArtifactRequest.newBuilder().setArtifact(artifact).build()); @@ -409,6 +411,8 @@ private static List resolveArtifacts( .build() .toByteString()) .build()); + // Delete beam-artifact temp File on program exit + artifactFile.deleteOnExit(); } return resolved; }