From 55f48726d56a22eb409df0c1a091839e92dd4525 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 28 Mar 2016 15:10:47 +0200 Subject: Auto-delete temporary files by default. This fixes multipart upload where temporary files are created for all fields. Instead we explicitly set the uploaded file itself to not be auto-deleted. This doesn't work on Windows (see NamedTemporaryFile for more details). --- fbin.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fbin.py b/fbin.py index fb037f7..a718ac9 100755 --- a/fbin.py +++ b/fbin.py @@ -30,7 +30,7 @@ class InactiveLoginError(BinError): pass class FileUploadFieldStorage(cgi.FieldStorage): def make_file(self, binary = None): # Make a temporary file in the destination directory, which will be renamed on completion. - return tempfile.NamedTemporaryFile(prefix = 'upload_', dir = settings.file_directory, delete = False) + return tempfile.NamedTemporaryFile(prefix = 'upload_', dir = settings.file_directory, delete = True) class Application(object): def get_or_create_user(self, username, jab_id): @@ -226,8 +226,6 @@ class Application(object): tempfile.tempdir = settings.file_directory form = FileUploadFieldStorage(fp = environ['wsgi.input'], environ = environ) if environ['REQUEST_METHOD'] != 'POST' or not 'file' in form or not 'filename' in form: - if 'file' in form: - form['file'].file.delete = True if user or settings.allow_anonymous_uploads: start_response('200 OK', [('Content-Type', 'text/html')]) return [str(templates.upload(searchList = {'settings': settings, 'user': user}))] @@ -241,6 +239,7 @@ class Application(object): filename = form.getvalue('filename') temp = form['file'].file + temp.delete = False # If the name attribute is missing, assume this is a StringIO object, then create a new temporary file and copy the contents. if not hasattr(temp, 'name'): -- cgit v1.2.3