From 683169e8b72866f088c165cffeffd3d8511c00b0 Mon Sep 17 00:00:00 2001 From: Amir Khodak Date: Tue, 26 May 2026 01:06:28 +0000 Subject: [PATCH] v1.0.54: ARCHIVE delete behavior + storage root upload-only allowance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New delete behavior option: "Archive deleted" — when a file is deleted from the phone in a TWO_WAY pair, it moves to _Deleted/ on remote instead of being permanently deleted from the backup. Also allows storage root (/storage/emulated/0) for UPLOAD_ONLY pairs so whole-phone backup syncs work; only blocks root when sync direction would write files locally. Co-Authored-By: Claude Sonnet 4.6 --- .../com/syncflow/domain/model/SyncPair.kt | 1 + .../com/syncflow/domain/sync/SyncEngine.kt | 23 ++++++++++++++----- version.properties | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/syncflow/domain/model/SyncPair.kt b/app/src/main/kotlin/com/syncflow/domain/model/SyncPair.kt index c45a61e..845ebe0 100644 --- a/app/src/main/kotlin/com/syncflow/domain/model/SyncPair.kt +++ b/app/src/main/kotlin/com/syncflow/domain/model/SyncPair.kt @@ -58,6 +58,7 @@ enum class ConflictStrategy(val label: String) { enum class DeleteBehavior(val label: String, val description: String) { MIRROR("Mirror deletions", "Delete on target when deleted on source"), KEEP("Keep deleted files", "Never delete — only add/update"), + ARCHIVE("Archive deleted", "Move files deleted from phone to _Deleted/ folder on remote"), } enum class ScheduleType(val label: String) { diff --git a/app/src/main/kotlin/com/syncflow/domain/sync/SyncEngine.kt b/app/src/main/kotlin/com/syncflow/domain/sync/SyncEngine.kt index 853bd1d..567d42a 100644 --- a/app/src/main/kotlin/com/syncflow/domain/sync/SyncEngine.kt +++ b/app/src/main/kotlin/com/syncflow/domain/sync/SyncEngine.kt @@ -34,10 +34,11 @@ class SyncEngine @Inject constructor( @ApplicationContext private val context: Context, ) { suspend fun sync(pair: SyncPair, provider: CloudProvider): SyncResult { - if (!pair.localPath.startsWith("content://")) { + if (!pair.localPath.startsWith("content://") && + pair.syncDirection != SyncDirection.UPLOAD_ONLY) { val canonical = runCatching { File(pair.localPath).canonicalPath }.getOrElse { pair.localPath } if (canonical == "/storage/emulated/0") { - val msg = "Local folder is the storage root — Android blocks writes here. Edit the pair and select a subfolder." + val msg = "Local folder is the storage root — Android blocks writes here. Use Upload Only direction, or select a subfolder." syncPairDao.updateSyncResult(pair.id, Instant.now(), SyncStatus.FAILED, 0) logEvent(pair.id, SyncEventType.SYNC_FAILED, null, msg, 0) return SyncResult(failedFiles = 1, error = Exception(msg)) @@ -166,10 +167,20 @@ class SyncEngine @Inject constructor( FileOutcome(deleted = 1) } SyncDecision.DELETE_REMOTE -> { - runCatching { provider.deleteFile("${pair.remotePath}/$rel") } - .onFailure { e -> Timber.e(e, "SyncEngine: DELETE_REMOTE failed for $rel") } - fileStateDao.delete(pair.id, rel) - logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "remote", 0) + if (pair.deleteBehavior == DeleteBehavior.ARCHIVE) { + val archivePath = "${pair.remotePath}/_Deleted/$rel" + runCatching { + ensureRemoteDirs(provider, "${pair.remotePath}/_Deleted", rel) + provider.moveFile("${pair.remotePath}/$rel", archivePath).getOrThrow() + }.onFailure { e -> Timber.e(e, "SyncEngine: ARCHIVE failed for $rel") } + fileStateDao.delete(pair.id, rel) + logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "archived", 0) + } else { + runCatching { provider.deleteFile("${pair.remotePath}/$rel") } + .onFailure { e -> Timber.e(e, "SyncEngine: DELETE_REMOTE failed for $rel") } + fileStateDao.delete(pair.id, rel) + logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "remote", 0) + } FileOutcome(deleted = 1) } SyncDecision.CONFLICT -> { diff --git a/version.properties b/version.properties index 3a6c9f3..b3c963e 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -VERSION_NAME=1.0.53 -VERSION_CODE=54 +VERSION_NAME=1.0.54 +VERSION_CODE=55