From 53f4edb0168b44535bd910ae941b9a07aff8276e Mon Sep 17 00:00:00 2001 From: nbenedek Date: Fri, 7 Apr 2023 00:17:33 +0200 Subject: [PATCH] gitweb: Completely uninstall app, remove repositories Tests: 1. Install app, create a repository 2. Reinstall app and confirm the repository is removed Signed-off-by: nbenedek [sunil: Update docstrings, make uninstall fail-safe] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/gitweb/__init__.py | 5 +++++ plinth/modules/gitweb/privileged.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/plinth/modules/gitweb/__init__.py b/plinth/modules/gitweb/__init__.py index 0254ef98c..76040f058 100644 --- a/plinth/modules/gitweb/__init__.py +++ b/plinth/modules/gitweb/__init__.py @@ -127,6 +127,11 @@ class GitwebApp(app_module.App): privileged.setup() self.enable() + def uninstall(self): + """De-configure and uninstall the app.""" + super().uninstall() + privileged.uninstall() + class GitwebWebserverAuth(Webserver): """Component to handle Gitweb authentication webserver configuration.""" diff --git a/plinth/modules/gitweb/privileged.py b/plinth/modules/gitweb/privileged.py index 9717ff616..bcd2dc5ce 100644 --- a/plinth/modules/gitweb/privileged.py +++ b/plinth/modules/gitweb/privileged.py @@ -4,6 +4,7 @@ import configparser import logging import os +import pathlib import re import shutil import subprocess @@ -386,3 +387,10 @@ def delete_repo(name: str): repo = validate_repo_name(name) repo_path = os.path.join(GIT_REPO_PATH, repo) shutil.rmtree(repo_path) + + +@privileged +def uninstall(): + """Remove git repositories.""" + for item in pathlib.Path(GIT_REPO_PATH).glob('*'): + shutil.rmtree(item, ignore_errors=True)