Describe y create_object_metadata accepts 2 types
Answers questions in review comments posted against: http://review.gluster.org/6157 Signed-off-by: Peter Portante <peter.portante@redhat.com> Change-Id: I96b348b4f54eaeb0d5d641af88cfcbfe961e4950 Reviewed-on: http://review.gluster.org/6161 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
This commit is contained in:
parent
76a173924a
commit
70a4cef96c
@ -326,7 +326,7 @@ def _read_for_etag(fp):
|
|||||||
return etag.hexdigest()
|
return etag.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def _get_etag(path):
|
def _get_etag(path_or_fd):
|
||||||
"""
|
"""
|
||||||
FIXME: It would be great to have a translator that returns the md5sum() of
|
FIXME: It would be great to have a translator that returns the md5sum() of
|
||||||
the file as an xattr that can be simply fetched.
|
the file as an xattr that can be simply fetched.
|
||||||
@ -334,24 +334,34 @@ def _get_etag(path):
|
|||||||
Since we don't have that we should yield after each chunk read and
|
Since we don't have that we should yield after each chunk read and
|
||||||
computed so that we don't consume the worker thread.
|
computed so that we don't consume the worker thread.
|
||||||
"""
|
"""
|
||||||
if isinstance(path, int):
|
if isinstance(path_or_fd, int):
|
||||||
with os.fdopen(os.dup(path), 'rb') as fp:
|
# We are given a file descriptor, so this is an invocation from the
|
||||||
|
# DiskFile.open() method.
|
||||||
|
fd = path_or_fd
|
||||||
|
with os.fdopen(os.dup(fd), 'rb') as fp:
|
||||||
etag = _read_for_etag(fp)
|
etag = _read_for_etag(fp)
|
||||||
os.lseek(path, 0, os.SEEK_SET)
|
os.lseek(fd, 0, os.SEEK_SET)
|
||||||
else:
|
else:
|
||||||
|
# We are given a path to the object when the DiskDir.list_objects_iter
|
||||||
|
# method invokes us.
|
||||||
|
path = path_or_fd
|
||||||
with open(path, 'rb') as fp:
|
with open(path, 'rb') as fp:
|
||||||
etag = _read_for_etag(fp)
|
etag = _read_for_etag(fp)
|
||||||
return etag
|
return etag
|
||||||
|
|
||||||
|
|
||||||
def get_object_metadata(obj_path):
|
def get_object_metadata(obj_path_or_fd):
|
||||||
"""
|
"""
|
||||||
Return metadata of object.
|
Return metadata of object.
|
||||||
"""
|
"""
|
||||||
if isinstance(obj_path, int):
|
if isinstance(obj_path_or_fd, int):
|
||||||
stats = do_fstat(obj_path)
|
# We are given a file descriptor, so this is an invocation from the
|
||||||
|
# DiskFile.open() method.
|
||||||
|
stats = do_fstat(obj_path_or_fd)
|
||||||
else:
|
else:
|
||||||
stats = do_stat(obj_path)
|
# We are given a path to the object when the DiskDir.list_objects_iter
|
||||||
|
# method invokes us.
|
||||||
|
stats = do_stat(obj_path_or_fd)
|
||||||
if not stats:
|
if not stats:
|
||||||
metadata = {}
|
metadata = {}
|
||||||
else:
|
else:
|
||||||
@ -362,7 +372,7 @@ def get_object_metadata(obj_path):
|
|||||||
X_CONTENT_TYPE: DIR_TYPE if is_dir else FILE_TYPE,
|
X_CONTENT_TYPE: DIR_TYPE if is_dir else FILE_TYPE,
|
||||||
X_OBJECT_TYPE: DIR_NON_OBJECT if is_dir else FILE,
|
X_OBJECT_TYPE: DIR_NON_OBJECT if is_dir else FILE,
|
||||||
X_CONTENT_LENGTH: 0 if is_dir else stats.st_size,
|
X_CONTENT_LENGTH: 0 if is_dir else stats.st_size,
|
||||||
X_ETAG: md5().hexdigest() if is_dir else _get_etag(obj_path)}
|
X_ETAG: md5().hexdigest() if is_dir else _get_etag(obj_path_or_fd)}
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
|
|
||||||
@ -421,9 +431,12 @@ def restore_metadata(path, metadata):
|
|||||||
return meta_new
|
return meta_new
|
||||||
|
|
||||||
|
|
||||||
def create_object_metadata(obj_path):
|
def create_object_metadata(obj_path_or_fd):
|
||||||
metadata = get_object_metadata(obj_path)
|
# We must accept either a path or a file descriptor as an argument to this
|
||||||
return restore_metadata(obj_path, metadata)
|
# method, as the diskfile modules uses a file descriptior and the DiskDir
|
||||||
|
# module (for container operations) uses a path.
|
||||||
|
metadata = get_object_metadata(obj_path_or_fd)
|
||||||
|
return restore_metadata(obj_path_or_fd, metadata)
|
||||||
|
|
||||||
|
|
||||||
def create_container_metadata(cont_path):
|
def create_container_metadata(cont_path):
|
||||||
|
Loading…
Reference in New Issue
Block a user