Introduce constant for files snapshot file extension

This commit is contained in:
Torsten Grote 2024-05-03 16:09:18 -03:00
parent 2f6edf6b4b
commit 1931024a10
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
5 changed files with 12 additions and 7 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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 {

View file

@ -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}")

View file

@ -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() {