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