Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure readonly files can be removed on Windows. #20244

Merged
merged 2 commits into from Mar 8, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -16,6 +16,7 @@
import re
import subprocess
import sys
import traceback
import urllib2
import glob

@@ -318,6 +319,7 @@ def get_size(path):
try:
delete(crate_path)
except:
print(traceback.format_exc())
print("Delete %s failed!" % crate_path)
else:
print("Would remove `{}`{} package from {}".format(*print_msg))
@@ -14,6 +14,7 @@
import platform
import shutil
from socket import error as socket_error
import stat
import StringIO
import sys
import zipfile
@@ -35,9 +36,15 @@
URLOPEN_KWARGS = {}


def remove_readonly(func, path, _):
"Clear the readonly bit and reattempt the removal"
os.chmod(path, stat.S_IWRITE)
func(path)


def delete(path):
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path)
shutil.rmtree(path, onerror=remove_readonly)
else:
os.remove(path)

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.