From b46b3dc7f292d8a082a2d86485b7d9aaa0f47b7f Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Wed, 20 Nov 2013 16:31:46 -0500 Subject: Fix double close issue in diskfile The DiskWriter was closing the file descriptor when it finished writing but initializing it to None. Therefore, the DiskFile context manager would then try to close it also. Change-Id: I188ec814d025e28c7b89532f0502ebf1d4a20a09 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/6317 Reviewed-by: Peter Portante Reviewed-by: pushpesh sharma Tested-by: pushpesh sharma Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/6487 --- gluster/swift/obj/diskfile.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'gluster') diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py index cccd5e6..3e4c5af 100644 --- a/gluster/swift/obj/diskfile.py +++ b/gluster/swift/obj/diskfile.py @@ -367,6 +367,14 @@ class DiskFileWriter(object): do_fadvise64(self._fd, self._last_sync, diff) self._last_sync = self._upload_size + def close(self): + """ + Close the file descriptor + """ + if self._fd: + do_close(self._fd) + self._fd = None + def write(self, chunk): """ Write a chunk of data to disk. @@ -463,10 +471,9 @@ class DiskFileWriter(object): else: # Success! break - # Close here so the calling context does not have to perform this, - # which keeps all file system operations in the threadpool context. - do_close(self._fd) - self._fd = None + # Close here so the calling context does not have to perform this + # in a thread. + self.close() def put(self, metadata): """ @@ -966,14 +973,9 @@ class DiskFile(object): dw = DiskFileWriter(fd, tmppath, self) yield dw finally: - if dw is not None: - try: - if dw._fd: - do_close(dw._fd) - except OSError: - pass - if dw._tmppath: - do_unlink(dw._tmppath) + dw.close() + if dw._tmppath: + do_unlink(dw._tmppath) def write_metadata(self, metadata): """ -- cgit