Skip to content

Commit ae887ac

Browse files
author
Dan Davis
committed
Addresses pypa#7280 - More targeted fix to problem
- Try to delete the temporary directory, as most of the time this works - If it fails on windows due to an Access error, it clearly is not an Access error because we just created the directory. Warn the user and continue.
1 parent 8c888a2 commit ae887ac

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/pip/_internal/utils/temp_dir.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import itertools
55
import logging
66
import os.path
7+
import sys
78
import tempfile
89
from contextlib import contextmanager
910

@@ -124,7 +125,21 @@ def cleanup(self):
124125
"""
125126
self._deleted = True
126127
if os.path.exists(self._path):
127-
rmtree(self._path)
128+
try:
129+
rmtree(self._path)
130+
except OSError as e:
131+
skip_error = (
132+
sys.platform == 'win32' and
133+
e.errno == errno.EACCES and
134+
getattr(e, 'winerror', 0) in {5, 32}
135+
)
136+
if skip_error:
137+
logger.warning(
138+
"%s (virus scanner may be holding it)."
139+
"cannot remove '%s'",
140+
e.strerror, e.filename)
141+
else:
142+
raise
128143

129144

130145
class AdjacentTempDirectory(TempDirectory):

0 commit comments

Comments
 (0)