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:
parent
88b5e284b5
commit
2019b7a7c3
@ -102,7 +102,7 @@ public class RepoUpdater {
|
||||
repo.getCredentials()
|
||||
);
|
||||
downloader.setCacheTag(repo.lastetag);
|
||||
downloader.downloadUninterrupted();
|
||||
downloader.download();
|
||||
|
||||
if (downloader.isCached()) {
|
||||
// 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);
|
||||
} catch (InterruptedException e) {
|
||||
// ignored if canceled, the local database just won't be updated
|
||||
e.printStackTrace();
|
||||
}
|
||||
return downloader;
|
||||
}
|
||||
|
@ -91,20 +91,6 @@ public abstract class Downloader {
|
||||
|
||||
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 boolean isCached();
|
||||
|
Loading…
x
Reference in New Issue
Block a user