Skip to content

fix(restore): don't crash on a broken symlink in the home folder - #2205

Open
pcbeingused333 wants to merge 1 commit into
lra:masterfrom
pcbeingused333:fix/restore-broken-symlink
Open

pcbeingused333 wants to merge 1 commit into
lra:masterfrom
pcbeingused333:fix/restore-broken-symlink

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #704

mackup restore (and --dry-run) aborted with FileNotFoundError when a file to restore was a dangling symlink in the home folder, for example a leftover link pointing to an old, now missing backup location.

Root cause: ApplicationProfile.link() decides whether the home path already points to the backup with os.path.samefile(mackup_filepath, home_filepath), which stats the home path and raises when the symlink is broken. In addition, the "already something in the home folder" check used os.path.exists, which is false for a broken link, so a later utils.link would have collided with the existing link.

Fix: only call samefile when the home path resolves (os.path.exists), and use os.path.lexists for the replacement check so a broken link goes through the usual "replace it with your backup?" confirmation (utils.delete already removes links) instead of crashing.

Reproduction

A valid backup file plus a home path that is a symlink to a nonexistent target; calling ApplicationProfile.link() (also with dry_run=True) raised FileNotFoundError from samefile.

Testing

Add three regression tests in tests/test_application.py: dry run with a broken home symlink, confirmed replacement (the home path ends up linked to the backup), and declined replacement (the broken link is left untouched).

python -m pytest tests -q: the 3 new tests fail without the change, and the full suite (92 tests) passes with it.

All submissions

Improving the Mackup codebase

  • My submission passes the tests
  • I have linted the code locally prior to submission
  • I have written new tests as applicable
  • I have added an explanation of what the changes do

AI assistance: this change and its regression tests were prepared using Claude Code.

samefile() stats the home path, so a dangling symlink raised FileNotFoundError during restore, even with --dry-run. Only compare files when the home path resolves, and treat a broken link as something to confirm and replace.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mackup restore on new machine cause OSError: [Errno 2] No such file or directory

1 participant