Skip to content

Commit 7b1e2ac

Browse files
caaladorZheSun88
andauthored
fix: remove broken node archive (#20818)
* 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 <31067185+ZheSun88@users.noreply.github.com>
1 parent 2a4dda7 commit 7b1e2ac

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/installer/NodeInstaller.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,24 +493,29 @@ private void extractFile(File archive, File destinationDirectory)
493493
"The archive file {} is corrupted and will be deleted. "
494494
+ "Please run the application again.",
495495
archive.getPath());
496-
boolean deleted = archive.delete();
497-
if (!deleted) {
498-
getLogger().error("Failed to remove archive file {}. "
499-
+ "Please remove it manually and run the application.",
500-
archive.getPath());
501-
}
496+
removeArchiveFile(archive);
502497
try {
503498
FileUtils.deleteDirectory(destinationDirectory);
504499
} catch (IOException ioe) {
505500
getLogger().error("Failed to remove target directory '{}'",
506501
destinationDirectory, ioe);
507502
}
503+
} else {
504+
removeArchiveFile(archive);
508505
}
509506

510507
throw e;
511508
}
512509
}
513510

511+
private static void removeArchiveFile(File archive) {
512+
if (!archive.delete()) {
513+
getLogger().error("Failed to remove archive file {}. "
514+
+ "Please remove it manually and run the application.",
515+
archive.getPath());
516+
}
517+
}
518+
514519
private void downloadFileIfMissing(URI downloadUrl, File destination,
515520
String userName, String password) throws DownloadException {
516521
if (!destination.exists()) {
@@ -522,6 +527,7 @@ private void downloadFileIfMissing(URI downloadUrl, File destination,
522527
return;
523528
} catch (DownloadException e) {
524529
if (i == MAX_DOWNLOAD_ATTEMPS - 1) {
530+
removeArchiveFile(destination);
525531
throw e;
526532
}
527533

0 commit comments

Comments
 (0)