'Ensure that all importables in this dir have been scanned
into the db at least once.'

def ensure_dir_scanned(self, dir, ctlr=None, reporter=None):

    if (dir not in self._have_ensured_scanned_from_dir_cache):
        if (reporter is None):
            reporter = self.lang_zone.db.event_reporter
        if (not callable(reporter)):
            reporter = None
        res_index = self.lang_zone.load_index(dir, 'res_index', {})
        importables = self._importables_from_dir(dir)
        importable_values = [i[0] for i in importables.values() if (i[0] is not None)]
        for base in importable_values:
            if (ctlr and ctlr.is_aborted()):
                log.debug('ctlr    aborted')
                return
            if (base not in res_index):
                if reporter:
                    reporter(("scanning    %s    files    in    '%s'" % (self.lang, dir)))
                    reporter = None
                try:
                    buf = self.mgr.buf_from_path(join(dir, base), lang=self.lang)
                except (EnvironmentError, CodeIntelError) as ex:
                    continue
                if (ctlr is not None):
                    ctlr.info('load    %r', buf)
                buf.scan_if_necessary()
        removed_values = set(res_index.keys()).difference(importable_values)
        for base in removed_values:
            if (ctlr and ctlr.is_aborted()):
                log.debug('ctlr    aborted')
                return
            if reporter:
                reporter(("scanning    %s    files    in    '%s'" % (self.lang, dir)))
                reporter = None
            basename = join(dir, base)
            self.lang_zone.remove_path(basename)
        self._have_ensured_scanned_from_dir_cache.add(dir)
