66import sys
77import 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+
928with open ("libraries.json" , "r" ) as file :
1029 libraries = json .load (file )
1130
1736for 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 ))
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