Skip to content

Commit e5d1e5a

Browse files
authored
Fix a Windows error with removing the temp repo
1 parent edc6bc7 commit e5d1e5a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: pull_request.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ def _calculate_diff_at_commit(self, commit: str) -> str:
9898

9999
os.chdir(original_working_directory)
100100
if os.path.exists(tmp_repo_fname):
101-
shutil.rmtree(tmp_repo_fname)
101+
102+
# rmtree can fail on Windows if files are set to readonly
103+
def remove_readonly(func, path, _):
104+
# Clear the readonly bit and reattempt the removal
105+
os.chmod(path, stat.S_IWRITE)
106+
func(path)
107+
108+
shutil.rmtree(tmp_repo_fname, onerror=remove_readonly)
102109

103110
def _diff_at_commit(self, commit: str) -> str:
104111
if commit not in self._commit_diffs:

0 commit comments

Comments
 (0)