Fix backup loop, NAS Archive regression, and manifest validity check

- AutoBackupCoordinator: add 55s debounce to onActive() so repeated .task
  and scenePhase triggers (navigation appear, rapid foreground cycles) are
  no-ops; start a 60s periodic recheck timer on first active call; stop timer
  and reset debounce on willResignActiveNotification so each new foreground
  session always gets an immediate fresh status check

- BackupView: remove the redundant lanMonitor.nasReachable onChange that was
  calling statusService.refresh() directly — coordinator already handles this
  via its Combine $nasReachable subscriber, avoiding a double reconcile that
  could bypass the autoBackupOnOpen gate with the wrong lastTriggerWasLAN value

- BackupStatusService: when NAS connect fails, restore nasArchiveTotal from
  NASManifestCache before writing the offline snapshot — prevents the count
  from showing 0 when the NAS is temporarily unreachable but the cache is warm

- BackupStatusService: manifest validity check — if the decoded manifest has
  ≤ 1 entries (corrupt or newly created), scan the NAS directory and use the
  real file count as the display floor for nasArchiveTotal without adding
  orphan entries to the manifest (that was the 7421 regression)

- BackupManifest: add ManifestIndex.init(manifest:overrideTotalCount:) for
  the validity check path — keeps localIdentifier matching intact while
  correcting the displayed archive count

- SMBService: add os.log around connect/auth/listDirectory with actual error
  reason instead of always surfacing authenticationFailed; distinguish network
  errors (timeout, host unreachable) from auth errors in thrown BackupError

Co-Authored-By: Kutesir <kutesir@provoc.ug>
Co-Authored-By: Sentry <sentry@provoc.ug>
This commit is contained in:
Robin Kutesa
2026-05-18 16:07:41 +03:00
parent 3beea88fab
commit d2190bce8a
5 changed files with 114 additions and 11 deletions

View File

@@ -54,6 +54,27 @@ struct ManifestIndex: Sendable {
self.totalCount = count
}
// Same as init(manifest:) but with a corrected totalCount for display.
// Used when the manifest has too few entries to trust but localIdentifiers are still valid.
init(manifest: BackupManifest, overrideTotalCount: Int) {
var ids = Set<String>(minimumCapacity: manifest.entries.count)
var names = Set<String>(minimumCapacity: manifest.entries.count)
var unclaimed = Set<String>()
for entry in manifest.entries {
let lower = entry.filename.lowercased()
names.insert(lower)
if !entry.localIdentifier.isEmpty {
ids.insert(entry.localIdentifier)
} else {
unclaimed.insert(lower)
}
}
self.localIdentifiers = ids
self.lowercasedFilenames = names
self.unclaimedFilenames = unclaimed
self.totalCount = overrideTotalCount
}
// Build from NAS directory listing (bootstrap no localIdentifiers known)
init(nasListing items: [NASItem]) {
var names = Set<String>()