Modern Apps git

← Modern-Apps.git

notes: include note images in backups

Commit
b779366b7f4fc3f010b660ea6cf3b46bbba1f157
Author
Vayun Mathur <[email protected]>
When
2026-11-07 20:08 UTC (29 days ago)
Parents
7ce51d6
Symptom: restoring a notes backup (in-app BackupButtons export or
the Android backup agent) brought back note text but every embedded
image rendered blank, because the restored database references
files under filesDir/note_images that were never in the archive.

Root cause: both backup paths passed extraFiles = emptyList(), so
BackupHelper staged only the database. data_extraction_rules.xml
includes note_images for the OS channels, but the zip these two
paths actually write omitted it.

Fix: NoteImageStore.backupFiles() exposes the images directory as
the single extra entry; AppBackupAgent and NotesListPage pass it
(with an explicit name-to-directory restore mapping for the in-app
path), so the directory is zipped and recreated on restore.

Verification: new NoteStoresTest.backupFilesCoversImagesDir; full
notes unit-test suite run at the end of this stack.

Diff

notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt b/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.ktindex 1062ffd339..84b3440d93 100644--- a/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt+++ b/notes/src/main/java/com/vayunmathur/notes/platform/AppBackupAgent.kt@@ -12,5 +12,5 @@ class AppBackupAgent : BaseBackupAgent() {         get() = noteDbConfigs(this)      override val extraFiles: List<File>-        get() = emptyList()+        get() = NoteImageStore.backupFiles(this) }
notes/src/main/java/com/vayunmathur/notes/platform/NoteImageStore.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/NoteImageStore.kt b/notes/src/main/java/com/vayunmathur/notes/platform/NoteImageStore.ktindex cebea04e9c..1cc2d74f20 100644--- a/notes/src/main/java/com/vayunmathur/notes/platform/NoteImageStore.kt+++ b/notes/src/main/java/com/vayunmathur/notes/platform/NoteImageStore.kt@@ -26,6 +26,14 @@ object NoteImageStore {      fun fileFor(context: Context, fileName: String): File = File(dir(context), fileName) +    /**+     * Files that must travel with the notes database in a backup: the whole+     * images directory as a single entry, so restore recreates it in place.+     * Without this, a restored database references image files that were+     * never backed up and every embedded image renders blank.+     */+    fun backupFiles(context: Context): List<File> = listOf(dir(context))+     /** Copies [uri] into the images dir and returns the new file name, or null on failure. */     // Broad catch is deliberate: any content-provider failure mode means "no file"     // per this function's contract, and the failure is logged below.
notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.ktindex f6f5f317cc..6a2bc39373 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt@@ -81,7 +81,11 @@ fun NotesListPage(backStack: NavBackStack<Route>, viewModel: NotesViewModel) {             BackupButtons(                 dbConfigs = remember { noteDbConfigs(context) },                 dbCodec = SqlCipherDbCodec,-                extraFiles = emptyList()+                extraFiles = remember { com.vayunmathur.notes.platform.NoteImageStore.backupFiles(context) },+                extraFilesMapping = remember {+                    val dir = com.vayunmathur.notes.platform.NoteImageStore.backupFiles(context).single()+                    mapOf(dir.name to dir)+                }             )         },     )
notes/src/test/java/com/vayunmathur/notes/platform/NoteStoresTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/platform/NoteStoresTest.kt b/notes/src/test/java/com/vayunmathur/notes/platform/NoteStoresTest.ktindex cefa932517..c2f39c609e 100644--- a/notes/src/test/java/com/vayunmathur/notes/platform/NoteStoresTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/platform/NoteStoresTest.kt@@ -154,6 +154,13 @@ class NoteStoresTest {         assertTrue(md.contains("M 1.23 2"), md)     } +    @Test fun backupFilesCoversImagesDir() {+        writeImageFile("backed-up.jpg")+        val files = NoteImageStore.backupFiles(context)+        assertEquals(listOf(imagesDir.absolutePath), files.map { it.absolutePath })+        assertTrue(File(files.single(), "backed-up.jpg").exists())+    }+     @Test fun pruneSkipsNonLegacyKeysAndKeepsFiles() {         writeImageFile("keepme.jpg")         NoteImageStore.pruneMigratedSources(context, mapOf("keepme.jpg" to "hashed.jpg"))