diff --git a/plinth/modules/kiwix/privileged.py b/plinth/modules/kiwix/privileged.py index cc7ae117f..bcaad19e1 100644 --- a/plinth/modules/kiwix/privileged.py +++ b/plinth/modules/kiwix/privileged.py @@ -33,6 +33,7 @@ def add_package(file_name: str, temporary_file_path: str): aria2c is used for both HTTP and Magnet downloads. """ kiwix.validate_file_name(file_name) + # file_name is verified further by move_uploaded_file() # Moving files to the Kiwix library path ensures that # they can't be removed by other apps or users. @@ -42,7 +43,13 @@ def add_package(file_name: str, temporary_file_path: str): user='root', group='root', permissions=0o644) - _kiwix_manage_add(str(CONTENT_DIR / file_name)) + content_file = CONTENT_DIR / file_name + try: + _kiwix_manage_add(str(CONTENT_DIR / file_name)) + except subprocess.CalledProcessError: + # Remove the uploaded file if we could not added it to library + content_file.unlink() + raise def _kiwix_manage_add(zim_file: str):