summaryrefslogtreecommitdiffstats
path: root/gluster
diff options
context:
space:
mode:
authorLuis Pabon <lpabon@redhat.com>2013-11-20 16:31:46 -0500
committerLuis Pabon <lpabon@redhat.com>2013-11-22 09:31:50 -0800
commit7095f1c6540612be7df25ece8f6f141b6089a844 (patch)
treedb16881dae6d2bf26a40b544876273605287fb28 /gluster
parentf4c0ab5b986c8caa912b2dd5037351a5a505428d (diff)
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 <lpabon@redhat.com> Reviewed-on: http://review.gluster.org/6317 Reviewed-by: Peter Portante <pportant@redhat.com> Reviewed-by: pushpesh sharma <psharma@redhat.com> Tested-by: pushpesh sharma <psharma@redhat.com>
Diffstat (limited to 'gluster')
-rw-r--r--gluster/swift/obj/diskfile.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py
index 41fe6c6..fdfabb5 100644
--- a/gluster/swift/obj/diskfile.py
+++ b/gluster/swift/obj/diskfile.py
@@ -297,6 +297,14 @@ class DiskWriter(object):
self.last_sync = 0
self.threadpool = threadpool
+ 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 into the temporary file.
@@ -407,7 +415,7 @@ class DiskWriter(object):
break
# Close here so the calling context does not have to perform this
# in a thread.
- do_close(self.fd)
+ self.close()
def put(self, metadata, extension='.data'):
"""
@@ -762,11 +770,7 @@ class DiskFile(SwiftDiskFile):
dw = DiskWriter(self, fd, tmppath, self.threadpool)
yield dw
finally:
- try:
- if dw.fd:
- do_close(dw.fd)
- except OSError:
- pass
+ dw.close()
if dw.tmppath:
do_unlink(dw.tmppath)