예제 #1
0
    def move(self, source_path, destination_path, user_id, endpoint=None):
        """
        Move a file or container.
        """
        tstart = time.time()
        src_reference = file_utils.get_reference(source_path,
                                                 self.config['home_dir'],
                                                 endpoint)
        dest_reference = file_utils.get_reference(destination_path,
                                                  self.config['home_dir'],
                                                  endpoint)

        req = cs3sp.MoveRequest(source=src_reference,
                                destination=dest_reference)
        res = self.cs3_api.Move(request=req,
                                metadata=[('x-access-token',
                                           self.auth.authenticate(user_id))])

        if res.status.code != cs3code.CODE_OK:
            self.log.error(
                'msg="Failed to move" source="%s" destination="%s" reason="%s"'
                % (source_path, destination_path, res.status.message))
            raise IOError(res.status.message)

        tend = time.time()
        self.log.debug(
            'msg="Invoked move" source="%s" destination="%s" elapsedTimems="%.1f"'
            % (source_path, destination_path, (tend - tstart) * 1000))
예제 #2
0
def renamefile(_endpoint, filepath, newfilepath, userid):
    '''Rename a file from origfilepath to newfilepath using the given userid as access token.'''
    source = cs3spr.Reference(path=filepath)
    destination = cs3spr.Reference(path=newfilepath)
    req = cs3sp.MoveRequest(source=source, destination=destination)
    res = ctx['cs3stub'].Move(request=req,
                              metadata=[('x-access-token', userid)])
    if res.status.code != cs3code.CODE_OK:
        ctx['log'].warning(
            'msg="Failed to rename file" filepath="%s" error="%s"' %
            (filepath, res.status.message))
        raise IOError(res.status.message)
    ctx['log'].debug('msg="Invoked renamefile" result="%s"' % res)