module main import alpm // filter_sync_dbs loads the sync dbs when a filter compares the installed // packages with them. the other filters need no sync data fn filter_sync_dbs(mut ui TransUI, mut handle &alpm.Handle, config ConfigSearch) ![]&alpm.DB { if !(config.foreign || config.native || config.upgrades) { return []&alpm.DB{} } dbs := init_repos(mut handle)! check_sync_fresh(mut ui, mut handle)! return dbs } // pkg_matches_filter is true when an installed package passes every filter // given, the way pacman's -Q filters combine fn pkg_matches_filter(pkg &alpm.Package, config ConfigSearch, sync_dbs []&alpm.DB) bool { reason := pkg.get_reason() if config.deps && reason != .depend { return false } if config.explicit && reason != .explicit { return false } // pacman's -Qt: required by nothing, and optional for nothing either; // twice (-Qtt) what is only optionally required passes too if config.unrequired && (pkg.compute_required_by().len > 0 || (config.unrequired_level < 2 && pkg.compute_optional_for().len > 0)) { return false } if config.foreign || config.native || config.upgrades { sync_pkg := find_repo_pkg(sync_dbs, pkg.get_name()) if config.foreign && sync_pkg != none { return false } if config.native && sync_pkg == none { return false } if config.upgrades { newer := sync_pkg or { return false } if alpm.pkg_vercmp(pkg.get_version(), newer.get_version()) >= 0 { return false } } } return true }