Skip to content

Commit

Permalink
Save downloaded libraries to .tmp, then rename once successful to avo…
Browse files Browse the repository at this point in the history
…id creating broken jars on errors
  • Loading branch information
eigenraven committed Apr 14, 2024
1 parent a62c401 commit c7bc58f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,13 @@ public Path targetLocation() {

public void download() throws IOException {
final Path targetDir = targetLocation.getParent();
final Path tempLocation = targetDir.resolve(
targetLocation.getFileName()
.toString() + ".tmp");

Files.createDirectories(targetDir);
Files.deleteIfExists(targetLocation);
Files.deleteIfExists(tempLocation);

byte[] data = null;
Relauncher.logger.info("Downloading {} from {}", targetLocation, sourceUrl);
Expand All @@ -372,7 +376,8 @@ public void download() throws IOException {
}
}
Objects.requireNonNull(data);
Files.write(targetLocation, data);
Files.write(tempLocation, data);
Files.move(tempLocation, targetLocation);
}

@Override
Expand Down

0 comments on commit c7bc58f

Please sign in to comment.