예제 #1
0
 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
예제 #2
0
    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)
예제 #3
0
    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
예제 #4
0
    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)
예제 #5
0
파일: DiskMeta.py 프로젝트: sun3shines/ufo
    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
예제 #6
0
파일: DiskMeta.py 프로젝트: sun3shines/ufo
 def update_object(self, metadata):
     
     meta_write_metadata(self.metafile, metadata)
     self.metadata = metadata
예제 #7
0
파일: DiskMeta.py 프로젝트: sun3shines/ufo
 def meta_put_metadata(self, metadata):
     
     meta_write_metadata(self.metafile, metadata)
     self.metadata = metadata
예제 #8
0
 def put_metadata(self, metadata):
     """
     Write metadata to directory/container.
     """
     meta_write_metadata(self.metafile, metadata)
     self.metadata = metadata