Esempio n. 1
0
    def _validate_transfer(self, src, dest):
        src_valid, abs_src = self._validate_external_path(src)
        dest_valid, dest = self._validate_path(dest)
        if not src_valid or not os.path.exists(abs_src) or self.exists(src):
            return (False, u'Invalid transfer source directory %s' % src)
        if not dest_valid:
            return (False, u'Invalid transfer destination directory %s' % dest)

        base_path = self.base_paths[-1]
        abs_dest = os.path.abspath(os.path.join(base_path, dest))
        real_dst = abs_dest
        if os.path.isdir(abs_dest):
            real_dst = os.path.join(abs_dest, asyncfs.basename(abs_src))
            if os.path.exists(real_dst):
                return (False,
                        'Destination path "%s" already exists' % real_dst)

        for entry in yielding_checked_fnwalk(abs_src, lambda p: True):
            path = entry.path
            path = os.path.relpath(path, abs_src)
            dest_path = os.path.abspath(os.path.join(real_dst, path))
            if len(to_bytes(dest_path)) > self.PATH_LEN_LIMIT:
                msg = '%s exceeds path length limit' % dest_path
                return (False, msg)

        return (True, None)
Esempio n. 2
0
    def transfer(self, src, dest):
        success, msg = self._validate_transfer(src, dest)
        if not success:
            return (success, msg)

        abs_src = os.path.abspath(src)
        # Assume that the last mentioned path is expected destination
        base_path = self.base_paths[-1]
        abs_dest = os.path.abspath(os.path.join(base_path, dest))
        logging.debug('Transferring content from "%s" to "%s"' % (abs_src,
                                                                  abs_dest))
        real_dst = abs_dest
        if os.path.isdir(real_dst):
            real_dst = os.path.join(real_dst, asyncfs.basename(abs_src))
        try:
            asyncfs.move(abs_src, abs_dest)
        except (asyncfs.Error, IOError) as e:
            logging.error('Error while transfering content: %s' % str(e))
            success = False
            msg = str(e)

        # Find the deepest parent in hierarchy which has been indexed
        path = os.path.relpath(real_dst, base_path)
        path = self._deepest_indexed_parent(path)
        logging.debug('Indexing %s' % path)
        self._update_db_async(path)
        return (success, msg)