Skip to content

Instantly share code, notes, and snippets.

@EliahKagan
Last active October 30, 2023 09:14
Show Gist options
  • Save EliahKagan/b2b14bcf1620dda81c40f4bb540cf85a to your computer and use it in GitHub Desktop.
Save EliahKagan/b2b14bcf1620dda81c40f4bb540cf85a to your computer and use it in GitHub Desktop.
Investigating GitPython git.util.rmtree permissions bug

Investigating GitPython git.util.rmtree permissions bug

$ ./perm.sh
Permissions BEFORE rmtree call:
-r--r--r-- 1 ek ek 0 Oct 30 05:13 dir1/file

Traceback (most recent call last):
  File "/usr/lib/python3.12/shutil.py", line 695, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'symlink'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ek/repos-wsl/GitPython/git/util.py", line 212, in rmtree
    shutil.rmtree(path, onexc=handler)
  File "/usr/lib/python3.12/shutil.py", line 769, in rmtree
    _rmtree_safe_fd(fd, path, onexc)
  File "/usr/lib/python3.12/shutil.py", line 697, in _rmtree_safe_fd
    onexc(os.unlink, fullname, err)
  File "/home/ek/repos-wsl/GitPython/git/util.py", line 203, in handler
    function(path)
PermissionError: [Errno 13] Permission denied: 'dir2/symlink'

Permissions AFTER rmtree call:
--w------- 1 ek ek 0 Oct 30 05:13 dir1/file

License for this gist (including perm.sh): CC0-1.0 (public domain) [SPDX]

#!/bin/sh
set -e
mkdir dir1
touch dir1/file
chmod -w dir1/file
printf 'Permissions BEFORE rmtree call:\n'
ls -l dir1/file
printf '\n'
mkdir dir2
ln -s ../dir1/file dir2/symlink
chmod -w dir2
python -c 'from git.util import rmtree; rmtree("dir2")' || true
printf '\nPermissions AFTER rmtree call:\n'
ls -l dir1/file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment