Offline collection volume loses deletion retry information

Aperta
#23,381 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
backend, mobile

Direzione di ricerca

Start with ProfileManager.deleteProfile and the collection path helpers it uses, then inspect ProfileManagerTest.kt, especially the offline volume regression test described in this issue. Check how deletion failures affect profile settings and whether a retry can complete cleanup after the volume is mounted again. Done when the profile and its collection data are both removed after a failed offline deletion is retried.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Multi Profile

Assisted-by: GPT-6.1-Sol xhigh & GPT-6-Astra xhigh

[EXISTING] Offline collection volume loses deletion retry information
Subject: [EXISTING] Offline collection volume loses deletion retry information

Deleting a profile while its collection volume is unmounted removes the profile settings and leaves its cards, media, and backups behind.

⚠️ This issue existed before the PR and should likely be split off into a separate issue.
The new delete action exposes the pre-existing helper defect.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileManagerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileManagerTest.kt
index 6492405d73..e44a464313 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileManagerTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileManagerTest.kt
@@ -1187,6 +1187,44 @@ class ProfileManagerTest {
         }
     }
 
+    @Test
+    fun `an offline collection volume keeps settings until it can be deleted`() {
+        val manager = ProfileManager.create(context)
+        val work = manager.createNewProfile(ProfileName.fromTrustedSource("Work"))
+        val mount = File(appDataRoot, "removable_card").apply { mkdirs() }
+        val detached = File(appDataRoot, "detached_card")
+        val collectionDir = File(mount, "AnkiDroid").apply { mkdirs() }
+        val collection = File(collectionDir, "collection.anki2").apply { writeText("collection") }
+        val media = File(collectionDir, "collection.media/image.jpg").apply {
+            parentFile!!.mkdirs()
+            writeText("media")
+        }
+        writeProfileCollectionPath(work, collectionDir)
+        val settings = File(appDataRoot, "shared_prefs/profile_${work.value}_${context.packageName}_preferences.xml")
+        ShadowEnvironment.setExternalStorageRemovable(mount, true)
+        ShadowEnvironment.setExternalStorageState(mount, Environment.MEDIA_MOUNTED)
+        assertTrue(mount.renameTo(detached))
+        ShadowEnvironment.setExternalStorageState(mount, Environment.MEDIA_UNMOUNTED)
+        try {
+            assertEquals(Environment.MEDIA_UNMOUNTED, Environment.getExternalStorageState(collectionDir))
+            assertFalse(collectionDir.exists())
+
+            assertThrows(IOException::class.java) { manager.deleteProfile(work) }
+
+            assertTrue(manager.getAllProfiles().containsKey(work))
+            assertTrue(settings.exists())
+        } finally {
+            assertTrue(detached.renameTo(mount))
+            ShadowEnvironment.setExternalStorageState(mount, Environment.MEDIA_MOUNTED)
+        }
+
+        manager.deleteProfile(work)
+
+        assertFalse(collection.exists())
+        assertFalse(media.exists())
+        assertFalse(manager.getAllProfiles().containsKey(work))
+    }
+
     /** Stubs [CookieManager.getInstance]. [completesRemoval] fires the cookie removal callback. */
     private class RecordingEditor(
         private val delegate: SharedPreferences.Editor,

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23329#pullrequestreview-5926332571

Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
1g 11h
PR unite (30g)
383

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ankidroid/Anki-Android

Tutte le issue di ankidroid/Anki-Android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.