feat(sync): добавлен механизм снятия блокировки синхронизации для хранилищ
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user