summaryrefslogtreecommitdiffstats
path: root/gluster/swift
diff options
context:
space:
mode:
authorChetan Risbud <crisbud@redhat.com>2013-08-01 19:36:31 +0530
committerLuis Pabon <lpabon@redhat.com>2013-08-28 19:28:19 -0700
commit8737f9e92a5c9dbf0d75e0702c7ab48f287f2761 (patch)
tree0df727348e52f384523a80bf8abdae03b68892a8 /gluster/swift
parent2542fb2398ab8079620a02dc189761d24a2e19e0 (diff)
Handle GET on zero content length failure case.
Added a fake_file class that implements minimal set of functions that are invoked by the code in GET. BUG: 987841 https://bugzilla.redhat.com/show_bug.cgi?id=987841 Change-Id: I5bdf5be1c0c4c8231f34c9be529e6edc83774f2e Signed-off-by: Chetan Risbud <crisbud@redhat.com> Reviewed-on: http://review.gluster.org/5511 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
Diffstat (limited to 'gluster/swift')
-rw-r--r--gluster/swift/common/fs_utils.py19
-rw-r--r--gluster/swift/obj/diskfile.py27
2 files changed, 33 insertions, 13 deletions
diff --git a/gluster/swift/common/fs_utils.py b/gluster/swift/common/fs_utils.py
index b2935d0..afc0cfe 100644
--- a/gluster/swift/common/fs_utils.py
+++ b/gluster/swift/common/fs_utils.py
@@ -24,6 +24,23 @@ from gluster.swift.common.exceptions import FileOrDirNotFoundError, \
NotDirectoryError, GlusterFileSystemOSError, GlusterFileSystemIOError
+class Fake_file(object):
+ def __init__(self, path):
+ self.path = path
+
+ def tell(self):
+ return 0
+
+ def read(self, count):
+ return 0
+
+ def fileno(self):
+ return -1
+
+ def close(self):
+ pass
+
+
def do_walk(*args, **kwargs):
return os.walk(*args, **kwargs)
@@ -205,7 +222,7 @@ def do_open(path, flags, **kwargs):
def do_close(fd):
- if isinstance(fd, file):
+ if isinstance(fd, file) or isinstance(fd, Fake_file):
try:
fd.close()
except IOError as err:
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py
index 4d50488..26852b1 100644
--- a/gluster/swift/obj/diskfile.py
+++ b/gluster/swift/obj/diskfile.py
@@ -35,7 +35,7 @@ from swift.common.exceptions import DiskFileNotExist, DiskFileError, \
from gluster.swift.common.exceptions import GlusterFileSystemOSError
from gluster.swift.common.Glusterfs import mount
from gluster.swift.common.fs_utils import do_fstat, do_open, do_close, \
- do_unlink, do_chown, os_path, do_fsync, do_fchown, do_stat
+ do_unlink, do_chown, os_path, do_fsync, do_fchown, do_stat, Fake_file
from gluster.swift.common.utils import read_metadata, write_metadata, \
validate_object, create_object_metadata, rmobjdir, dir_is_object, \
get_object_metadata
@@ -530,13 +530,20 @@ class DiskFile(SwiftDiskFile):
self._filter_metadata()
- if not self._is_dir and keep_data_fp:
- # The caller has an assumption that the "fp" field of this
- # object is an file object if keep_data_fp is set. However,
- # this implementation of the DiskFile object does not need to
- # open the file for internal operations. So if the caller
- # requests it, we'll just open the file for them.
- self.fp = do_open(data_file, 'rb')
+ if keep_data_fp:
+ if not self._is_dir:
+ # The caller has an assumption that the "fp" field of this
+ # object is an file object if keep_data_fp is set. However,
+ # this implementation of the DiskFile object does not need to
+ # open the file for internal operations. So if the caller
+ # requests it, we'll just open the file for them.
+ self.fp = do_open(data_file, 'rb')
+ else:
+ self.fp = Fake_file(data_file)
+
+ def drop_cache(self, fd, offset, length):
+ if fd >= 0:
+ super(DiskFile, self).drop_cache(fd, offset, length)
def close(self, verify_file=True):
"""
@@ -545,10 +552,6 @@ class DiskFile(SwiftDiskFile):
:param verify_file: Defaults to True. If false, will not check
file to see if it needs quarantining.
"""
- # Marker directory
- if self._is_dir:
- assert not self.fp
- return
if self.fp:
do_close(self.fp)
self.fp = None