make all Downloader downloads cancelable

Allowing all downloads, including updates, to be canceled simplifies the
code and if the user wants to cancel an update, they should be able to. But
canceling updates is not implemented in this commit.
This commit is contained in:
Hans-Christoph Steiner 2016-03-28 16:52:58 +02:00
parent 88b5e284b5
commit 2019b7a7c3
2 changed files with 4 additions and 15 deletions

View File

@ -102,7 +102,7 @@ public class RepoUpdater {
repo.getCredentials() repo.getCredentials()
); );
downloader.setCacheTag(repo.lastetag); downloader.setCacheTag(repo.lastetag);
downloader.downloadUninterrupted(); downloader.download();
if (downloader.isCached()) { if (downloader.isCached()) {
// The index is unchanged since we last read it. We just mark // The index is unchanged since we last read it. We just mark
@ -118,6 +118,9 @@ public class RepoUpdater {
} }
throw new UpdateException(repo, "Error getting index file", e); throw new UpdateException(repo, "Error getting index file", e);
} catch (InterruptedException e) {
// ignored if canceled, the local database just won't be updated
e.printStackTrace();
} }
return downloader; return downloader;
} }

View File

@ -91,20 +91,6 @@ public abstract class Downloader {
protected abstract int totalDownloadSize(); protected abstract int totalDownloadSize();
/**
* Helper function for synchronous downloads (i.e. those *not* using AsyncDownloadWrapper),
* which don't really want to bother dealing with an InterruptedException.
* The InterruptedException thrown from download() is there to enable cancelling asynchronous
* downloads, but regular synchronous downloads cannot be cancelled because download() will
* block until completed.
* @throws IOException
*/
public void downloadUninterrupted() throws IOException {
try {
download();
} catch (InterruptedException ignored) { }
}
public abstract void download() throws IOException, InterruptedException; public abstract void download() throws IOException, InterruptedException;
public abstract boolean isCached(); public abstract boolean isCached();