mirror of https://github.com/zlatinb/muwire
remove incomplete file and pieces file if download is hopeless
parent
28d1d9fc0e
commit
18696f9b88
|
@ -115,6 +115,15 @@ class NetworkDownloader extends Downloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void closePiecesFile() {
|
||||||
|
synchronized (piecesFile) {
|
||||||
|
if (piecesFileClosed)
|
||||||
|
return
|
||||||
|
piecesFileClosed = true
|
||||||
|
piecesFile.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long donePieces() {
|
long donePieces() {
|
||||||
pieces.donePieces()
|
pieces.donePieces()
|
||||||
}
|
}
|
||||||
|
@ -409,19 +418,20 @@ class NetworkDownloader extends Downloader {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
log.log(Level.WARNING, "Exception while downloading", DataUtil.findRoot(bad))
|
log.log(Level.WARNING, "Exception while downloading", DataUtil.findRoot(bad))
|
||||||
markFailed(destination)
|
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))
|
eventBus.publish(new DownloadHopelessEvent(downloader: NetworkDownloader.this))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
currentState = WorkerState.FINISHED
|
currentState = WorkerState.FINISHED
|
||||||
try {
|
try {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
writePieces()
|
writePieces()
|
||||||
if (pieces.isComplete() && eventFired.compareAndSet(false, true)) {
|
if (pieces.isComplete() && eventFired.compareAndSet(false, true)) {
|
||||||
synchronized (piecesFile) {
|
closePiecesFile()
|
||||||
piecesFileClosed = true
|
|
||||||
piecesFile.delete()
|
|
||||||
}
|
|
||||||
activeWorkers.values().each {
|
activeWorkers.values().each {
|
||||||
if (it.destination != destination)
|
if (it.destination != destination)
|
||||||
it.cancel()
|
it.cancel()
|
||||||
|
|
Loading…
Reference in New Issue