Skip to content

Commit

Permalink
Ensure readonly files can be removed on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Mar 8, 2018
1 parent 1d122c2 commit 71e2e84
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/servo/util.py
Expand Up @@ -14,6 +14,7 @@
import platform
import shutil
from socket import error as socket_error
import stat
import StringIO
import sys
import zipfile
Expand All @@ -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)

Expand Down

0 comments on commit 71e2e84

Please sign in to comment.