use of org.fdroid.fdroid.net.Downloader in project fdroidclient by f-droid.
the class IndexUpdater method update.
/**
* All repos are represented by a signed jar file, {@code index.jar}, which contains
* a single file, {@code index.xml}. This takes the {@code index.jar}, verifies the
* signature, then returns the unzipped {@code index.xml}.
*
* @return whether this version of the repo index was found and processed
* @throws UpdateException All error states will come from here.
*/
public boolean update() throws UpdateException {
final Downloader downloader = downloadIndex();
hasChanged = downloader.hasChanged();
if (hasChanged) {
// Don't worry about checking the status code for 200. If it was a
// successful download, then we will have a file ready to use:
cacheTag = downloader.getCacheTag();
processDownloadedFile(downloader.outputFile);
processRepoPushRequests(repoPushRequestList);
}
return true;
}
use of org.fdroid.fdroid.net.Downloader in project fdroidclient by f-droid.
the class RepoUpdater method downloadIndex.
private Downloader downloadIndex() throws UpdateException {
Downloader downloader = null;
try {
downloader = DownloaderFactory.create(context, indexUrl);
downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener);
downloader.download();
} catch (IOException e) {
if (downloader != null && downloader.outputFile != null) {
if (!downloader.outputFile.delete()) {
Log.w(TAG, "Couldn't delete file: " + downloader.outputFile.getAbsolutePath());
}
}
throw new UpdateException("Error getting index file", e);
} catch (InterruptedException e) {
// ignored if canceled, the local database just won't be updated
e.printStackTrace();
}
return downloader;
}
use of org.fdroid.fdroid.net.Downloader in project fdroidclient by f-droid.
the class RepoUpdater method update.
/**
* All repos are represented by a signed jar file, {@code index.jar}, which contains
* a single file, {@code index.xml}. This takes the {@code index.jar}, verifies the
* signature, then returns the unzipped {@code index.xml}.
*
* @return whether this version of the repo index was found and processed
* @throws UpdateException All error states will come from here.
*/
public boolean update() throws UpdateException {
final Downloader downloader = downloadIndex();
hasChanged = downloader.hasChanged();
if (hasChanged) {
// Don't worry about checking the status code for 200. If it was a
// successful download, then we will have a file ready to use:
cacheTag = downloader.getCacheTag();
processDownloadedFile(downloader.outputFile);
processRepoPushRequests();
}
return true;
}
use of org.fdroid.fdroid.net.Downloader in project fdroidclient by f-droid.
the class IndexV1Updater method update.
/**
* @return whether this successfully found an index of this version
* @throws IndexUpdater.UpdateException
* @see org.fdroid.fdroid.net.DownloaderService#handleIntent(android.content.Intent)
*/
@Override
public boolean update() throws IndexUpdater.UpdateException {
if (repo.isSwap) {
// swap repos do not support index-v1
return false;
}
Downloader downloader = null;
try {
// read file name from file
downloader = DownloaderFactory.create(context, indexUrl);
downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener);
downloader.download();
if (downloader.isNotFound()) {
return false;
}
hasChanged = downloader.hasChanged();
if (!hasChanged) {
return true;
}
processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e) {
// if the above list changes, also change below and in DownloaderService.handleIntent()
Utils.debugLog(TAG, "Trying to download the index from a mirror: " + e.getMessage());
// Mirror logic here, so that the default download code is untouched.
String mirrorUrl;
String prevMirrorUrl = indexUrl;
FDroidApp.resetMirrorVars();
// 3 is the number of timeouts we have. 10s, 30s & 60s
int n = repo.getMirrorCount() * 3;
for (int i = 0; i <= n; i++) {
try {
mirrorUrl = FDroidApp.getNewMirrorOnError(prevMirrorUrl, repo);
prevMirrorUrl = mirrorUrl;
downloader = DownloaderFactory.create(context, mirrorUrl);
downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener);
downloader.setTimeout(FDroidApp.getTimeout());
downloader.download();
if (downloader.isNotFound()) {
return false;
}
hasChanged = downloader.hasChanged();
if (!hasChanged) {
return true;
}
processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
break;
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e2) {
// We'll just let this try the next mirror
Utils.debugLog(TAG, "Trying next mirror");
} catch (IOException e2) {
if (downloader != null) {
FileUtils.deleteQuietly(downloader.outputFile);
}
throw new IndexUpdater.UpdateException(repo, "Error getting F-Droid index file", e2);
} catch (InterruptedException e2) {
// ignored if canceled, the local database just won't be updated
}
}
} catch (IOException e) {
if (downloader != null) {
FileUtils.deleteQuietly(downloader.outputFile);
}
throw new IndexUpdater.UpdateException(repo, "Error getting F-Droid index file", e);
} catch (InterruptedException e) {
// ignored if canceled, the local database just won't be updated
}
return true;
}
use of org.fdroid.fdroid.net.Downloader in project fdroidclient by f-droid.
the class IndexUpdater method downloadIndex.
private Downloader downloadIndex() throws UpdateException {
Downloader downloader = null;
try {
downloader = DownloaderFactory.create(context, indexUrl);
downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener);
downloader.download();
} catch (IOException e) {
if (downloader != null && downloader.outputFile != null) {
if (!downloader.outputFile.delete()) {
Log.w(TAG, "Couldn't delete file: " + downloader.outputFile.getAbsolutePath());
}
}
throw new UpdateException(repo, "Error getting F-Droid index file", e);
} catch (InterruptedException e) {
// ignored if canceled, the local database just won't be updated
e.printStackTrace();
}
return downloader;
}
Aggregations