Skip to content

Commit

Permalink
cleanup temp remote artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
natedanner committed Oct 10, 2024
1 parent cd09a07 commit 9c777c3
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public LocalRemoteArtifactCache(Path cacheDir) {

@Override
public @Nullable Path put(URI uri, InputStream artifactInputStream, Consumer<Throwable> onError) {
Path artifact = null;
try {
Path artifact = cacheDir.resolve(UUID.randomUUID() + ".tmp");
artifact = cacheDir.resolve(UUID.randomUUID() + ".tmp");
try (InputStream is = artifactInputStream) {
Files.copy(is, artifact, StandardCopyOption.REPLACE_EXISTING);
}
Expand All @@ -56,14 +57,19 @@ public LocalRemoteArtifactCache(Path cacheDir) {
if (!Files.exists(cachedArtifact)) {
Files.move(artifact, cachedArtifact, StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING);
} else {
Files.delete(artifact);
}
}
return cachedArtifact;
} catch (Exception e) {
onError.accept(e);
return null;
} finally {
if (artifact != null) {
try {
Files.deleteIfExists(artifact);
} catch (Exception ignored) {
}
}
}
}

Expand Down

0 comments on commit 9c777c3

Please sign in to comment.