Skip to content

fix: rm_rf handles dirs without S_IXUSR permission#2

Open
yashwant86 wants to merge 2 commits intomainfrom
pr-14331
Open

fix: rm_rf handles dirs without S_IXUSR permission#2
yashwant86 wants to merge 2 commits intomainfrom
pr-14331

Conversation

@yashwant86
Copy link
Copy Markdown

Mirror of pytest-dev#14331

RonnyPfannschmidt and others added 2 commits March 27, 2026 20:24
…-dev#7940)

The on_rm_rf_error handler previously only set S_IRUSR|S_IWUSR (read+write)
when retrying failed removals, and silently skipped os.open/os.scandir
failures. This meant directories lacking execute permission (S_IXUSR) could
not be traversed or removed by shutil.rmtree.

Now the handler:
- Uses S_IRWXU (read+write+execute) for all permission fixes
- Handles os.open and os.scandir PermissionError by fixing permissions
  on the path and its parent, then removing the entry directly
- Includes a guard against infinite recursion when chmod has no effect

Supersedes pytest-dev#7941 which took the approach of delegating to
tempfile.TemporaryDirectory._rmtree.

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Claude Opus <claude@anthropic.com>
- Use stat.S_IMODE() to extract only permission bits before
  comparing/setting, avoiding file-type bit leakage into os.chmod
- Only add S_IXUSR for directories; regular files get S_IRUSR|S_IWUSR
  only, avoiding unnecessary execute side-effect on files
- Fix recursion guard: track whether *either* parent or path chmod
  changed permissions, so fixing the parent alone (the common case for
  missing S_IXUSR) is sufficient to proceed with removal
- Add test for parent-only permission fix scenario

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Claude Opus <claude@anthropic.com>
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