Deal with read-only files when removing directories
Fixes error on windows when installing from non-default git repo (for some reason a few files in .git are read-only and shutil.rmtree fails to remove them).
This commit is contained in:
parent
3eadfc5456
commit
fa0a6f6a53
17
hererocks.py
17
hererocks.py
@ -11,6 +11,7 @@ import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
@ -177,6 +178,16 @@ def check_existence(path):
|
||||
def copy_dir(src, dst):
|
||||
shutil.copytree(src, dst, ignore=lambda _, __: {".git"})
|
||||
|
||||
def remove_read_only_or_reraise(func, path, exc_info):
|
||||
if not os.access(path, os.W_OK):
|
||||
os.chmod(path, stat.S_IWUSR)
|
||||
func(path)
|
||||
else:
|
||||
raise
|
||||
|
||||
def remove_dir(path):
|
||||
shutil.rmtree(path, onerror=remove_read_only_or_reraise)
|
||||
|
||||
clever_http_git_whitelist = [
|
||||
"http://github.com/", "https://github.com/",
|
||||
"http://bitbucket.com/", "https://bitbucket.com/"
|
||||
@ -1198,7 +1209,7 @@ class LuaJIT(Lua):
|
||||
opts.location, "share", "lua", self.major_version, "jit")
|
||||
|
||||
if os.path.exists(jitlib_path):
|
||||
shutil.rmtree(jitlib_path)
|
||||
remove_dir(jitlib_path)
|
||||
|
||||
copy_dir("jit", jitlib_path)
|
||||
|
||||
@ -1489,7 +1500,7 @@ def setup_vs_and_rerun(vs_version, arch):
|
||||
argv_h.write("\r\n".join(sys.argv).encode("UTF-8"))
|
||||
|
||||
exit_code = subprocess.call([bat_name])
|
||||
shutil.rmtree(temp_dir)
|
||||
remove_dir(temp_dir)
|
||||
sys.exit(exit_code)
|
||||
|
||||
def setup_vs(target):
|
||||
@ -1689,7 +1700,7 @@ def main(argv=None):
|
||||
|
||||
os.chdir(start_dir)
|
||||
|
||||
shutil.rmtree(temp_dir)
|
||||
remove_dir(temp_dir)
|
||||
print("Done.")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@ -61,6 +61,9 @@ class TestCLI(unittest.TestCase):
|
||||
self.assertHererocksSuccess(["--lua", "latest", "--luarocks", "latest"], ["already installed"])
|
||||
self.assertHererocksSuccess(["--luarocks", "latest", "--ignore-installed"], ["Fetching", "cached"])
|
||||
|
||||
def test_install_latest_lua_with_luarocks_from_git(self):
|
||||
self.assertHererocksSuccess(["--lua", "latest", "--luarocks", "https://github.com/mpeterv/luarocks@master"])
|
||||
|
||||
def test_verbose_install_bleeding_edge_luajit_with_latest_luarocks(self):
|
||||
self.assertHererocksSuccess(["--luajit", "@v2.1", "--luarocks", "latest", "--verbose"])
|
||||
self.assertSuccess(["lua", "-v"], ["LuaJIT 2.1.0"])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user