Example #1
0
    def COPY(self, req):

        drive, part, accountname = split_path(unquote(req.path), 3, 3, True)
        accountname = accountname.split('/')[0]
        dbpath = '%s/%s.db' % (self.root,accountname)
        tx_id = req.environ.get('HTTP_X_TRANS_ID')
        swifttime = str(time.time())
        task_db_insert(dbpath, tx_id, swifttime, 'running', '')
        
        try:
            drive, part, account, src_container, src_direr = split_path(
                unquote(req.path), 4, 5, True)
            validate_device_partition(drive, part)
        except ValueError, err:
            task_db_update(dbpath,'failed','bad request',tx_id)
            return jresponse('-1', 'bad request', req,400)
Example #2
0
 def copy_action(self,src_file,dst_file,req,account,dbpath,tx_id):
     
     try:
         upload_expiration = time.time() + self.max_upload_time
         upload_size = 0
         last_sync = 0
         with dst_file.mkstemp() as (fd, tmppath):
             
             for chunk in src_file:
                 
                 upload_size += len(chunk)
                 if time.time() > upload_expiration:
                     task_db_update(dbpath,'request timeout',tx_id)
                     return jresponse('-1','request timeout',req,408)
                
                 while chunk:
                     written = os.write(fd, chunk)
                     chunk = chunk[written:]
                 # For large files sync every 512MB (by default) written
                 if upload_size - last_sync >= self.bytes_per_sync:
                     tpool.execute(os.fdatasync, fd)
                     drop_buffer_cache(fd, last_sync, upload_size - last_sync)
                     last_sync = upload_size
                 sleep()
             
             dst_file.copy_put(fd, tmppath)
         if dst_file.is_deleted():
             task_db_update(dbpath,'failed','conflict',tx_id)
             return jresponse('-1', 'conflict', req,409)
         
         dst_file.metadata = src_file.metadata
         dst_file.metadata['X-Timestamp'] = req.headers['x-timestamp']
         with dst_file.mkstemp() as (fd, tmppath):
             dst_file.put(fd, tmppath,dst_file.metadata, extension='.meta')
         self.account_update(req, account, src_file.metadata['Content-Length'], add_flag=True)
         task_db_update(dbpath,'success','',tx_id)
         
     except:
         task_db_update(dbpath,'failed','server exception',tx_id)
         syslog.syslog(syslog.LOG_ERR,'object copy: '+str(traceback.format_exc()))
Example #3
0
 task_db_insert(dbpath, tx_id, swifttime, 'running', '')
 
 try:
     drive, part, account, src_container, src_direr = split_path(
         unquote(req.path), 4, 5, True)
     validate_device_partition(drive, part)
 except ValueError, err:
     task_db_update(dbpath,'failed','bad request',tx_id)
     return jresponse('-1', 'bad request', req,400)
 
 try:
     dst_path = req.headers.get('x-copy-dst')
     dst_container, dst_direr = split_path(
         unquote(dst_path), 1, 2, True)
 except ValueError, err:
     task_db_update(dbpath,'failed','bad request',tx_id)
     return jresponse('-1', 'bad request', req,400)
     
 if self.mount_check and not check_mount(self.root, drive):
     return jresponse('-1', 'insufficient storage', req,507)
 
 src_broker = self._get_direr_broker(drive, part, account, src_container,src_direr)
 dst_broker = self._get_direr_broker(drive, part, account, dst_container,dst_direr)
 
 if src_broker.is_deleted():
     task_db_update(dbpath,'failed','not found',tx_id)
     return jresponse('-1', 'not found', req,404)
         
 if not os.path.isdir(src_broker.datadir):
     task_db_update(dbpath,'failed','object ftype error',tx_id)
     return jresponse('-1','object ftype error',req,400)
Example #4
0
        task_db_insert(dbpath, tx_id, swifttime, 'running', '')
        
        try:
            device, partition, account, src_container, src_obj = split_path(
                unquote(req.path), 4, 5, True)
            validate_device_partition(device, partition)
        except ValueError, err:
            task_db_update(dbpath,'failed','bad request',tx_id)
            return jresponse('-1', 'bad request', req,400)
    
        try:
            dst_path = req.headers.get('x-copy-dst')
            dst_container, dst_obj = split_path(
                unquote(dst_path), 1, 2, True)
        except ValueError, err:
            task_db_update(dbpath,'failed','bad request',tx_id)
            return jresponse('-1', 'bad request', req,400)
                        
        if self.mount_check and not check_mount(self.devices, device):
            task_db_update(dbpath,'failed','insufficient storage',tx_id)
            return jresponse('-1', 'insufficient storage', req,507)

        if 'x-timestamp' not in req.headers or \
                    not check_float(req.headers['x-timestamp']):
            self.logger.increment('PUT.errors')
            task_db_update(dbpath,'failed','bad request',tx_id)
            return jresponse('-1', 'bad request', req,400)
            
        src_file = DiskFile(self.devices, device, partition, account, src_container,
                        src_obj, self.logger, keep_data_fp=True,disk_chunk_size=self.disk_chunk_size)