Repository navigation
Conversation
os.walk lists symlinks among files, and os.chmod follows them by default, so an orphaned symlink (e.g. a link restored before its target) makes chmod() crash with FileNotFoundError. Skip entries that aren't real files. Supersedes #971 by glaszig, reworked for the current src/ layout and pytest. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates utils.chmod() to avoid crashing during mackup restore when encountering temporarily orphaned symlinks (symlinks whose targets don’t exist yet), and adds a regression test to cover the scenario.
Changes:
- Update
src/mackup/utils.pyto skip chmod operations on entries that would fail due to orphaned symlinks during recursive directory traversal. - Extend
tests/test_utils.py::test_chmod_filewith a new orphaned-symlink case to reproduce and prevent the crash.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/mackup/utils.py |
Adjusts recursive chmod logic to avoid os.chmod failures caused by orphaned symlinks during os.walk. |
tests/test_utils.py |
Adds a regression test ensuring utils.chmod() does not crash when a directory contains an orphaned symlink. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Narrow the skip guard to broken symlinks (symlink && !exists) instead of os.path.isfile, which also skipped non-regular files (FIFOs, sockets, device nodes) that os.walk legitimately lists.
Pre-checking with os.path.exists() skips symlinks on any stat() failure (e.g. permission errors), not just dangling ones. Attempt os.chmod and only ignore FileNotFoundError when the path is a symlink; re-raise for real missing regular files.
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.
What
utils.chmod()crashes withFileNotFoundErrorwhen a directory contains an orphaned symlink (a link whose target doesn't exist).os.walklists symlinks amongfiles, andos.chmodfollows symlinks by default, so chmodding an orphaned link fails. This happens duringmackup restorewhen a link is restored before the file it points to (e.g. the fish/fisherman ordering case from #710).Fix
Skip entries that aren't real files (
os.path.isfileisFalsefor orphaned symlinks,Truefor valid ones — preserving prior follow-the-link behavior).Test
Extended
test_chmod_filewith an orphaned-symlink case that reproduced the original crash. Fulltests/test_utils.pysuite passes (20 passed).Supersedes #971 by @glaszig, reworked for the current
src/layout and pytest.