fix(sync): обработал отсутствие journal и lock при синхронизации
Добавил readSystemFileBytesOrEmpty и подключил в Local/Yandex accessors, чтобы фоновый sync не падал с FileNotFound на пустых journal/lock.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.github.nullptroma.wallenc.domain.vault.storages.common
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.errors.WallencException
|
||||
import java.io.InputStream
|
||||
|
||||
/** Читает системный файл; отсутствие файла — пустой массив байт (не исключение). */
|
||||
internal suspend fun readSystemFileBytesOrEmpty(open: suspend () -> InputStream): ByteArray =
|
||||
try {
|
||||
open().use { it.readBytes() }
|
||||
} catch (_: WallencException.Storage.FileNotFound) {
|
||||
ByteArray(0)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.nullptroma.wallenc.domain.vault.storages.local
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.errors.WallencException
|
||||
import com.github.nullptroma.wallenc.domain.vault.storages.common.readSystemFileBytesOrEmpty
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
@@ -572,7 +573,7 @@ class LocalStorageAccessor(
|
||||
}
|
||||
|
||||
override suspend fun readSyncJournal(): List<StorageSyncJournalEntry> = withContext(ioDispatcher) {
|
||||
val bytes = openReadSystemFile(SYNC_JOURNAL_FILENAME).use { it.readBytes() }
|
||||
val bytes = readSystemFileBytesOrEmpty { openReadSystemFile(SYNC_JOURNAL_FILENAME) }
|
||||
if (bytes.isEmpty()) {
|
||||
return@withContext emptyList()
|
||||
}
|
||||
@@ -602,7 +603,7 @@ class LocalStorageAccessor(
|
||||
}
|
||||
|
||||
override suspend fun readSyncLock(): StorageSyncLock? = withContext(ioDispatcher) {
|
||||
val bytes = openReadSystemFile(SYNC_LOCK_FILENAME).use { it.readBytes() }
|
||||
val bytes = readSystemFileBytesOrEmpty { openReadSystemFile(SYNC_LOCK_FILENAME) }
|
||||
if (bytes.isEmpty()) {
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.github.nullptroma.wallenc.domain.vault.storages.yandex
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.errors.WallencException
|
||||
import com.github.nullptroma.wallenc.domain.vault.errors.toVaultWallencException
|
||||
import com.github.nullptroma.wallenc.domain.vault.storages.common.readSystemFileBytesOrEmpty
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.YandexDiskAuthException
|
||||
@@ -597,7 +598,7 @@ class YandexStorageAccessor(
|
||||
}
|
||||
|
||||
override suspend fun readSyncJournal(): List<StorageSyncJournalEntry> = withContext(ioDispatcher) {
|
||||
val bytes = openReadSystemFile(SYNC_JOURNAL_FILENAME).use { it.readBytes() }
|
||||
val bytes = readSystemFileBytesOrEmpty { openReadSystemFile(SYNC_JOURNAL_FILENAME) }
|
||||
if (bytes.isEmpty()) {
|
||||
return@withContext emptyList()
|
||||
}
|
||||
@@ -631,7 +632,7 @@ class YandexStorageAccessor(
|
||||
}
|
||||
|
||||
override suspend fun readSyncLock(): StorageSyncLock? = withContext(ioDispatcher) {
|
||||
val bytes = openReadSystemFile(SYNC_LOCK_FILENAME).use { it.readBytes() }
|
||||
val bytes = readSystemFileBytesOrEmpty { openReadSystemFile(SYNC_LOCK_FILENAME) }
|
||||
if (bytes.isEmpty()) {
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user