mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
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!
This commit is contained in:
parent
0c53f4e003
commit
d6abd9b32d
1 changed files with 4 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue