feat: add progress watchdog and iCloud hints to mackup restore
- Pre-materialize iCloud stubs before restore (same as backup) - Report stub count so user knows why it might be slow - Background watchdog prints '… still running (Ns elapsed)' every 15s so long iCloud download pauses don't look like a hang - Report total elapsed time on completion Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+55
-1
@@ -101,6 +101,60 @@ ssr::mackup::backup() {
|
||||
|
||||
ssr::mackup::restore() {
|
||||
ssr::log "mackup restore"
|
||||
|
||||
# Pre-materialize iCloud placeholders so mackup doesn't have to wait for
|
||||
# each file to download one-by-one during the restore walk.
|
||||
local cfg="$HOME/.mackup.cfg" mackup_root="" path dir
|
||||
if [[ -f "$cfg" ]]; then
|
||||
path="$(awk -F= '/^path/{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2); print $2}' "$cfg")"
|
||||
dir="$( awk -F= '/^directory/{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2); print $2}' "$cfg")"
|
||||
[[ -n "$path" && -n "$dir" ]] && mackup_root="$path/$dir"
|
||||
fi
|
||||
if [[ -n "$mackup_root" ]]; then
|
||||
ssr::log "Materializing iCloud files in $mackup_root (may take a moment)…"
|
||||
ssr::mackup::_materialize_icloud "$mackup_root"
|
||||
# Count remaining stubs; if there are many, give iCloud more time.
|
||||
local stub_count
|
||||
stub_count="$(find "$mackup_root" -name '*.icloud' -type f 2>/dev/null | wc -l | tr -d ' ')"
|
||||
if [[ "$stub_count" -gt 0 ]]; then
|
||||
ssr::warn "$stub_count placeholder file(s) still pending — waiting 5s for iCloud sync…"
|
||||
sleep 5
|
||||
fi
|
||||
fi
|
||||
|
||||
local stub_total
|
||||
stub_total="$(find "${mackup_root:-/dev/null}" -name '*.icloud' -type f 2>/dev/null | wc -l | tr -d ' ')"
|
||||
if [[ "$stub_total" -gt 0 ]]; then
|
||||
ssr::warn "$stub_total file(s) still need downloading from iCloud — restore may pause between files."
|
||||
fi
|
||||
ssr::log "Running mackup restore (long pauses are normal while iCloud fetches files)…"
|
||||
|
||||
# Background watchdog: prints elapsed time every 15s so the user knows the
|
||||
# process is still alive during iCloud download pauses.
|
||||
local start_ts rc=0 done_flag watchdog_pid
|
||||
start_ts="$(date +%s)"
|
||||
done_flag="$(mktemp)"
|
||||
(
|
||||
while [[ -f "$done_flag" ]]; do
|
||||
sleep 15
|
||||
[[ -f "$done_flag" ]] || break
|
||||
printf ' … mackup restore still running (%ds elapsed — waiting for iCloud)\n' \
|
||||
"$(( $(date +%s) - start_ts ))" >&2
|
||||
done
|
||||
) &
|
||||
watchdog_pid=$!
|
||||
|
||||
# -f: answer "yes" to all prompts (consistent with backup behaviour).
|
||||
mackup -f restore
|
||||
mackup -f restore || rc=$?
|
||||
|
||||
rm -f "$done_flag"
|
||||
kill "$watchdog_pid" 2>/dev/null || true
|
||||
wait "$watchdog_pid" 2>/dev/null || true
|
||||
|
||||
local elapsed=$(( $(date +%s) - start_ts ))
|
||||
if [[ $rc -ne 0 ]]; then
|
||||
ssr::warn "mackup restore finished with errors (rc=$rc, ${elapsed}s elapsed)"
|
||||
else
|
||||
ssr::ok "mackup restore completed in ${elapsed}s"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user