aboutsummarybugs & patchesrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVosjedev <vosje@vosjedev.net>2026-01-26 18:44:07 +0100
committerVosjedev <vosje@vosjedev.net>2026-01-26 18:45:51 +0100
commitd7ef1e16e7ad188fa5ec90b1c8f4a6415a86b26a (patch)
treee9537d4ac9a90e96fdc96778799e55707d94d60f
parent1fbd8c3c4d11c2e9fc95e3b5bee0ddc1e4ac5b99 (diff)
downloaddiscord_image_bridge-d7ef1e16e7ad188fa5ec90b1c8f4a6415a86b26a.tar.gz
discord_image_bridge-d7ef1e16e7ad188fa5ec90b1c8f4a6415a86b26a.tar.bz2
discord_image_bridge-d7ef1e16e7ad188fa5ec90b1c8f4a6415a86b26a.tar.xz
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 <vosje@vosjedev.net>
-rw-r--r--src/discord_image_bridge/utils.py13
1 files changed, 9 insertions, 4 deletions
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