Skip to content

[Multiple-Profile]fix: external directory not created for profile#20752

Open
criticalAY wants to merge 2 commits intoankidroid:mainfrom
criticalAY:mp/fix-external-dir
Open

[Multiple-Profile]fix: external directory not created for profile#20752
criticalAY wants to merge 2 commits intoankidroid:mainfrom
criticalAY:mp/fix-external-dir

Conversation

@criticalAY
Copy link
Copy Markdown
Contributor

Purpose / Description

Fixes a VERY BIG BLUNDER that I did earlier, I overlooked external dir. but thanks to @david-allison I figured this one, apart from deletion the addition logic was also missing

Fixes

Approach

See commit

How Has This Been Tested?

Unit test to verify that directory was created

Learning (optional, can help others)

Always doc first

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@criticalAY criticalAY changed the title [Multi-Profile]fix: external directory not created for profile [Multiple-Profile]fix: external directory not created for profile Apr 15, 2026
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect, I'm not sure I understand the logic

return super.getSharedPreferences("$prefix$name", mode)
}

override fun getExternalFilesDir(type: String?): File? {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unusual, we typically use PREF_COLLECTION_PATH ("deckPath")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I was doing the job indirectly in a pretty fragile ( the actual collection location isnt read from getExternalFilesDir() which I assumed. i.e. PREF_COLLECTION_PATH <- Read from here)

@criticalAY criticalAY force-pushed the mp/fix-external-dir branch 3 times, most recently from 4407f00 to 4c32e33 Compare April 17, 2026 22:13
Comment on lines +201 to +205
val externalBase = appContext.getExternalFilesDir(null)
if (externalBase == null) {
Timber.w("External files dir unavailable; skipping deckPath init for ${profileId.value}")
return
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look into getDefaultAnkiDroidDirectory

@criticalAY criticalAY force-pushed the mp/fix-external-dir branch from 4c32e33 to 565f336 Compare April 18, 2026 21:18
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/multiprofile/ProfileManager.kt Outdated
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the complexity here, let's simplify it further

Comment on lines +210 to +216
val defaultAnkiDroidDir = getDefaultAnkiDroidDirectory(appContext)
val externalBase =
defaultAnkiDroidDir.parentFile
?: error("getDefaultAnkiDroidDirectory returned a path with no parent: $defaultAnkiDroidDir")

val profileCollectionDir = File(externalBase, profileId.value).apply { mkdirs() }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the complexity, but I feel it should be moved inside getDefaultAnkiDroidDirectory

ideally some of the complexity can be fixed inside the method call

        val ankiDroidDir = getDefaultAnkiDroidDirectory(appContext, directoryName = profileId.value).apply {
            mkdirs()
        }

@criticalAY criticalAY force-pushed the mp/fix-external-dir branch from 11d5095 to 379c741 Compare April 21, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants