Skip to content

Commit

Permalink
util: also run chmod on EPERM
Browse files Browse the repository at this point in the history
Writing a test for this one is tricky, because I was seeing the issue
only when the directory being removed is a docker volume, so instead of
getting EACCES we get EPERM.

This is easy to reproduce though. The existing test fails when the
directory being used for the files is a docker volume:

```
% docker run \
	-v $(mktemp -d):/tmp \
	-v ${PWD}:/src \
	-w /src \
	python:3 \
	bash -c 'pip install -e . && pip install -r requirements-dev.txt && python -m pytest tests/util_test.py'
```
  • Loading branch information
fsouza committed Dec 6, 2020
1 parent 92ce2dc commit bb0d957
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pre_commit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def handle_remove_readonly(
excvalue = exc[1]
if (
func in (os.rmdir, os.remove, os.unlink) and
excvalue.errno == errno.EACCES
excvalue.errno in (errno.EACCES, errno.EPERM)
):
for p in (path, os.path.dirname(path)):
os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
Expand Down

0 comments on commit bb0d957

Please sign in to comment.