From da8b97007825c964d14d26666f986387db532627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=8B=D1=82=D0=BA=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD?= Date: Thu, 21 May 2026 11:05:04 +0300 Subject: [PATCH] =?UTF-8?q?fix(sync):=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=BB=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=B8=D0=B5=20journal=20=D0=B8=20lock=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавил readSystemFileBytesOrEmpty и подключил в Local/Yandex accessors, чтобы фоновый sync не падал с FileNotFound на пустых journal/lock. --- .../domain/vault/storages/common/SystemFileRead.kt | 12 ++++++++++++ .../vault/storages/local/LocalStorageAccessor.kt | 5 +++-- .../vault/storages/yandex/YandexStorageAccessor.kt | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/common/SystemFileRead.kt diff --git a/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/common/SystemFileRead.kt b/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/common/SystemFileRead.kt new file mode 100644 index 0000000..78f0294 --- /dev/null +++ b/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/common/SystemFileRead.kt @@ -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) + } diff --git a/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/local/LocalStorageAccessor.kt b/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/local/LocalStorageAccessor.kt index 37cc14a..b10e1c0 100644 --- a/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/local/LocalStorageAccessor.kt +++ b/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/local/LocalStorageAccessor.kt @@ -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 = 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 } diff --git a/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/yandex/YandexStorageAccessor.kt b/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/yandex/YandexStorageAccessor.kt index 4e21b7f..5e6d710 100644 --- a/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/yandex/YandexStorageAccessor.kt +++ b/domain-vault/src/main/java/com/github/nullptroma/wallenc/domain/vault/storages/yandex/YandexStorageAccessor.kt @@ -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 = 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 }