Skip to content

Don't chmod temporarily orphaned symlinks during restore - #2198

Merged
lra merged 3 commits into
masterfrom
fix_971
Jun 15, 2026
Merged

lra merged 3 commits into
masterfrom
fix_971

Conversation

@lra

@lra lra commented Jun 15, 2026 •

Copy link
Copy Markdown
Owner

What

utils.chmod() crashes with FileNotFoundError when a directory contains an orphaned symlink (a link whose target doesn't exist).

os.walk lists symlinks among files, and os.chmod follows symlinks by default, so chmodding an orphaned link fails. This happens during mackup restore when 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.isfile is False for orphaned symlinks, True for valid ones — preserving prior follow-the-link behavior).

Test

Extended test_chmod_file with an orphaned-symlink case that reproduced the original crash. Full tests/test_utils.py suite passes (20 passed).


Supersedes #971 by @glaszig, reworked for the current src/ layout and pytest.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py to skip chmod operations on entries that would fail due to orphaned symlinks during recursive directory traversal.
  • Extend tests/test_utils.py::test_chmod_file with 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.

Comment thread src/mackup/utils.py Resolved
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/mackup/utils.py Resolved
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@lra
lra merged commit fbaa444 into master Jun 15, 2026
34 checks passed
@lra
lra deleted the fix_971 branch June 15, 2026 00:33
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.

2 participants