mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
kiwix: Don't leave invalid .zim in library after a failed attempt
Tests: - Without patch, upload an invalid zim file, 'Failed to add content'... message is shown. The library's content directory contains that invalid file. Try to add the file again and the message shown is 'File already exists'. - With patch, upload an invalid zim file, 'Failed to add content'... message is shown. The library's content directory does not contain that file. Try to add the file again and the same message is shown. - Functional tests for kiwix pass. Repeating just the test test_add_invalid_zim_file works. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
876cace107
commit
2f33026577
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user