From f205f01afc4beb10b84d2c33c2c244a4c4d71619 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 8 Dec 2019 21:58:18 +0100 Subject: filesystem: Fix error on max file size Move the chmod call into the try block so we always call this when add_file succeeds, otherwise new_file might not be set yet and we will get an UnboundLocalError. --- fbin/file_storage/filesystem.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fbin/file_storage/filesystem.py b/fbin/file_storage/filesystem.py index 07d29db..3a640bb 100644 --- a/fbin/file_storage/filesystem.py +++ b/fbin/file_storage/filesystem.py @@ -24,13 +24,12 @@ class Storage(BaseStorage): new_file = self.add_file(file_hash, uploaded_file.filename, size, user, ip) if new_file: os.rename(temp_path, new_file.get_path()) + if self.app.config.get('DESTINATION_MODE'): + os.chmod(new_file.get_path(), self.app.config.get('DESTINATION_MODE')) return new_file except: os.unlink(temp.name) raise - finally: - if self.app.config.get('DESTINATION_MODE'): - os.chmod(new_file.get_path(), self.app.config.get('DESTINATION_MODE')) def get_file(self, f): path = f.get_path() -- cgit v1.2.3