From d7ef1e16e7ad188fa5ec90b1c8f4a6415a86b26a Mon Sep 17 00:00:00 2001 From: Vosjedev Date: Mon, 26 Jan 2026 18:44:07 +0100 Subject: actually save the files due to me not making the directory in the cache it couldn't move the file there. whoops Signed-off-by: Vosjedev --- src/discord_image_bridge/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/discord_image_bridge/utils.py b/src/discord_image_bridge/utils.py index 23a4fb0..49b92a3 100644 --- a/src/discord_image_bridge/utils.py +++ b/src/discord_image_bridge/utils.py @@ -11,6 +11,12 @@ from . import fsmanager download_locks={} +def safe_mkdir(dirname): + try: + return os.mkdir(dirname) + except FileExistsError: + pass + def download_and_cache(url, filename): cherrypy.log("Downloading attachment %s"%filename) try: @@ -25,13 +31,12 @@ def download_and_cache(url, filename): try: tmpname=fsmanager.hash2fname(hash,temp=True) dirname=os.path.dirname(tmpname) - try: - os.mkdir(dirname) - except FileExistsError: - pass + safe_mkdir(dirname) with fsmanager.DataFile(open(tmpname,'wb')) as fd: fd.write(resp.content) fname=fsmanager.hash2fname(hash) + dirname=os.path.dirname(fname) + safe_mkdir(dirname) os.rename(tmpname, fname) return hash, fname -- cgit