From b50ab61d5cc66abcb583be86e4de9a69cbf5cceb Mon Sep 17 00:00:00 2001 From: "Oliver Surke (Gitea)" Date: Tue, 12 May 2026 11:00:25 +0200 Subject: [PATCH] fix: remove dangling symlinks before mackup backup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shutil.copy fails on dangling symlinks with [Errno 2] No such file or directory (e.g. ~/.claude/debug/latest → missing target). Pre-backup cleanup now handles two cases: - Unix sockets (-type s) → Errno 102 - Dangling links (-type l !-e) → Errno 2 Both are ephemeral runtime artefacts that cannot be meaningfully backed up. Co-authored-by: Cursor --- lib/mackup.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/mackup.sh b/lib/mackup.sh index a64e225..9d04e8a 100644 --- a/lib/mackup.sh +++ b/lib/mackup.sh @@ -202,9 +202,10 @@ ssr::mackup::backup() { fi [[ -n "$mackup_root" ]] && ssr::mackup::_materialize_icloud "$mackup_root" - # Unix socket files (type s) cannot be copied and are always recreated - # by their owning app on startup. Remove them from $HOME before backup - # to prevent shutil.Error: [Errno 102] Operation not supported on socket. + # Pre-backup cleanup: remove file types that shutil.copy cannot handle. + # + # 1. Unix socket files (-type s) — runtime artefacts, recreated on app start. + # Cause: shutil.Error [Errno 102] Operation not supported on socket local socket_count socket_count="$(find "$HOME" -type s 2>/dev/null | wc -l | tr -d ' ')" if [[ "$socket_count" -gt 0 ]]; then @@ -212,6 +213,15 @@ ssr::mackup::backup() { find "$HOME" -type s -delete 2>/dev/null || true fi + # 2. Dangling symlinks (-type l ! -e) — point to a non-existent target. + # Cause: shutil.Error [Errno 2] No such file or directory: '' + local dangling_count + dangling_count="$(find "$HOME" -type l ! -e 2>/dev/null | wc -l | tr -d ' ')" + if [[ "$dangling_count" -gt 0 ]]; then + ssr::log "Removing $dangling_count dangling symlink(s) before mackup backup" + find "$HOME" -type l ! -e -delete 2>/dev/null || true + fi + local attempt rc=0 for attempt in 1 2 3; do if mackup -f backup; then