Ejemplo n.º 1
0
def _read_metadata(dd):
    """ Filter read metadata so that it always returns a tuple that includes
        some kind of timestamp. With 1.4.8 of the Swift integration the
        timestamps were not stored. Here we fabricate timestamps for volumes
        where the existing data has no timestamp (that is, stored data is not
        a tuple), allowing us a measure of backward compatibility.

        FIXME: At this time it does not appear that the timestamps on each
        metadata are used for much, so this should not hurt anything.
    """
    metadata_i = read_metadata(dd)
    metadata = {}
    timestamp = 0
    for key, value in metadata_i.iteritems():
        if not isinstance(value, tuple):
            value = (value, timestamp)
        metadata[key] = value
    return metadata
Ejemplo n.º 2
0
    def get_container_timestamp(self, container):
        cont_path = os.path.join(self.datadir, container)
        metadata = read_metadata(cont_path)

        return int(metadata.get(X_PUT_TIMESTAMP, ('0',0))[0]) or None
Ejemplo n.º 3
0
    def __init__(self, path, device, partition, account, container, obj,
                 logger, keep_data_fp=False, disk_chunk_size=65536,
                 uid=DEFAULT_UID, gid=DEFAULT_GID, iter_hook=None):
        
        self.iter_hook = iter_hook
        self.disk_chunk_size = disk_chunk_size
        
        obj = obj.strip('/')
        if '/' in obj:
            self.obj_path, self.obj = obj.rsplit('/', 1)
        else:
            self.obj_path = ''
            self.obj = obj

        if self.obj_path:
            self.name = '/'.join((container, self.obj_path))
        else:
            self.name = container
            
        #Absolute path for obj directory.
        
        self.datadir = os.path.join(path, device, self.name)
        
        self.device_path = os.path.join(path, device)
        self.container_path = os.path.join(path, device, container)
        self.cntpath = os.path.join(path, device, container)
        
        self.tmpdir = os.path.join(path, device, 'tmp')
        self.logger = logger
        self.metadata = {}
        self.data_file = None
        self.fp = None
        self.iter_etag = None
        self.started_at_0 = False
        self.read_to_eof = False
        self.quarantined_dir = None
        self.keep_cache = False
        self.is_dir = False
        self.is_valid = True
        self.uid = int(uid)
        self.gid = int(gid)
        
        self.data_file = os.path.join(self.datadir, self.obj)
        self.fhr_path = parent_path(self.data_file)
        
        self.cnt_flag = self.cnt_exists()
        if not self.cnt_flag:
            return
        
        if not os.path.exists(self.datadir + '/' + self.obj):
            return
        
        if os.path.isdir(self.datadir + '/' + self.obj):
            self.is_dir = True
        else:
            self.fp = do_open(self.data_file, 'rb')
            if not keep_data_fp:
                self.close(verify_file=False)
                
        
        self.metadata = read_metadata(self.datadir + '/' + self.obj)
        if not self.metadata:
            create_object_metadata(self.datadir + '/' + self.obj)
            self.metadata = read_metadata(self.datadir + '/' + self.obj)


        if not validate_object(self.metadata):
            create_object_metadata(self.datadir + '/' + self.obj)
            self.metadata = read_metadata(self.datadir + '/' +
                                        self.obj)
            
        self.filter_metadata()