summaryrefslogtreecommitdiffstats
path: root/gluster/swift/common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gluster/swift/common/utils.py')
-rw-r--r--gluster/swift/common/utils.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/gluster/swift/common/utils.py b/gluster/swift/common/utils.py
index e6f4bcc..3bcd074 100644
--- a/gluster/swift/common/utils.py
+++ b/gluster/swift/common/utils.py
@@ -432,18 +432,19 @@ def _get_etag(path_or_fd):
return etag
-def get_object_metadata(obj_path_or_fd):
+def get_object_metadata(obj_path_or_fd, stats=None):
"""
Return metadata of object.
"""
- if isinstance(obj_path_or_fd, int):
- # We are given a file descriptor, so this is an invocation from the
- # DiskFile.open() method.
- stats = do_fstat(obj_path_or_fd)
- else:
- # 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 isinstance(obj_path_or_fd, int):
+ # We are given a file descriptor, so this is an invocation from the
+ # DiskFile.open() method.
+ stats = do_fstat(obj_path_or_fd)
+ else:
+ # 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:
metadata = {}
@@ -502,8 +503,10 @@ def get_account_metadata(acc_path):
return _add_timestamp(metadata)
-def restore_metadata(path, metadata):
- meta_orig = read_metadata(path)
+def restore_metadata(path, metadata, meta_orig):
+ if not meta_orig:
+ # Container and account metadata
+ meta_orig = read_metadata(path)
if meta_orig:
meta_new = meta_orig.copy()
meta_new.update(metadata)
@@ -514,23 +517,23 @@ def restore_metadata(path, metadata):
return meta_new
-def create_object_metadata(obj_path_or_fd):
+def create_object_metadata(obj_path_or_fd, stats=None, existing_meta={}):
# We must accept either a path or a file descriptor as an argument to this
# 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)
+ metadata_from_stat = get_object_metadata(obj_path_or_fd, stats)
+ return restore_metadata(obj_path_or_fd, metadata_from_stat, existing_meta)
def create_container_metadata(cont_path):
metadata = get_container_metadata(cont_path)
- rmd = restore_metadata(cont_path, metadata)
+ rmd = restore_metadata(cont_path, metadata, {})
return rmd
def create_account_metadata(acc_path):
metadata = get_account_metadata(acc_path)
- rmd = restore_metadata(acc_path, metadata)
+ rmd = restore_metadata(acc_path, metadata, {})
return rmd