feat(sync): добавлен механизм снятия блокировки синхронизации для хранилищ

This commit is contained in:
2026-05-13 14:43:27 +03:00
parent f38b3dfbb4
commit 6c18a1d741
9 changed files with 122 additions and 2 deletions

View File

@@ -371,6 +371,14 @@ class EncryptedStorageAccessor(
}
}
override suspend fun forceClearSyncLock() {
syncLockMutex.withLock {
openWriteSystemFile(SYNC_LOCK_FILENAME).use { out ->
out.write(ByteArray(0))
}
}
}
private suspend fun appendSyncEntry(path: String, operation: StorageSyncOperation) {
val cleanedPath = if (path.startsWith("/")) path else "/$path"
val entries = readSyncJournal()

View File

@@ -669,6 +669,27 @@ class LocalStorageAccessor(
}
}
override suspend fun forceClearSyncLock() = withContext(ioDispatcher) {
val lockPath = systemLockPath()
if (!Files.exists(lockPath)) {
return@withContext
}
Files.createDirectories(lockPath.parent)
FileChannel.open(
lockPath,
StandardOpenOption.READ,
StandardOpenOption.WRITE,
).use { channel ->
val fileLock = channel.lock()
try {
channel.truncate(0)
channel.force(true)
} finally {
fileLock.release()
}
}
}
private fun systemLockPath(): Path =
_filesystemBasePath.resolve(SYSTEM_HIDDEN_DIRNAME).resolve(SYNC_LOCK_FILENAME)

View File

@@ -636,6 +636,14 @@ class YandexStorageAccessor(
}
}
override suspend fun forceClearSyncLock() = withContext(ioDispatcher) {
syncLockMutex.withLock {
openWriteSystemFile(SYNC_LOCK_FILENAME).use { out ->
out.write(ByteArray(0))
}
}
}
private suspend fun appendSyncEntry(path: String, operation: StorageSyncOperation) {
val cleanedPath = if (path.startsWith("/")) path else "/$path"
val entries = readSyncJournal()