Skip to content

Commit

Permalink
fix: remove broken node archive (#20818)
Browse files Browse the repository at this point in the history
* fix: remove broken node archive

If archive extraction throws
remove arcive to next time re-download.

* remove archive file in exceptions

In cases where the archive can be corrupt
remove file.

---------

Co-authored-by: Zhe Sun <[email protected]>
  • Loading branch information
caalador and ZheSun88 authored Jan 9, 2025
1 parent 2a4dda7 commit 7b1e2ac
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,24 +493,29 @@ private void extractFile(File archive, File destinationDirectory)
"The archive file {} is corrupted and will be deleted. "
+ "Please run the application again.",
archive.getPath());
boolean deleted = archive.delete();
if (!deleted) {
getLogger().error("Failed to remove archive file {}. "
+ "Please remove it manually and run the application.",
archive.getPath());
}
removeArchiveFile(archive);
try {
FileUtils.deleteDirectory(destinationDirectory);
} catch (IOException ioe) {
getLogger().error("Failed to remove target directory '{}'",
destinationDirectory, ioe);
}
} else {
removeArchiveFile(archive);
}

throw e;
}
}

private static void removeArchiveFile(File archive) {
if (!archive.delete()) {
getLogger().error("Failed to remove archive file {}. "
+ "Please remove it manually and run the application.",
archive.getPath());
}
}

private void downloadFileIfMissing(URI downloadUrl, File destination,
String userName, String password) throws DownloadException {
if (!destination.exists()) {
Expand All @@ -522,6 +527,7 @@ private void downloadFileIfMissing(URI downloadUrl, File destination,
return;
} catch (DownloadException e) {
if (i == MAX_DOWNLOAD_ATTEMPS - 1) {
removeArchiveFile(destination);
throw e;
}

Expand Down

0 comments on commit 7b1e2ac

Please sign in to comment.