Skip to content

Commit

Permalink
Introduce constant for files snapshot file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed May 3, 2024
1 parent 2f6edf6 commit 1931024
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1931024

Please sign in to comment.