v1.0.29: fix sync loop, stale-state auto-heal, icon redesign
- SyncEngine: self-healing stale folder state detection (isRetry) wipes orphaned SyncFileStateEntity records when localPath changes without a pair re-save — prevents repeated DELETE_REMOTE on 32 old files - SyncEngine: second-precision mtime comparison (/ 1000 / .epochSecond) eliminates phantom localChanged=true from FAT32/WebDAV precision mismatch - FileWatchService: syncCooldownUntil map suppresses FileObserver events for 120s after sync starts and 60s after it finishes, breaking the download→FileObserver→sync→download feedback loop - Icon: three bold teardrop shapes (teal/red/amber) rotated 0/120/240° on dark charcoal background with white cloud at intersection Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -62,13 +62,28 @@ class SyncEngine @Inject constructor(
|
|||||||
else
|
else
|
||||||
LocalAccessor.JavaFile(File(localPath))
|
LocalAccessor.JavaFile(File(localPath))
|
||||||
|
|
||||||
private suspend fun performSync(pair: SyncPair, provider: CloudProvider): SyncResult {
|
private suspend fun performSync(
|
||||||
|
pair: SyncPair,
|
||||||
|
provider: CloudProvider,
|
||||||
|
isRetry: Boolean = false,
|
||||||
|
): SyncResult {
|
||||||
val accessor = makeAccessor(pair.localPath)
|
val accessor = makeAccessor(pair.localPath)
|
||||||
val knownStates = fileStateDao.getForPair(pair.id).associateBy { it.relativePath }
|
var knownStates = fileStateDao.getForPair(pair.id).associateBy { it.relativePath }
|
||||||
val remoteFiles = provider.listFiles(pair.remotePath).getOrThrow()
|
val remoteFiles = provider.listFiles(pair.remotePath).getOrThrow()
|
||||||
.associateBy { it.path.removePrefix(pair.remotePath).trimStart('/') }
|
.associateBy { it.path.removePrefix(pair.remotePath).trimStart('/') }
|
||||||
val localFiles = accessor.walkFiles(pair)
|
val localFiles = accessor.walkFiles(pair)
|
||||||
|
|
||||||
|
// Self-healing: if every known-state path is absent from the current local scan but
|
||||||
|
// the local folder does have files, the localPath was changed without clearing state.
|
||||||
|
// The stale records would cause every old file to look like "DELETE_REMOTE" and every
|
||||||
|
// new file to re-upload indefinitely. Wipe and retry once as a fresh initial sync.
|
||||||
|
if (!isRetry && knownStates.isNotEmpty() && localFiles.isNotEmpty() &&
|
||||||
|
knownStates.keys.none { it in localFiles }) {
|
||||||
|
Timber.w("SyncEngine: stale folder states detected for pair ${pair.id} — resetting")
|
||||||
|
fileStateDao.deleteForPair(pair.id)
|
||||||
|
return performSync(pair, provider, isRetry = true)
|
||||||
|
}
|
||||||
|
|
||||||
val allPaths = (localFiles.keys + remoteFiles.keys + knownStates.keys).toSet()
|
val allPaths = (localFiles.keys + remoteFiles.keys + knownStates.keys).toSet()
|
||||||
val hasPriorSyncState = knownStates.isNotEmpty()
|
val hasPriorSyncState = knownStates.isNotEmpty()
|
||||||
val semaphore = Semaphore(4)
|
val semaphore = Semaphore(4)
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class FileWatchService : Service() {
|
|||||||
private val fileObservers = mutableMapOf<Long, MutableList<FileObserver>>()
|
private val fileObservers = mutableMapOf<Long, MutableList<FileObserver>>()
|
||||||
private val contentObservers = mutableMapOf<Long, ContentObserver>()
|
private val contentObservers = mutableMapOf<Long, ContentObserver>()
|
||||||
private val debounceJobs = mutableMapOf<Long, Job>()
|
private val debounceJobs = mutableMapOf<Long, Job>()
|
||||||
|
// After a watcher-triggered sync completes, suppress FileObserver events for this long
|
||||||
|
// to stop the feedback loop: sync writes files → FileObserver fires → another sync → repeat.
|
||||||
|
private val syncCooldownUntil = mutableMapOf<Long, Long>()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val CHANNEL_WATCH = "sync_watching"
|
const val CHANNEL_WATCH = "sync_watching"
|
||||||
@@ -210,6 +213,13 @@ class FileWatchService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onChangeDetected(pairId: Long, wifiOnly: Boolean, chargingOnly: Boolean) {
|
private fun onChangeDetected(pairId: Long, wifiOnly: Boolean, chargingOnly: Boolean) {
|
||||||
|
// Ignore events fired by our own sync writing files — prevents the feedback loop
|
||||||
|
// where downloaded/uploaded files trigger another sync indefinitely.
|
||||||
|
if (System.currentTimeMillis() < (syncCooldownUntil[pairId] ?: 0L)) {
|
||||||
|
Timber.d("FileWatchService: suppressing change event for pair $pairId (sync cooldown)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
debounceJobs[pairId]?.cancel()
|
debounceJobs[pairId]?.cancel()
|
||||||
debounceJobs[pairId] = scope.launch {
|
debounceJobs[pairId] = scope.launch {
|
||||||
delay(5_000)
|
delay(5_000)
|
||||||
@@ -217,19 +227,22 @@ class FileWatchService : Service() {
|
|||||||
if (pair == null || !pair.isEnabled) return@launch
|
if (pair == null || !pair.isEnabled) return@launch
|
||||||
Timber.d("FileWatchService: triggering sync for pair $pairId after debounce")
|
Timber.d("FileWatchService: triggering sync for pair $pairId after debounce")
|
||||||
|
|
||||||
|
// Block new triggers from this point until 60s after sync completes
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 120_000
|
||||||
|
|
||||||
val req = SyncWorker.buildOneTimeRequest(pairId, wifiOnly, chargingOnly, silent = true)
|
val req = SyncWorker.buildOneTimeRequest(pairId, wifiOnly, chargingOnly, silent = true)
|
||||||
WorkManager.getInstance(applicationContext)
|
WorkManager.getInstance(applicationContext)
|
||||||
.enqueueUniqueWork("onchange_$pairId", ExistingWorkPolicy.KEEP, req)
|
.enqueueUniqueWork("onchange_$pairId", ExistingWorkPolicy.KEEP, req)
|
||||||
|
|
||||||
// Update notification while sync is in progress
|
|
||||||
updateNotificationDynamic("Syncing: ${pair.name}…")
|
updateNotificationDynamic("Syncing: ${pair.name}…")
|
||||||
|
|
||||||
// Wait for completion and show result in the persistent notification
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
val info = WorkManager.getInstance(applicationContext)
|
val info = WorkManager.getInstance(applicationContext)
|
||||||
.getWorkInfoByIdFlow(req.id)
|
.getWorkInfoByIdFlow(req.id)
|
||||||
.first { it?.state?.isFinished == true }
|
.first { it?.state?.isFinished == true }
|
||||||
|
// Extend cooldown: 60s after sync finishes to let filesystem settle
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
val summary = info?.outputData?.getString(SyncWorker.KEY_RESULT_SUMMARY)
|
val summary = info?.outputData?.getString(SyncWorker.KEY_RESULT_SUMMARY)
|
||||||
val watchCount = fileObservers.keys.size + contentObservers.size
|
val watchCount = fileObservers.keys.size + contentObservers.size
|
||||||
val watching = "Watching $watchCount folder${if (watchCount != 1) "s" else ""}"
|
val watching = "Watching $watchCount folder${if (watchCount != 1) "s" else ""}"
|
||||||
@@ -239,8 +252,9 @@ class FileWatchService : Service() {
|
|||||||
updateNotificationDynamic("$watching")
|
updateNotificationDynamic("$watching")
|
||||||
}
|
}
|
||||||
delay(12_000)
|
delay(12_000)
|
||||||
updateNotificationDynamic(null) // revert to default watching text
|
updateNotificationDynamic(null)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
syncCooldownUntil[pairId] = 0L
|
||||||
updateNotificationDynamic(null)
|
updateNotificationDynamic(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,6 +268,7 @@ class FileWatchService : Service() {
|
|||||||
contentObservers.clear()
|
contentObservers.clear()
|
||||||
debounceJobs.values.forEach { it.cancel() }
|
debounceJobs.values.forEach { it.cancel() }
|
||||||
debounceJobs.clear()
|
debounceJobs.clear()
|
||||||
|
syncCooldownUntil.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ensureChannel() {
|
private fun ensureChannel() {
|
||||||
|
|||||||
@@ -1,102 +1,67 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
SyncFlow icon foreground.
|
SyncFlow icon foreground.
|
||||||
Design: three bold teardrop "speed streak" shapes in Avast color palette
|
Three bold teardrop shapes in Avast-palette colors (teal, red, amber),
|
||||||
(teal, red, yellow) converging on a white cloud in the centre.
|
tips meeting at center (54,54), wide heads pointing outward at 0/120/240 deg.
|
||||||
Each teardrop has a pointed tail (far from cloud) and a wide rounded head
|
White cloud centred over the intersection point.
|
||||||
(near the cloud), like motion streaks flying into the sync point.
|
|
||||||
|
|
||||||
Safe zone: 18-90dp band. Cloud centred at (54, 55).
|
|
||||||
-->
|
-->
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:aapt="http://schemas.android.com/aapt"
|
|
||||||
android:width="108dp"
|
android:width="108dp"
|
||||||
android:height="108dp"
|
android:height="108dp"
|
||||||
android:viewportWidth="108"
|
android:viewportWidth="108"
|
||||||
android:viewportHeight="108">
|
android:viewportHeight="108">
|
||||||
|
|
||||||
<!-- SHADOW layer under teardrops for depth -->
|
<!-- Teal teardrop — head pointing straight up -->
|
||||||
<path
|
<group android:rotation="0"
|
||||||
android:pathData="M 54,28 C 42,28 30,36 32,50 C 22,55 22,70 34,72 L 74,72 C 84,72 88,62 82,55 C 86,43 76,33 66,35 C 62,30 58,28 54,28 Z"
|
android:pivotX="54"
|
||||||
android:fillColor="#000000"
|
android:pivotY="54">
|
||||||
android:fillAlpha="0.20"
|
<path
|
||||||
android:translateY="2.5"/>
|
android:fillColor="#00C4A7"
|
||||||
|
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
||||||
|
</group>
|
||||||
|
|
||||||
<!-- TEAL teardrop: enters from upper-left, tail at (22,22), head near cloud top-left -->
|
<!-- Red teardrop — head pointing lower-right (120 deg CW from up) -->
|
||||||
<!-- Teardrop shape: pointed at tail, fat elliptical head, rotated ~45 deg into centre -->
|
<group android:rotation="120"
|
||||||
<path
|
android:pivotX="54"
|
||||||
android:pathData="M 35.5,26.5
|
android:pivotY="54">
|
||||||
C 30,21 22,22 22,22
|
<path
|
||||||
C 22,22 27,30 32.5,35.5
|
android:fillColor="#F44336"
|
||||||
C 36,38 40,40 43,42
|
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
||||||
C 40,39 36,32 35.5,26.5 Z">
|
</group>
|
||||||
<aapt:attr name="android:fillColor">
|
|
||||||
<gradient android:type="linear"
|
|
||||||
android:startX="22" android:startY="22"
|
|
||||||
android:endX="43" android:endY="42"
|
|
||||||
android:startColor="#00BFA5"
|
|
||||||
android:endColor="#26D6C0"/>
|
|
||||||
</aapt:attr>
|
|
||||||
</path>
|
|
||||||
|
|
||||||
<!-- RED teardrop: enters from upper-right, tail at (86,22), head near cloud top-right -->
|
<!-- Amber teardrop — head pointing lower-left (240 deg CW from up) -->
|
||||||
<path
|
<group android:rotation="240"
|
||||||
android:pathData="M 72.5,26.5
|
android:pivotX="54"
|
||||||
C 78,21 86,22 86,22
|
android:pivotY="54">
|
||||||
C 86,22 81,30 75.5,35.5
|
<path
|
||||||
C 72,38 68,40 65,42
|
android:fillColor="#FFC107"
|
||||||
C 68,39 72,32 72.5,26.5 Z">
|
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
||||||
<aapt:attr name="android:fillColor">
|
</group>
|
||||||
<gradient android:type="linear"
|
|
||||||
android:startX="86" android:startY="22"
|
|
||||||
android:endX="65" android:endY="42"
|
|
||||||
android:startColor="#E53935"
|
|
||||||
android:endColor="#EF6558"/>
|
|
||||||
</aapt:attr>
|
|
||||||
</path>
|
|
||||||
|
|
||||||
<!-- YELLOW teardrop: enters from bottom-centre, tail at (54,88), head near cloud base -->
|
<!-- White cloud centred at (54,52), sits over the teardrop intersection -->
|
||||||
<path
|
|
||||||
android:pathData="M 48,75
|
|
||||||
C 45,82 47,88 54,88
|
|
||||||
C 61,88 63,82 60,75
|
|
||||||
C 58,71 56,68 54,66
|
|
||||||
C 52,68 50,71 48,75 Z">
|
|
||||||
<aapt:attr name="android:fillColor">
|
|
||||||
<gradient android:type="linear"
|
|
||||||
android:startX="54" android:startY="88"
|
|
||||||
android:endX="54" android:endY="66"
|
|
||||||
android:startColor="#F9A825"
|
|
||||||
android:endColor="#FFD740"/>
|
|
||||||
</aapt:attr>
|
|
||||||
</path>
|
|
||||||
|
|
||||||
<!-- CLOUD body (white, centred at 54,50) -->
|
|
||||||
<path
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
android:pathData="
|
android:pathData="
|
||||||
M 36,62
|
M 42,62
|
||||||
A 9,9 0 0,1 36,44
|
A 8,8 0 0,1 42,46
|
||||||
A 9,9 0 0,1 45,36
|
A 8,8 0 0,1 51,39
|
||||||
A 12,12 0 0,1 66,37
|
A 11,11 0 0,1 67,42
|
||||||
A 8,8 0 0,1 74,48
|
A 7,7 0 0,1 68,56
|
||||||
A 8,8 0 0,1 68,62
|
A 7,7 0 0,1 66,62
|
||||||
Z"
|
Z"/>
|
||||||
android:fillColor="#FFFFFF"/>
|
|
||||||
|
|
||||||
<!-- Teal highlight on cloud top-left edge -->
|
<!-- Cloud inner shadow to make it pop from the coloured teardrops -->
|
||||||
<path
|
<path
|
||||||
android:pathData="M 36,53 A 9,9 0 0,1 41,38"
|
|
||||||
android:fillColor="#00000000"
|
android:fillColor="#00000000"
|
||||||
android:strokeWidth="2"
|
android:strokeColor="#18000000"
|
||||||
android:strokeLineCap="round"
|
android:strokeWidth="1.5"
|
||||||
android:strokeColor="#4000BFA5"/>
|
android:pathData="
|
||||||
|
M 42,62
|
||||||
<!-- Red highlight on cloud top-right edge -->
|
A 8,8 0 0,1 42,46
|
||||||
<path
|
A 8,8 0 0,1 51,39
|
||||||
android:pathData="M 63,37 A 8,8 0 0,1 73,48"
|
A 11,11 0 0,1 67,42
|
||||||
android:fillColor="#00000000"
|
A 7,7 0 0,1 68,56
|
||||||
android:strokeWidth="2"
|
A 7,7 0 0,1 66,62
|
||||||
android:strokeLineCap="round"
|
Z"/>
|
||||||
android:strokeColor="#40E53935"/>
|
|
||||||
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
VERSION_NAME=1.0.28
|
VERSION_NAME=1.0.29
|
||||||
VERSION_CODE=29
|
VERSION_CODE=30
|
||||||
|
|||||||
Reference in New Issue
Block a user