-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix database corruption dialog #19692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lukstbit
merged 2 commits into
ankidroid:main
from
Alex7D3:fix/database-corruption-dialog
Feb 10, 2026
+109
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+67.4 KB
AnkiDroid/src/androidTest/assets/initial_version_2_12_1_corrupt_regular.anki2
Binary file not shown.
95 changes: 95 additions & 0 deletions
95
AnkiDroid/src/androidTest/java/com/ichi2/anki/dialogs/DatabaseCorruptDialogTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Copyright (c) 2025 Alex Odorico <alex.odorico03@gmail.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| * details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.ichi2.anki.dialogs | ||
|
|
||
| import androidx.test.core.app.ActivityScenario | ||
| import androidx.test.espresso.Espresso.onView | ||
| import androidx.test.espresso.assertion.ViewAssertions.matches | ||
| import androidx.test.espresso.matcher.RootMatchers.isDialog | ||
| import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
| import androidx.test.espresso.matcher.ViewMatchers.withText | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.ichi2.anki.CollectionHelper.getCurrentAnkiDroidDirectory | ||
| import com.ichi2.anki.CollectionManager | ||
| import com.ichi2.anki.DeckPicker | ||
| import com.ichi2.anki.R | ||
| import com.ichi2.anki.tests.InstrumentedTest | ||
| import com.ichi2.anki.tests.Shared | ||
| import com.ichi2.anki.testutil.discardPreliminaryViews | ||
| import org.junit.After | ||
| import org.junit.Assert | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import timber.log.Timber | ||
| import java.io.File | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class DatabaseCorruptDialogTest : InstrumentedTest() { | ||
| private lateinit var targetColFile: File | ||
| private lateinit var corruptColFile: File | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| val dbDir = getCurrentAnkiDroidDirectory(testContext) | ||
| targetColFile = | ||
| File(dbDir, "collection.anki2").apply { | ||
| mkdirs() | ||
| deleteOnExit() | ||
| } | ||
| corruptColFile = Shared.getTestFile(testContext, "initial_version_2_12_1_corrupt_regular.anki2") | ||
|
|
||
| corruptColFile.copyTo(targetColFile, overwrite = true) | ||
| Timber.i("Copied %d bytes to target", targetColFile.length()) | ||
|
|
||
| ActivityScenario.launch(DeckPicker::class.java) | ||
| discardPreliminaryViews() | ||
| } | ||
|
|
||
| @Test | ||
| fun testCorruptDialogFlagSet() { | ||
| Assert.assertTrue(DatabaseErrorDialog.databaseCorruptFlag) | ||
| } | ||
|
|
||
| @Test | ||
| fun testOpenCollectionFailedDialog() { | ||
| onView(withText(R.string.open_collection_failed_title)) | ||
| .inRoot(isDialog()) | ||
| .check(matches(isDisplayed())) | ||
| } | ||
|
|
||
| @Test | ||
| fun testCorruptCollectionDialog() { | ||
| val corruptMsg = | ||
| testContext.getString( | ||
| R.string.corrupt_db_message, | ||
| testContext.getString(R.string.repair_deck), | ||
| ) | ||
| onView(withText(corruptMsg)) | ||
| .inRoot(isDialog()) | ||
| .check(matches(isDisplayed())) | ||
| } | ||
|
|
||
| @After | ||
| fun cleanupCorruptColFile() { | ||
| CollectionManager.closeCollectionBlocking() | ||
| if (!targetColFile.delete()) { | ||
| Timber.e("Cleanup: Failed to delete %s", targetColFile.path) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.