Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Properly dispose of downloaded ingredient dump

Roland Geider27ce680cbda0
diff --git a/wger/nutrition/management/commands/sync-ingredients-bulk.py b/wger/nutrition/management/commands/sync-ingredients-bulk.py
index 32a269cbf..6a028d648 100644
--- a/wger/nutrition/management/commands/sync-ingredients-bulk.py
+++ b/wger/nutrition/management/commands/sync-ingredients-bulk.py
@@ -81,10 +81,15 @@ class Command(WgerCommand):
except FileNotFoundError as e:
raise CommandError(str(e))
- sync_ingredients_from_dump(
- self.stdout.write,
- file_path=file_path,
- mode=mode,
- style_fn=self.style.SUCCESS,
- show_progress_bar=True,
- )
+ try:
+ sync_ingredients_from_dump(
+ self.stdout.write,
+ file_path=file_path,
+ mode=mode,
+ style_fn=self.style.SUCCESS,
+ show_progress_bar=True,
+ )
+ finally:
+ # Clean up the temp file if no explicit folder was given
+ if not options['folder']:
+ file_path.unlink(missing_ok=True)
diff --git a/wger/nutrition/tasks.py b/wger/nutrition/tasks.py
index aa1174ac2..5a92d9f2e 100644
--- a/wger/nutrition/tasks.py
+++ b/wger/nutrition/tasks.py
@@ -154,7 +154,10 @@ def sync_ingredients_bulk_or_api_task():
"""
try:
file_path = download_ingredient_dump(logger.info)
- sync_ingredients_from_dump(logger.info, file_path)
+ try:
+ sync_ingredients_from_dump(logger.info, file_path)
+ finally:
+ file_path.unlink(missing_ok=True)
except FileNotFoundError:
logger.info('Bulk dump not available, falling back to API sync.')
sync_all_ingredients_chunked_task.delay()