Change ImageUpload to open file once

When uploading an image via REST without a file name,
the image upload code closes the file twice, triggering
the inotify twice.

Resolves openbmc/openbmc#2174

Change-Id: I24ff920c745b865bb4e25468e1895b38abf4a592
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 6560367..91f7f8c 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -684,19 +684,19 @@
         if not filename:
             handle, filename = tempfile.mkstemp(cls.file_suffix,
                                                 cls.file_prefix, cls.file_loc)
-            os.close(handle)
         else:
             filename = os.path.join(cls.file_loc, filename)
-
+            handle = os.open(filename, os.O_WRONLY | os.O_CREAT)
         try:
             file_contents = request.body.read()
             request.body.close()
-            with open(filename, "w") as fd:
-                fd.write(file_contents)
+            os.write(handle, file_contents)
         except (IOError, ValueError), e:
             abort(400, str(e))
         except:
             abort(400, "Unexpected Error")
+        finally:
+            os.close(handle)
 
 
 class ImagePostHandler(RouteHandler):