Repository navigation
fix(restore): don't crash on a broken symlink in the home folder - #2205
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #704
mackup restore(and--dry-run) aborted withFileNotFoundErrorwhen 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 withos.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 usedos.path.exists, which is false for a broken link, so a laterutils.linkwould have collided with the existing link.Fix: only call
samefilewhen the home path resolves (os.path.exists), and useos.path.lexistsfor the replacement check so a broken link goes through the usual "replace it with your backup?" confirmation (utils.deletealready 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 withdry_run=True) raisedFileNotFoundErrorfromsamefile.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
AI assistance: this change and its regression tests were prepared using Claude Code.