From 262bd6931db5a7066004817ba964ee6a891067e5 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 9 Oct 2021 20:53:22 +0100 Subject: [PATCH] fix persistence of downloaders which was broken in GitHub issue #65 --- .../com/muwire/core/download/DownloadManager.groovy | 10 ++++++++-- .../groovy/com/muwire/core/download/Downloader.groovy | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy index 05d7a249..6dbc5f45 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy @@ -177,6 +177,9 @@ public class DownloadManager { downloadsFile.eachLine { def json = slurper.parseText(it) File file = new File(DataUtil.readi18nString(Base64.decode(json.file))) + File toShare = null + if (json.toShare != null) + toShare = new File(DataUtil.readi18nString(Base64.decode(json.toShare))) InfoHash infoHash if (json.hashList != null) { @@ -216,7 +219,7 @@ public class DownloadManager { Pieces pieces = getPieces(infoHash, (long)json.length, json.pieceSizePow2, sequential) - downloader = new NetworkDownloader(eventBus, this, chatServer, me, file, (long)json.length, + downloader = new NetworkDownloader(eventBus, this, chatServer, me, file, toShare, (long)json.length, infoHash, collectionInfoHash, json.pieceSizePow2, connector, destinations, incompletes, pieces, muSettings.downloadMaxFailures) downloader.successfulDestinations.addAll(destinations) // if it was persisted, it was successful downloader.readPieces() @@ -224,7 +227,7 @@ public class DownloadManager { downloader.paused = json.paused } else { File source = new File(DataUtil.readi18nString(Base64.decode(json.source))) - downloader = new CopyingDownloader(eventBus, this, file, (long)json.length, + downloader = new CopyingDownloader(eventBus, this, file, toShare, (long)json.length, infoHash, collectionInfoHash, json.pieceSizePow2, source) } @@ -277,6 +280,9 @@ public class DownloadManager { if (!downloader.cancelled) { def json = [:] json.file = Base64.encode(DataUtil.encodei18nString(downloader.file.getAbsolutePath())) + if (downloader.toShare != null) { + json.toShare = Base64.encode(DataUtil.encodei18nString(downloader.toShare.getAbsolutePath())) + } json.length = downloader.length json.pieceSizePow2 = downloader.pieceSizePow2 diff --git a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy index a443bf2b..94505647 100644 --- a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy +++ b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy @@ -28,7 +28,7 @@ abstract class Downloader { protected final DownloadManager downloadManager protected final File file - private final File toShare + protected final File toShare protected final long length protected volatile InfoHash infoHash, collectionInfoHash