From 4e8549d3ce9356115bdf54715c1988c14b4e69cc Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 4 Jun 2026 10:04:07 -0300 Subject: [PATCH] [download] fix MirrorChooser always picking f-droid.org if there's no domestic mirror --- .../kotlin/org/fdroid/download/MirrorChooser.kt | 4 ++-- .../kotlin/org/fdroid/download/MirrorChooserTest.kt | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt b/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt index 042dce168..f02ad36e6 100644 --- a/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt +++ b/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt @@ -127,7 +127,7 @@ internal class MirrorChooserWithParameters( error1.compareTo(error2) } - val mirrorList: MutableList = mutableListOf() + val mirrorList: MutableList = mutableListOf() if ( mirrorParameterManager != null && mirrorParameterManager.getCurrentLocation().isNotEmpty() @@ -186,8 +186,8 @@ internal class MirrorChooserWithParameters( mirrorList.addAll(domesticList) } else { mirrorList.addAll(domesticList) - mirrorList.addAll(unknownList) mirrorList.addAll(foreignList) + mirrorList.addAll(unknownList) } return mirrorList } diff --git a/libs/download/src/commonTest/kotlin/org/fdroid/download/MirrorChooserTest.kt b/libs/download/src/commonTest/kotlin/org/fdroid/download/MirrorChooserTest.kt index 8107dc2dc..04e723e4a 100644 --- a/libs/download/src/commonTest/kotlin/org/fdroid/download/MirrorChooserTest.kt +++ b/libs/download/src/commonTest/kotlin/org/fdroid/download/MirrorChooserTest.kt @@ -9,7 +9,6 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertTrue import kotlinx.io.IOException -import org.fdroid.getIndexFile import org.fdroid.runSuspend class MirrorChooserTest { @@ -29,15 +28,13 @@ class MirrorChooserTest { ) private val downloadRequest = DownloadRequest("foo", mirrors) private val downloadRequestLocation = DownloadRequest("location", mirrorsLocation) - private val downloadRequestTryFIrst = + private val downloadRequestTryFirst = DownloadRequest( path = "location", mirrors = mirrorsLocation, tryFirstMirror = Mirror(baseUrl = "remote_1", countryCode = "THERE"), ) - private val ipfsIndexFile = getIndexFile(name = "foo", ipfsCidV1 = "CIDv1") - @Test fun testMirrorChooserDefaultImpl() = runSuspend { val mirrorChooser = MirrorChooserRandom() @@ -177,7 +174,9 @@ class MirrorChooserTest { assertEquals("HERE", domesticList[0].countryCode) assertEquals("HERE", domesticList[1].countryCode) assertEquals("HERE", domesticList[2].countryCode) - assertEquals(null, domesticList[3].countryCode) + // unknown mirrors should be last, + // because otherwise they will always be at the front if there are no domestic mirrors + assertEquals(null, domesticList.last().countryCode) } @Test @@ -229,7 +228,7 @@ class MirrorChooserTest { val mirrorChooser = MirrorChooserWithParameters(mockManager) // test tryfirst mirror parameter - val tryFirstList = mirrorChooser.orderMirrors(downloadRequestTryFIrst) + val tryFirstList = mirrorChooser.orderMirrors(downloadRequestTryFirst) // confirm the list contains all mirrors assertEquals(9, tryFirstList.size) // tryfirst mirror should be included before local mirrors