Skip to content

Commit

Permalink
githubplugin: try to solve non-empty dir problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Nov 18, 2024
1 parent f72fa1b commit 33da94b
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions githubplugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,24 @@ def _move_old_link(self, name) -> bool:
self.loggerr(f'error renaming old plugin: {e}')
return False

def _rmtree(self, path):
""" remove path tree, also try to remove .DS_Store if present """
try:
rmtree(path)
except Exception:
pass

if os.path.exists(path):
# if directory wasn't deleted, just silently try again
try:
rmtree(path)
except Exception:
pass

if os.path.exists(path):
# Try again, but finally give up if error persists
rmtree(path)

def remove_plugin(self, name) -> bool:
""" remove plugin link, worktree and if not longer needed, local repo """
if name not in self.repos:
Expand Down Expand Up @@ -612,14 +630,9 @@ def remove_plugin(self, name) -> bool:
err.append(e)

if last_branch:
try:
# cope with possibly created .DS_Store files on Mac
os.chmod(wt_path, 0o777)
except Exception:
pass
try:
self.logger.debug(f'removing worktree {wt_path}')
rmtree(wt_path)
self._rmtree(wt_path)
except Exception as e:
err.append(e)
try:
Expand All @@ -629,14 +642,9 @@ def remove_plugin(self, name) -> bool:
err.append(e)

if last_repo:
try:
# cope with possibly created .DS_Store files on Mac
os.chmod(repo_path, 0o777)
except Exception:
pass
try:
self.logger.debug(f'repo {repo_path} is no longer used, removing')
rmtree(repo_path)
self._rmtree(repo_path)
except Exception as e:
err.append(e)
else:
Expand Down

0 comments on commit 33da94b

Please sign in to comment.