From 56c3c1faa69cab2854edefd062cb44c4fa84d456 Mon Sep 17 00:00:00 2001
From: Renzo Frigato <rfrigato@stanford.edu>
Date: Wed, 9 Dec 2015 10:37:10 -0800
Subject: [PATCH] move filename logic and add comment

---
 api/files.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/api/files.py b/api/files.py
index cfcfc401..ce215ab9 100644
--- a/api/files.py
+++ b/api/files.py
@@ -34,8 +34,6 @@ def getHashingFieldStorage(upload_dir, hash_alg):
     class HashingFieldStorage(cgi.FieldStorage):
         bufsize = 2**20
         def make_file(self, binary=None):
-            if not self.filename:
-                return self.file
             self.open_file = HashingFile(os.path.join(upload_dir, os.path.basename(self.filename)), hash_alg)
             return self.open_file
 
@@ -43,8 +41,11 @@ def getHashingFieldStorage(upload_dir, hash_alg):
         # _FieldStorage__file is the private variable __file of the same class
         def _FieldStorage__write(self, line):
             if self._FieldStorage__file is not None:
-                self.file = self.make_file('')
-                self.file.write(self._FieldStorage__file.getvalue())
+                # use the make_file method only if the form includes a filename
+                # e.g. do not create a file and a hash for the form metadata.
+                if self.filename:
+                    self.file = self.make_file('')
+                    self.file.write(self._FieldStorage__file.getvalue())
                 self._FieldStorage__file = None
             self.file.write(line)
 
-- 
GitLab