From 7c13b1038482d68c2ab581dad16fa81c0a09034e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 9 Jun 2021 18:17:27 +0200 Subject: file_storage.s3: Fix deleting object on file_add error Make sure obj is returned from upload_file so that we can delete it if add_file raises an exception. --- fbin/file_storage/s3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fbin') diff --git a/fbin/file_storage/s3.py b/fbin/file_storage/s3.py index e2dd1ea..71ee1e7 100644 --- a/fbin/file_storage/s3.py +++ b/fbin/file_storage/s3.py @@ -29,10 +29,10 @@ class Storage(BaseStorage): if not size: obj = self.client.ObjectSummary(self.app.config['S3_BUCKET'], key) size = obj.size - return size + return obj, size def store_file(self, uploaded_file, file_hash, user, ip): - size = self.upload_file(uploaded_file, file_hash, user) + obj, size = self.upload_file(uploaded_file, file_hash, user) try: return self.add_file(file_hash, uploaded_file.filename, size, user, ip) except: -- cgit v1.2.3