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')[0] bused, timestamp = new_metadata[X_BYTES_USED] new_metadata[X_BYTES_USED] = (int(str(bused)) + int(content_length), timestamp) elif metadata.has_key('X-Account-Meta-Bytes-Del'): content_length = metadata.get('X-Account-Meta-Bytes-Del')[0] bused, timestamp = new_metadata[X_BYTES_USED] new_metadata[X_BYTES_USED] = (int(str(bused)) - int(content_length), timestamp) 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: write_metadata(self.datadir, 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][0]) != container_count: self.metadata[X_CONTAINER_COUNT] = (container_count, 0) write_metadata(self.datadir, 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) write_metadata(self.datadir, 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][0]) != object_count \ or X_BYTES_USED not in self.metadata \ or int(self.metadata[X_BYTES_USED][0]) != bytes_used: self.metadata[X_OBJECTS_COUNT] = (object_count, 0) self.metadata[X_BYTES_USED] = (bytes_used, 0) write_metadata(self.datadir, 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.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 write_metadata(tmppath, 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 put_metadata(self, metadata): """ Write metadata to directory/container. """ write_metadata(self.datadir, metadata) self.metadata = metadata
def update_object(self, metadata): obj_path = self.datadir + '/' + self.obj write_metadata(obj_path, metadata) self.metadata = metadata
def put_metadata(self, metadata): obj_path = self.datadir + '/' + self.obj write_metadata(obj_path, metadata) self.metadata = metadata