Skip to content

Commit

Permalink
fix: #99 Interrupt download gracefully on ctrl+c (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 authored Jan 30, 2025
1 parent 2d18025 commit c23501a
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ private Path download(String component, String downloadUrl, String targetDir, St
int percentCompleted;

while ((bytesRead = inputStream.read(buffer)) != -1) {
if (Thread.currentThread().isInterrupted()) {
writeLn(warnLabel("Download", "Download interrupted by user."));
Files.deleteIfExists(targetPath);
return null;
}

outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
percentCompleted = (int) ((totalBytesRead * 100) / fileSize);
Expand Down

0 comments on commit c23501a

Please sign in to comment.