diff --git a/githubplugin/__init__.py b/githubplugin/__init__.py index 95090bf2a..07550f7c8 100644 --- a/githubplugin/__init__.py +++ b/githubplugin/__init__.py @@ -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: @@ -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: @@ -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: