Exemplo n.º 1
0
    def scan_dir(self, mdid, direct, udfmode=False):
        """Compares one directory between metadata and disk."""
        log_info("scan dir: %r  mdid: %s", direct, mdid)

        # get the share to get only a subset of mdids
        for share in self._get_volumes():
            if direct.startswith(share.path):
                break
        else:
            # not in RW shares; let's check RO shares, otherwise it's an error

            for share in self._get_volumes(access_level="View"):
                if direct.startswith(share.path):
                    return
            log_error("The received path is not in any share!")
            raise ValueError("The received path is not in any share!")

        # uglier than path_exists and isdir, but only hit the disk once
        stat_result = get_stat(direct)
        if stat_result is None:
            m = "The received path is not in disk: path %r  mdid %s"
            log_debug(m, direct, mdid)
            # it's better to delay the rescan some miliseconds, as if a
            # directory was moved, it's better to leave stuff some time to
            # settle down
            reactor.callLater(.1, self._send_scan_error, mdid, udfmode)
            return
        elif not stat.S_ISDIR(stat_result.st_mode):
            m = "The path is in disk but it's not a dir: %r" % direct
            log_error(m)
            raise ValueError(m)

        # No, 'share' is surely defined; pylint: disable-msg=W0631
        self._queue.appendleft((share, direct, mdid, udfmode))
        return self._queue_scan()
Exemplo n.º 2
0
        def scan():
            """The scan, really."""

            log_debug("scanning the dir %r", dirpath)
            dircontent = listdir(dirpath)

            # get the info from disk
            dnames = []
            fnames = []
            for something in dircontent:
                fullname = os.path.join(dirpath, something)
                stat_result = get_stat(fullname)
                if stat_result is None:
                    # gone between the listdir and now
                    continue
                if is_link(fullname):
                    log_info("Ignoring path as it's a symlink: %r", fullname)
                    continue
                if not is_valid_name(fullname):
                    m = "Ignoring path because it's invalid (non utf8): %r"
                    log_info(m, fullname)
                    continue
                if not access(fullname):
                    log_warning("Ignoring path as we don't have enough "
                                "permissions to track it: %r", fullname)
                    continue

                if stat.S_ISDIR(stat_result.st_mode):
                    dnames.append(something)
                elif stat.S_ISREG(stat_result.st_mode):
                    fnames.append(something)
                else:
                    log_warning("Path: %r isn't a dir, file or symlink.",
                                fullname)

            events, to_scan_later = self._compare(dirpath, dnames, fnames,
                                                  share)
            to_later.extend(to_scan_later)
            return events