diff options
author | Thiago da Silva <thiago@redhat.com> | 2013-11-12 15:26:10 -0500 |
---|---|---|
committer | Luis Pabon <lpabon@redhat.com> | 2013-11-20 13:38:28 -0800 |
commit | 47f401b2ef0023f57b1fce83b10f9c6a3aa5c757 (patch) | |
tree | 374a6cb7b1e84c43c24074aeb689907a7dcc2c73 /gluster/swift/obj/diskfile.py | |
parent | d65cee2e3bd2fb0fbf49f6a4d55a1480c915278f (diff) |
fix metadata overwrite during a post request
During a post request, the object-server is ovewriting
the existing object metadata. This fix prevents the overwrite
of the system metadata while it allows for the user to
add/remove user metadata
Change-Id: Ic62cd064589b625ee425a9934be8766650622c13
Signed-off-by: Thiago da Silva <thiago@redhat.com>
Reviewed-on: http://review.gluster.org/6254
Reviewed-by: Luis Pabon <lpabon@redhat.com>
Tested-by: Luis Pabon <lpabon@redhat.com>
Signed-off-by: Thiago da Silva <thiago@redhat.com>
Reviewed-on: http://review.gluster.org/6315
Diffstat (limited to 'gluster/swift/obj/diskfile.py')
-rw-r--r-- | gluster/swift/obj/diskfile.py | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py index 6e6856d..cccd5e6 100644 --- a/gluster/swift/obj/diskfile.py +++ b/gluster/swift/obj/diskfile.py @@ -44,7 +44,8 @@ from gluster.swift.common.utils import read_metadata, write_metadata, \ get_object_metadata from gluster.swift.common.utils import X_CONTENT_TYPE, \ X_TIMESTAMP, X_TYPE, X_OBJECT_TYPE, FILE, OBJECT, DIR_TYPE, \ - FILE_TYPE, DEFAULT_UID, DEFAULT_GID, DIR_NON_OBJECT, DIR_OBJECT + FILE_TYPE, DEFAULT_UID, DEFAULT_GID, DIR_NON_OBJECT, DIR_OBJECT, \ + X_ETAG, X_CONTENT_LENGTH from ConfigParser import ConfigParser, NoSectionError, NoOptionError # FIXME: Hopefully we'll be able to move to Python 2.7+ where O_CLOEXEC will @@ -260,7 +261,8 @@ def _adjust_metadata(metadata): # Fix up the metadata to ensure it has a proper value for the # Content-Type metadata, as well as an X_TYPE and X_OBJECT_TYPE # metadata values. - content_type = metadata[X_CONTENT_TYPE] + content_type = metadata.get(X_CONTENT_TYPE, '') + if not content_type: # FIXME: How can this be that our caller supplied us with metadata # that has a content type that evaluates to False? @@ -983,12 +985,39 @@ class DiskFile(object): :raises DiskFileError: this implementation will raise the same errors as the `create()` method. """ - # FIXME: we need to validate system metadata is preserved - metadata = _adjust_metadata(metadata) + metadata = self._keep_sys_metadata(metadata) data_file = os.path.join(self._put_datadir, self._obj) self._threadpool.run_in_thread( write_metadata, data_file, metadata) + def _keep_sys_metadata(self, metadata): + """ + Make sure system metadata is not lost when writing new user metadata + + This method will read the existing metadata and check for system + metadata. If there are any, it should be appended to the metadata obj + the user is trying to write. + """ + orig_metadata = self.read_metadata() + + sys_keys = [X_CONTENT_TYPE, X_ETAG, 'name', X_CONTENT_LENGTH, + X_OBJECT_TYPE, X_TYPE] + + for key in sys_keys: + if key in orig_metadata: + metadata[key] = orig_metadata[key] + + if X_OBJECT_TYPE not in orig_metadata: + if metadata[X_CONTENT_TYPE].lower() == DIR_TYPE: + metadata[X_OBJECT_TYPE] = DIR_OBJECT + else: + metadata[X_OBJECT_TYPE] = FILE + + if X_TYPE not in orig_metadata: + metadata[X_TYPE] = OBJECT + + return metadata + def _unlinkold(self): if self._is_dir: # Marker, or object, directory. |