[Multiple-Profile]fix: external directory not created for profile#20752
[Multiple-Profile]fix: external directory not created for profile#20752criticalAY wants to merge 2 commits intoankidroid:mainfrom
Conversation
david-allison
left a comment
There was a problem hiding this comment.
This seems incorrect, I'm not sure I understand the logic
| return super.getSharedPreferences("$prefix$name", mode) | ||
| } | ||
|
|
||
| override fun getExternalFilesDir(type: String?): File? { |
There was a problem hiding this comment.
This is unusual, we typically use PREF_COLLECTION_PATH ("deckPath")
There was a problem hiding this comment.
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)
4407f00 to
4c32e33
Compare
| val externalBase = appContext.getExternalFilesDir(null) | ||
| if (externalBase == null) { | ||
| Timber.w("External files dir unavailable; skipping deckPath init for ${profileId.value}") | ||
| return | ||
| } |
There was a problem hiding this comment.
Look into getDefaultAnkiDroidDirectory
4c32e33 to
565f336
Compare
565f336 to
11d5095
Compare
david-allison
left a comment
There was a problem hiding this comment.
Given the complexity here, let's simplify it further
| 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() } | ||
|
|
There was a problem hiding this comment.
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()
}11d5095 to
379c741
Compare
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.