Unreadable collection loses deletion retry information

Open
#23,379 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with ProfileManagerTest.kt, especially the profile deletion tests and the unreadable collection case shown in the issue. Trace the deletion helper that lists the collection directory and check how it handles listing failures. Done means deletion preserves the profile and its settings when the collection cannot be read, with a regression test covering the retry case.

Written by the indexing model from the issue text.

Description

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

[EXISTING] Unreadable collection loses deletion retry information
Subject: [EXISTING] Unreadable collection loses deletion retry information

When a collection directory cannot be listed, deletion removes its profile and settings while leaving its data 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 3297d2a617..8aa9575f84 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileManagerTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileManagerTest.kt
@@ -1124,6 +1124,27 @@ class ProfileManagerTest {
         assertTrue("Unrecognized collection exports must survive profile deletion", otherCollection.exists())
     }
 
+    @Test
+    fun `an unreadable collection keeps the profile and its settings for retry`() {
+        val manager = ProfileManager.create(context)
+        val work = manager.createNewProfile(ProfileName.fromTrustedSource("Work"))
+        val collectionDir = File(context.getExternalFilesDir(null), "unreadable_collection").apply { mkdirs() }
+        File(collectionDir, "collection.anki2").writeText("collection")
+        writeProfileCollectionPath(work, collectionDir)
+        val settings = File(appDataRoot, "shared_prefs/profile_${work.value}_${context.packageName}_preferences.xml")
+        org.junit.Assume.assumeTrue(collectionDir.setReadable(false, false))
+        try {
+            org.junit.Assume.assumeFalse("The test runner must respect directory permissions", collectionDir.canRead())
+
+            assertThrows(IOException::class.java) { manager.deleteProfile(work) }
+
+            assertTrue(manager.getAllProfiles().containsKey(work))
+            assertTrue(settings.exists())
+        } finally {
+            collectionDir.setReadable(true, true)
+        }
+    }
+
     /** 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

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
1d 11h
Merged PRs (30d)
383

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.