servo: Merge #20244 - Ensure readonly files can be removed on Windows (from servo:jdm-patch-10); r=SimonSapin
This is based off of https://bugs.python.org/issue19643. At worst, it makes our deletion function more robust and doesn't help with the ongoing windows CI problems. Source-Repo: https://github.com/servo/servo Source-Revision: f1338d3df8d76f821353686efe2d6a0a4691da02
This commit is contained in:
@@ -16,6 +16,7 @@ import os.path as path
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
import urllib2
|
import urllib2
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
@@ -318,6 +319,7 @@ class MachCommands(CommandBase):
|
|||||||
try:
|
try:
|
||||||
delete(crate_path)
|
delete(crate_path)
|
||||||
except:
|
except:
|
||||||
|
print(traceback.format_exc())
|
||||||
print("Delete %s failed!" % crate_path)
|
print("Delete %s failed!" % crate_path)
|
||||||
else:
|
else:
|
||||||
print("Would remove `{}`{} package from {}".format(*print_msg))
|
print("Would remove `{}`{} package from {}".format(*print_msg))
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import os.path
|
|||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
from socket import error as socket_error
|
from socket import error as socket_error
|
||||||
|
import stat
|
||||||
import StringIO
|
import StringIO
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -35,9 +36,15 @@ else:
|
|||||||
URLOPEN_KWARGS = {}
|
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):
|
def delete(path):
|
||||||
if os.path.isdir(path) and not os.path.islink(path):
|
if os.path.isdir(path) and not os.path.islink(path):
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path, onerror=remove_readonly)
|
||||||
else:
|
else:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user