From d6abd9b32d0a1c2a25cef56c9405e607eef461cc Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Tue, 1 Feb 2022 21:45:13 -0800 Subject: [PATCH] Ensure directory exists, don't crash if we fail to write We should be creating the directory because the static tree from the repo isn't actually copied into the container, so we can't rely on it existing. And if we can't write it, we should catch that error instead of crashing the whole thing, oops! --- bookwyrm/apps.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bookwyrm/apps.py b/bookwyrm/apps.py index c2dfd4b8..10ccc89f 100644 --- a/bookwyrm/apps.py +++ b/bookwyrm/apps.py @@ -13,11 +13,15 @@ logger = logging.getLogger(__name__) def download_file(url, destination): """Downloads a file to the given path""" try: + # Ensure our destination directory exists + os.makedirs(os.path.dirname(destination)) with urllib.request.urlopen(url) as stream: with open(destination, "b+w") as outfile: outfile.write(stream.read()) except (urllib.error.HTTPError, urllib.error.URLError): logger.error("Failed to download file %s", url) + except OSError: + logger.error("Couldn't open font file %s for writing", destination) class BookwyrmConfig(AppConfig):