clarify get mirrors method: Repo.getRandomMirror()
This commit is contained in:
parent
cf9a6b851d
commit
89422e9c8f
@ -263,7 +263,7 @@ public class FDroidApp extends Application {
|
|||||||
*
|
*
|
||||||
* @see #resetMirrorVars()
|
* @see #resetMirrorVars()
|
||||||
* @see #getTimeout()
|
* @see #getTimeout()
|
||||||
* @see Repo#getMirror(String)
|
* @see Repo#getRandomMirror(String)
|
||||||
*/
|
*/
|
||||||
public static String getMirror(String urlString, Repo repo2) throws IOException {
|
public static String getMirror(String urlString, Repo repo2) throws IOException {
|
||||||
if (repo2.hasMirrors()) {
|
if (repo2.hasMirrors()) {
|
||||||
@ -286,7 +286,7 @@ public class FDroidApp extends Application {
|
|||||||
if (numTries == Integer.MAX_VALUE) {
|
if (numTries == Integer.MAX_VALUE) {
|
||||||
numTries = repo2.getMirrorCount();
|
numTries = repo2.getMirrorCount();
|
||||||
}
|
}
|
||||||
String mirror = repo2.getMirror(lastWorkingMirror);
|
String mirror = repo2.getRandomMirror(lastWorkingMirror);
|
||||||
String newUrl = urlString.replace(lastWorkingMirror, mirror);
|
String newUrl = urlString.replace(lastWorkingMirror, mirror);
|
||||||
Utils.debugLog(TAG, "Trying mirror " + mirror + " after " + lastWorkingMirror + " failed," +
|
Utils.debugLog(TAG, "Trying mirror " + mirror + " after " + lastWorkingMirror + " failed," +
|
||||||
" timeout=" + timeout / 1000 + "s");
|
" timeout=" + timeout / 1000 + "s");
|
||||||
|
@ -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.
|
||||||
|
* <p>
|
||||||
* The mirror logic assumes that it has a mirrors list with at least once
|
* 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},
|
* 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
|
* 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.
|
* if there is only one item in the mirrors list, there are no other URLs to try.
|
||||||
* <p>
|
* <p>
|
||||||
* 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
|
* 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
|
* update. That makes it possible to do the first index update via SD Card
|
||||||
* or USB OTG drive.
|
* or USB OTG drive.
|
||||||
@ -394,16 +398,16 @@ public class Repo extends ValueObject {
|
|||||||
* @see FDroidApp#getMirror(String, Repo)
|
* @see FDroidApp#getMirror(String, Repo)
|
||||||
* @see FDroidApp#getTimeout()
|
* @see FDroidApp#getTimeout()
|
||||||
*/
|
*/
|
||||||
public String getMirror(String lastWorkingMirror) {
|
public String getRandomMirror(String mirrorToSkip) {
|
||||||
if (TextUtils.isEmpty(lastWorkingMirror)) {
|
if (TextUtils.isEmpty(mirrorToSkip)) {
|
||||||
lastWorkingMirror = address;
|
mirrorToSkip = address;
|
||||||
}
|
}
|
||||||
List<String> shuffledMirrors = getMirrorList();
|
List<String> shuffledMirrors = getMirrorList();
|
||||||
Collections.shuffle(shuffledMirrors);
|
|
||||||
if (shuffledMirrors.size() > 1) {
|
if (shuffledMirrors.size() > 1) {
|
||||||
|
Collections.shuffle(shuffledMirrors);
|
||||||
for (String m : shuffledMirrors) {
|
for (String m : shuffledMirrors) {
|
||||||
// Return a non default, and not last used mirror
|
// Return a non default, and not last used mirror
|
||||||
if (!m.equals(lastWorkingMirror)) {
|
if (!m.equals(mirrorToSkip)) {
|
||||||
if (FDroidApp.isUsingTor()) {
|
if (FDroidApp.isUsingTor()) {
|
||||||
return m;
|
return m;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user