remove incomplete file and pieces file if download is hopeless

auto-update
Zlatin Balevsky 2022-02-21 10:43:56 +00:00
parent 28d1d9fc0e
commit 18696f9b88
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 15 additions and 5 deletions

View File

@ -114,6 +114,15 @@ class NetworkDownloader extends Downloader {
}
}
}
private void closePiecesFile() {
synchronized (piecesFile) {
if (piecesFileClosed)
return
piecesFileClosed = true
piecesFile.delete()
}
}
long donePieces() {
pieces.donePieces()
@ -409,8 +418,12 @@ class NetworkDownloader extends Downloader {
if (!cancelled) {
log.log(Level.WARNING, "Exception while downloading", DataUtil.findRoot(bad))
markFailed(destination)
if (!hasLiveSources() && hopelessEventFired.compareAndSet(false, true))
if (!hasLiveSources() && hopelessEventFired.compareAndSet(false, true)) {
log.info("Download hopeless, removing incomplete file")
incompleteFile.delete()
closePiecesFile()
eventBus.publish(new DownloadHopelessEvent(downloader: NetworkDownloader.this))
}
}
} finally {
currentState = WorkerState.FINISHED
@ -418,10 +431,7 @@ class NetworkDownloader extends Downloader {
if (!cancelled) {
writePieces()
if (pieces.isComplete() && eventFired.compareAndSet(false, true)) {
synchronized (piecesFile) {
piecesFileClosed = true
piecesFile.delete()
}
closePiecesFile()
activeWorkers.values().each {
if (it.destination != destination)
it.cancel()