Skip to content

Commit 7aaedd5

Browse files
committed
Merge pull request #1745 from RobberPhex/develop
delete read-only file in Windows
2 parents 7e79099 + 8a86fd3 commit 7aaedd5

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

pip/util.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
from pip.exceptions import InstallationError, BadCommand
1313
from pip.backwardcompat import(
14-
WindowsError, string_types, raw_input, console_to_str,
15-
PermissionError, stdlib_pkgs
14+
string_types, raw_input, console_to_str, stdlib_pkgs
1615
)
1716
from pip.locations import (
1817
site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
@@ -52,19 +51,15 @@ def rmtree_errorhandler(func, path, exc_info):
5251
"""On Windows, the files in .svn are read-only, so when rmtree() tries to
5352
remove them, an exception is thrown. We catch that here, remove the
5453
read-only attribute, and hopefully continue without problems."""
55-
exctype, value = exc_info[:2]
56-
if not ((exctype is WindowsError and value.args[0] == 5) or # others
57-
(exctype is OSError and value.args[0] == 13) or # python2.4
58-
(exctype is PermissionError and value.args[3] == 5) # python3.3
59-
):
60-
raise
61-
# file type should currently be read only
62-
if ((os.stat(path).st_mode & stat.S_IREAD) != stat.S_IREAD):
54+
# if file type currently read only
55+
if os.stat(path).st_mode & stat.S_IREAD:
56+
# convert to read/write
57+
os.chmod(path, stat.S_IWRITE)
58+
# use the original function to repeat the operation
59+
func(path)
60+
return
61+
else:
6362
raise
64-
# convert to read/write
65-
os.chmod(path, stat.S_IWRITE)
66-
# use the original function to repeat the operation
67-
func(path)
6863

6964

7065
def display_path(path):

0 commit comments

Comments
 (0)