summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2016-03-28 15:10:47 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2016-03-28 15:10:47 +0200
commit55f48726d56a22eb409df0c1a091839e92dd4525 (patch)
treed5c0ccd10282c22d07a88b5032cd4622e7e65094
parent9be01802af3cb0c1e933f07291907ae9aaa2acef (diff)
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).
-rwxr-xr-xfbin.py5
1 files 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'):