add null check for source directory (#1248)

This commit is contained in:
Hayden 2022-05-21 11:50:01 -08:00 committed by GitHub
parent 89d609e47b
commit a85fa3fc54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import contextlib
import shutil
import tempfile
import zipfile
@ -27,25 +28,17 @@ class MealieAlphaMigrator(BaseMigrator):
if recipe.get("categories", False):
recipe["recipeCategory"] = recipe.get("categories")
del recipe["categories"]
try:
with contextlib.suppress(KeyError):
del recipe["_id"]
del recipe["date_added"]
except Exception:
pass
# Migration from list to Object Type Data
try:
with contextlib.suppress(KeyError):
if "" in recipe["tags"]:
recipe["tags"] = [tag for tag in recipe["tags"] if tag != ""]
except Exception:
pass
try:
with contextlib.suppress(KeyError):
if "" in recipe["categories"]:
recipe["categories"] = [cat for cat in recipe["categories"] if cat != ""]
except Exception:
pass
if type(recipe["extras"]) == list:
recipe["extras"] = {}
@ -86,6 +79,9 @@ class MealieAlphaMigrator(BaseMigrator):
if dest_dir.exists():
shutil.rmtree(dest_dir)
if source_dir is None:
continue
for dir in source_dir.iterdir():
if dir.is_dir():
shutil.copytree(dir, dest_dir / dir.name)