From bb0d9573a9a87616b65ee4c1cedccb18406d5982 Mon Sep 17 00:00:00 2001 From: francisco souza Date: Sat, 5 Dec 2020 22:26:38 -0500 Subject: [PATCH 1/2] util: also run chmod on EPERM 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' ``` --- pre_commit/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre_commit/util.py b/pre_commit/util.py index f4cf7045a..fc506b98e 100644 --- a/pre_commit/util.py +++ b/pre_commit/util.py @@ -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) From c598785b6f7be0fb9371eb54e48fd09668210a96 Mon Sep 17 00:00:00 2001 From: francisco souza <108725+fsouza@users.noreply.github.com> Date: Sun, 6 Dec 2020 07:45:31 -0800 Subject: [PATCH 2/2] util: use set instead of tuple in errno check Co-authored-by: Paul Fischer <70564747+paulhfischer@users.noreply.github.com> --- pre_commit/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre_commit/util.py b/pre_commit/util.py index fc506b98e..b5f40ada4 100644 --- a/pre_commit/util.py +++ b/pre_commit/util.py @@ -255,7 +255,7 @@ def handle_remove_readonly( excvalue = exc[1] if ( func in (os.rmdir, os.remove, os.unlink) and - excvalue.errno in (errno.EACCES, errno.EPERM) + 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)