summaryrefslogtreecommitdiffstats
path: root/gluster/swift/common/utils.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2013-10-24 16:15:25 -0400
committerLuis Pabon <lpabon@redhat.com>2013-10-28 11:51:51 -0700
commit286a1308db72c5cfdd6ce16aff3f291ebce257c2 (patch)
treeaabb3c54a29d6236f5ade0a229c477378a6c832c /gluster/swift/common/utils.py
parent6b8d7c59195327484ac0f14bd1c29e4f75415e3b (diff)
Rebase to OpenStack Swift Havana (1.10.0)
Change-Id: I90821230a1a7100c74d97cccc9c445251d0f65e7 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/6157 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
Diffstat (limited to 'gluster/swift/common/utils.py')
-rw-r--r--gluster/swift/common/utils.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/gluster/swift/common/utils.py b/gluster/swift/common/utils.py
index 522d307..595a965 100644
--- a/gluster/swift/common/utils.py
+++ b/gluster/swift/common/utils.py
@@ -23,8 +23,9 @@ from hashlib import md5
from eventlet import sleep
import cPickle as pickle
from swift.common.utils import normalize_timestamp
+from gluster.swift.common.exceptions import GlusterFileSystemIOError
from gluster.swift.common.fs_utils import do_rename, do_fsync, os_path, \
- do_stat, do_listdir, do_walk, do_rmdir
+ do_stat, do_fstat, do_listdir, do_walk, do_rmdir
from gluster.swift.common import Glusterfs
X_CONTENT_TYPE = 'Content-Type'
@@ -55,18 +56,6 @@ PICKLE_PROTOCOL = 2
CHUNK_SIZE = 65536
-class GlusterFileSystemOSError(OSError):
- # Having our own class means the name will show up in the stack traces
- # recorded in the log files.
- pass
-
-
-class GlusterFileSystemIOError(IOError):
- # Having our own class means the name will show up in the stack traces
- # recorded in the log files.
- pass
-
-
def read_metadata(path_or_fd):
"""
Helper function to read the pickled metadata from a File/Directory.
@@ -320,6 +309,23 @@ def get_account_details(acc_path):
return container_list, container_count
+def _read_for_etag(fp):
+ etag = md5()
+ while True:
+ chunk = fp.read(CHUNK_SIZE)
+ if chunk:
+ etag.update(chunk)
+ if len(chunk) >= CHUNK_SIZE:
+ # It is likely that we have more data to be read from the
+ # file. Yield the co-routine cooperatively to avoid
+ # consuming the worker during md5sum() calculations on
+ # large files.
+ sleep()
+ else:
+ break
+ return etag.hexdigest()
+
+
def _get_etag(path):
"""
FIXME: It would be great to have a translator that returns the md5sum() of
@@ -328,28 +334,24 @@ def _get_etag(path):
Since we don't have that we should yield after each chunk read and
computed so that we don't consume the worker thread.
"""
- etag = md5()
- with open(path, 'rb') as fp:
- while True:
- chunk = fp.read(CHUNK_SIZE)
- if chunk:
- etag.update(chunk)
- if len(chunk) >= CHUNK_SIZE:
- # It is likely that we have more data to be read from the
- # file. Yield the co-routine cooperatively to avoid
- # consuming the worker during md5sum() calculations on
- # large files.
- sleep()
- else:
- break
- return etag.hexdigest()
+ if isinstance(path, int):
+ with os.fdopen(os.dup(path), 'rb') as fp:
+ etag = _read_for_etag(fp)
+ os.lseek(path, 0, os.SEEK_SET)
+ else:
+ with open(path, 'rb') as fp:
+ etag = _read_for_etag(fp)
+ return etag
def get_object_metadata(obj_path):
"""
Return metadata of object.
"""
- stats = do_stat(obj_path)
+ if isinstance(obj_path, int):
+ stats = do_fstat(obj_path)
+ else:
+ stats = do_stat(obj_path)
if not stats:
metadata = {}
else: