diff --git a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java index 1f3ec670b..c828876e2 100644 --- a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java +++ b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java @@ -263,7 +263,7 @@ public class FDroidApp extends Application { * * @see #resetMirrorVars() * @see #getTimeout() - * @see Repo#getMirror(String) + * @see Repo#getRandomMirror(String) */ public static String getMirror(String urlString, Repo repo2) throws IOException { if (repo2.hasMirrors()) { @@ -286,7 +286,7 @@ public class FDroidApp extends Application { if (numTries == Integer.MAX_VALUE) { numTries = repo2.getMirrorCount(); } - String mirror = repo2.getMirror(lastWorkingMirror); + String mirror = repo2.getRandomMirror(lastWorkingMirror); String newUrl = urlString.replace(lastWorkingMirror, mirror); Utils.debugLog(TAG, "Trying mirror " + mirror + " after " + lastWorkingMirror + " failed," + " timeout=" + timeout / 1000 + "s"); diff --git a/app/src/main/java/org/fdroid/fdroid/data/Repo.java b/app/src/main/java/org/fdroid/fdroid/data/Repo.java index 43fbe65e8..1333adc7c 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/Repo.java +++ b/app/src/main/java/org/fdroid/fdroid/data/Repo.java @@ -380,12 +380,16 @@ public class Repo extends ValueObject { } /** + * Get a random mirror URL from the list of mirrors for this repo. It will + * remove the URL in {@code mirrorToSkip} from consideration before choosing + * which mirror to return. + *
* The mirror logic assumes that it has a mirrors list with at least once * valid entry in it. In the index format as defined by {@code fdroid update}, * there is always at least one valid URL: the canonical URL. That also means * if there is only one item in the mirrors list, there are no other URLs to try. *
- * The initial state of the repos in the database also include the canonical
+ * The initial state of the repos in the database also includes the canonical
* URL in the mirrors list so the mirror logic works on the first index
* update. That makes it possible to do the first index update via SD Card
* or USB OTG drive.
@@ -394,16 +398,16 @@ public class Repo extends ValueObject {
* @see FDroidApp#getMirror(String, Repo)
* @see FDroidApp#getTimeout()
*/
- public String getMirror(String lastWorkingMirror) {
- if (TextUtils.isEmpty(lastWorkingMirror)) {
- lastWorkingMirror = address;
+ public String getRandomMirror(String mirrorToSkip) {
+ if (TextUtils.isEmpty(mirrorToSkip)) {
+ mirrorToSkip = address;
}
List