Search in sources :

Example 1 with Downloader

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;
}
Also used : Downloader(org.fdroid.fdroid.net.Downloader)

Example 2 with Downloader

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;
}
Also used : Downloader(org.fdroid.fdroid.net.Downloader) IOException(java.io.IOException)

Example 3 with 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;
}
Also used : Downloader(org.fdroid.fdroid.net.Downloader)

Example 4 with Downloader

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;
}
Also used : SSLProtocolException(javax.net.ssl.SSLProtocolException) ProtocolException(java.net.ProtocolException) UnknownHostException(java.net.UnknownHostException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) Downloader(org.fdroid.fdroid.net.Downloader) IOException(java.io.IOException) SSLKeyException(javax.net.ssl.SSLKeyException) HttpRetryException(java.net.HttpRetryException) NoRouteToHostException(java.net.NoRouteToHostException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLProtocolException(javax.net.ssl.SSLProtocolException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException)

Example 5 with Downloader

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;
}
Also used : Downloader(org.fdroid.fdroid.net.Downloader) IOException(java.io.IOException)

Aggregations

Downloader (org.fdroid.fdroid.net.Downloader)5 IOException (java.io.IOException)3 ConnectException (java.net.ConnectException)1 HttpRetryException (java.net.HttpRetryException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 ProtocolException (java.net.ProtocolException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 SSLKeyException (javax.net.ssl.SSLKeyException)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 SSLProtocolException (javax.net.ssl.SSLProtocolException)1