From 1931024a1001b7bbb0d79157168b5a4d086d1887 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 3 May 2024 16:09:18 -0300 Subject: [PATCH] Introduce constant for files snapshot file extension --- .../plugins/saf/DocumentsProviderStoragePlugin.kt | 3 ++- .../seedvault/plugins/webdav/WebDavStoragePlugin.kt | 3 ++- .../stevesoltys/seedvault/storage/WebDavStoragePlugin.kt | 9 +++++---- .../org/calyxos/backup/storage/plugin/PluginConstants.kt | 1 + .../backup/storage/plugin/saf/SafStoragePlugin.kt | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsProviderStoragePlugin.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsProviderStoragePlugin.kt index e1d88f54..691921d8 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsProviderStoragePlugin.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/saf/DocumentsProviderStoragePlugin.kt @@ -10,6 +10,7 @@ import com.stevesoltys.seedvault.plugins.EncryptedMetadata import com.stevesoltys.seedvault.plugins.StoragePlugin import com.stevesoltys.seedvault.plugins.chunkFolderRegex import com.stevesoltys.seedvault.plugins.tokenRegex +import org.calyxos.backup.storage.plugin.PluginConstants.SNAPSHOT_EXT import java.io.FileNotFoundException import java.io.IOException import java.io.InputStream @@ -149,5 +150,5 @@ private fun DocumentFile.getTokenOrNull(name: String?): Long? { private fun isUnexpectedFile(name: String): Boolean { return name != FILE_NO_MEDIA && !chunkFolderRegex.matches(name) && - !name.endsWith(".SeedSnap") + !name.endsWith(SNAPSHOT_EXT) } diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt index 0d9986cd..f88e2d95 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt @@ -14,6 +14,7 @@ import com.stevesoltys.seedvault.plugins.saf.FILE_BACKUP_METADATA import com.stevesoltys.seedvault.plugins.saf.FILE_NO_MEDIA import com.stevesoltys.seedvault.plugins.tokenRegex import okhttp3.HttpUrl.Companion.toHttpUrl +import org.calyxos.backup.storage.plugin.PluginConstants.SNAPSHOT_EXT import java.io.IOException import java.io.InputStream import java.io.OutputStream @@ -191,7 +192,7 @@ internal class WebDavStoragePlugin( private fun isUnexpectedFile(name: String): Boolean { return name != FILE_NO_MEDIA && !chunkFolderRegex.matches(name) && - !name.endsWith(".SeedSnap") + !name.endsWith(SNAPSHOT_EXT) } override val providerPackageName: String = context.packageName // 100% built-in plugin diff --git a/app/src/main/java/com/stevesoltys/seedvault/storage/WebDavStoragePlugin.kt b/app/src/main/java/com/stevesoltys/seedvault/storage/WebDavStoragePlugin.kt index 09695860..b7bdcc05 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/storage/WebDavStoragePlugin.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/storage/WebDavStoragePlugin.kt @@ -14,6 +14,7 @@ import com.stevesoltys.seedvault.plugins.webdav.WebDavStorage import okhttp3.HttpUrl.Companion.toHttpUrl import org.calyxos.backup.storage.api.StoragePlugin import org.calyxos.backup.storage.api.StoredSnapshot +import org.calyxos.backup.storage.plugin.PluginConstants.SNAPSHOT_EXT import org.calyxos.backup.storage.plugin.PluginConstants.chunkRegex import org.calyxos.backup.storage.plugin.PluginConstants.snapshotRegex import org.koin.core.time.measureDuration @@ -136,13 +137,13 @@ internal class WebDavStoragePlugin( @Throws(IOException::class) override suspend fun getBackupSnapshotOutputStream(timestamp: Long): OutputStream { - val location = "$url/$folder/$timestamp.SeedSnap".toHttpUrl() + val location = "$url/$folder/$timestamp$SNAPSHOT_EXT".toHttpUrl() debugLog { "getBackupSnapshotOutputStream($location)" } return try { getOutputStream(location) } catch (e: Exception) { if (e is IOException) throw e - else throw IOException("Error getting OutputStream for $timestamp.SeedSnap: ", e) + else throw IOException("Error getting OutputStream for $timestamp$SNAPSHOT_EXT: ", e) } } @@ -184,7 +185,7 @@ internal class WebDavStoragePlugin( @Throws(IOException::class) override suspend fun getBackupSnapshotInputStream(storedSnapshot: StoredSnapshot): InputStream { val timestamp = storedSnapshot.timestamp - val location = "$url/${storedSnapshot.userId}/$timestamp.SeedSnap".toHttpUrl() + val location = "$url/${storedSnapshot.userId}/$timestamp$SNAPSHOT_EXT".toHttpUrl() debugLog { "getBackupSnapshotInputStream($location)" } return try { getInputStream(location) @@ -251,7 +252,7 @@ internal class WebDavStoragePlugin( val timestamp = storedSnapshot.timestamp Log.d(TAG, "Deleting snapshot $timestamp") - val location = "$url/${storedSnapshot.userId}/$timestamp.SeedSnap".toHttpUrl() + val location = "$url/${storedSnapshot.userId}/$timestamp$SNAPSHOT_EXT".toHttpUrl() val davCollection = DavCollection(okHttpClient, location) try { diff --git a/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/PluginConstants.kt b/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/PluginConstants.kt index 6ce71fb9..98db4974 100644 --- a/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/PluginConstants.kt +++ b/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/PluginConstants.kt @@ -7,6 +7,7 @@ package org.calyxos.backup.storage.plugin public object PluginConstants { + public const val SNAPSHOT_EXT: String = ".SeedSnap" public val folderRegex: Regex = Regex("^[a-f0-9]{16}\\.sv$") public val chunkFolderRegex: Regex = Regex("[a-f0-9]{2}") public val chunkRegex: Regex = Regex("[a-f0-9]{64}") diff --git a/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/saf/SafStoragePlugin.kt b/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/saf/SafStoragePlugin.kt index 7b790578..1d152f01 100644 --- a/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/saf/SafStoragePlugin.kt +++ b/storage/lib/src/main/java/org/calyxos/backup/storage/plugin/saf/SafStoragePlugin.kt @@ -16,6 +16,7 @@ import org.calyxos.backup.storage.api.StoredSnapshot import org.calyxos.backup.storage.measure import org.calyxos.backup.storage.plugin.PluginConstants.CHUNK_FOLDER_COUNT import org.calyxos.backup.storage.plugin.PluginConstants.MIME_TYPE +import org.calyxos.backup.storage.plugin.PluginConstants.SNAPSHOT_EXT import org.calyxos.backup.storage.plugin.PluginConstants.chunkFolderRegex import org.calyxos.backup.storage.plugin.PluginConstants.chunkRegex import org.calyxos.backup.storage.plugin.PluginConstants.folderRegex @@ -72,7 +73,7 @@ public abstract class SafStoragePlugin( } private fun timestampToSnapshot(timestamp: Long): String { - return "$timestamp.SeedSnap" + return "$timestamp$SNAPSHOT_EXT" } override suspend fun init() {