Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

private const val SNAPSHOT_PACKAGE_NAME_PREFIX = "com.ai.assistance.operit"

internal fun isSupportedSnapshotPackageName(packageName: String): Boolean =
packageName.startsWith(SNAPSHOT_PACKAGE_NAME_PREFIX)

object RawSnapshotBackupManager {

private const val TAG = "RawSnapshotBackup"
Expand Down Expand Up @@ -288,7 +293,7 @@ object RawSnapshotBackupManager {
AppLogger.i(TAG, "restore closed databases (room + objectbox)")

withContext(Dispatchers.Main) { onProgress?.invoke(RestoreProgress.EXTRACTING) }
val manifest = extractZipToWorkDir(cacheZip, workDir, expectedPackageName = context.packageName)
val manifest = extractZipToWorkDir(cacheZip, workDir)

val payloadDir = File(workDir, "payload")
val externalFilesPayloadDir = File(payloadDir, "external_files")
Expand Down Expand Up @@ -343,7 +348,7 @@ object RawSnapshotBackupManager {
}
}

private fun extractZipToWorkDir(zipFile: File, workDir: File, expectedPackageName: String): Manifest {
private fun extractZipToWorkDir(zipFile: File, workDir: File): Manifest {
val payloadRoot = File(workDir, "payload")
payloadRoot.mkdirs()

Expand Down Expand Up @@ -407,7 +412,7 @@ object RawSnapshotBackupManager {
throw IllegalArgumentException("Unsupported backup version: ${manifest.formatVersion}")
}

if (manifest.packageName != expectedPackageName) {
if (!isSupportedSnapshotPackageName(manifest.packageName)) {
throw IllegalArgumentException("Backup package mismatch: ${manifest.packageName}")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ai.assistance.operit.data.backup

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class RawSnapshotBackupManagerTest {

@Test
fun snapshotPackageName_acceptsOperitPackagePrefix() {
assertTrue(isSupportedSnapshotPackageName("com.ai.assistance.operit"))
assertTrue(isSupportedSnapshotPackageName("com.ai.assistance.operit.debug"))
assertTrue(isSupportedSnapshotPackageName("com.ai.assistance.operit.clone"))
}

@Test
fun snapshotPackageName_rejectsDifferentPackagePrefix() {
assertFalse(isSupportedSnapshotPackageName("com.ai.assistance.other"))
assertFalse(isSupportedSnapshotPackageName("com.example.operit"))
}
}