From b66b18cb1a4e9e29f70fce6a26a07e4abaf49e7d Mon Sep 17 00:00:00 2001 From: Gunnar Mills Date: Mon, 21 Aug 2017 16:17:21 -0500 Subject: 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 --- module/obmc/wsgi/apps/rest_dbus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/obmc/wsgi') 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 @@ class ImageUploadUtils: 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): -- cgit v1.2.1