def update_metadata(self, metadata): assert self.metadata, "Valid container/account metadata should have been created by now" if metadata: new_metadata = self.metadata.copy() if metadata.has_key('X-Account-Meta-Bytes-Add'): content_length = metadata.get('X-Account-Meta-Bytes-Add') bused = new_metadata[X_BYTES_USED] new_metadata[X_BYTES_USED] = int(str(bused)) + int(content_length) elif metadata.has_key('X-Account-Meta-Bytes-Del'): content_length = metadata.get('X-Account-Meta-Bytes-Del') bused = new_metadata[X_BYTES_USED] new_metadata[X_BYTES_USED] = int(str(bused)) - int(content_length) else: new_metadata.update(metadata) del_keys = ['X-Account-Meta-Bytes-Del','X-Account-Meta-Bytes-Add'] for dkey in del_keys: if new_metadata.has_key(dkey): new_metadata.pop(dkey) if new_metadata != self.metadata: meta_write_metadata(self.metafile, new_metadata) self.metadata = new_metadata
def update_container_count(self): if not self.container_info: self.container_info = get_account_details(self.datadir) containers, container_count = self.container_info if X_CONTAINER_COUNT not in self.metadata \ or int(self.metadata[X_CONTAINER_COUNT]) != container_count: self.metadata[X_CONTAINER_COUNT] = container_count meta_write_metadata(self.metafile, self.metadata)
def put(self, metadata): """ Create and write metatdata to directory/container. :param metadata: Metadata to write. """ if not self.dir_exists: mkdirs(self.datadir) os.chown(self.datadir, self.uid, self.gid) meta_write_metadata(self.metafile, metadata) self.metadata = metadata self.dir_exists = True
def update_object_count(self): if not self.object_info: self.object_info = get_container_details(self.datadir) objects, object_count, bytes_used = self.object_info if X_OBJECTS_COUNT not in self.metadata \ or int(self.metadata[X_OBJECTS_COUNT]) != object_count \ or X_BYTES_USED not in self.metadata \ or int(self.metadata[X_BYTES_USED]) != bytes_used: self.metadata[X_OBJECTS_COUNT] = object_count self.metadata[X_BYTES_USED] = bytes_used meta_write_metadata(self.metafile, self.metadata)
def put(self, fd, tmppath, metadata,extension=''): if extension == '.ts': # TombStone marker (deleted) return True metadata[X_TYPE] = OBJECT if extension == '.meta': # Metadata recorded separately from the file self.meta_put_metadata(metadata) return True # Check if directory already exists. if self.is_dir: self.logger.error('Directory already exists %s/%s' % \ (self.datadir , self.obj)) return False meta_write_metadata(self.metafile, metadata) if X_CONTENT_LENGTH in metadata: self.drop_cache(fd, 0, int(metadata[X_CONTENT_LENGTH])) tpool.execute(os.fsync, fd) if self.obj_path: dir_objs = self.obj_path.split('/') tmp_path = '' if len(dir_objs): for dir_name in dir_objs: if tmp_path: tmp_path = tmp_path + '/' + dir_name else: tmp_path = dir_name if not self.create_dir_object(os.path.join(self.container_path, tmp_path)): self.logger.error("Failed in subdir %s",\ os.path.join(self.container_path,tmp_path)) return False renamer(tmppath, os.path.join(self.datadir, self.obj)) do_chown(os.path.join(self.datadir, self.obj), self.uid, self.gid) self.metadata = metadata return True
def update_object(self, metadata): meta_write_metadata(self.metafile, metadata) self.metadata = metadata
def meta_put_metadata(self, metadata): meta_write_metadata(self.metafile, metadata) self.metadata = metadata
def put_metadata(self, metadata): """ Write metadata to directory/container. """ meta_write_metadata(self.metafile, metadata) self.metadata = metadata