Skip to content

Commit 7276f94

Browse files
committed
updated dependencies script to fix permissions
1 parent 7c40ac0 commit 7276f94

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

src/update_dependencies.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
import sys
77
import shutil
88

9+
def onerror(func, path, exc_info):
10+
"""
11+
Error handler for ``shutil.rmtree``.
12+
13+
If the error is due to an access error (read only file)
14+
it attempts to add write permission and then retries.
15+
16+
If the error is for another reason it re-raises the error.
17+
18+
Usage : ``shutil.rmtree(path, onerror=onerror)``
19+
"""
20+
import stat
21+
# Is the error an access error?
22+
if not os.access(path, os.W_OK):
23+
os.chmod(path, stat.S_IWUSR)
24+
func(path)
25+
else:
26+
raise
27+
928
with open("libraries.json", "r") as file:
1029
libraries = json.load(file)
1130

@@ -17,7 +36,7 @@
1736
for library in libraries:
1837
repo_name = library["git_url"].split("/")[-1].replace(".git", "")
1938
if Path(repo_name).exists():
20-
shutil.rmtree(repo_name)
39+
shutil.rmtree(repo_name, onerror=onerror)
2140

2241
os.system(f"git clone {library["git_url"]}")
2342
os.chdir(os.path.join(arduino_lib_path, repo_name))
@@ -27,5 +46,6 @@
2746
else:
2847
os.system(f"git sparse-checkout set --no-cone {library["root_dir"]}")
2948
shutil.copytree(library["root_dir"], os.getcwd(), dirs_exist_ok=True)
30-
shutil.rmtree(library["root_dir"].split("/")[0])
31-
print(f"Moved {library["root_dir"]} to be the root of {repo_name}")
49+
shutil.rmtree(library["root_dir"].split("/")[0], onerror=onerror)
50+
print(f"Moved {library["root_dir"]} to be the root of {repo_name}")
51+
shutil.rmtree(".git", onerror=onerror)

0 commit comments

Comments
 (0)