/** * backend_get_updates: */ static void backend_get_updates (PkBackend *backend, PkBitfield filters) { guint i; const gchar *package_id; const gchar *new_package_id; slapt_pkg_list_t *installed; slapt_pkg_list_t *available; slapt_pkg_info_t *pkg; slapt_pkg_info_t *newpkg; const gchar *summary; const char *changelog; PkInfoEnum state; pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage (backend, 0); installed = slapt_get_installed_pkgs(); available = slapt_get_available_pkgs(); for (i = 0; i < installed->pkg_count; i++) { pkg = installed->pkgs[i]; newpkg = slapt_get_newest_pkg(available, pkg->name); if (newpkg == NULL) continue; if (slapt_cmp_pkgs(pkg,newpkg) >= 0) continue; package_id = _get_string_from_pkg(pkg); new_package_id = _get_string_from_pkg(newpkg); changelog = slapt_get_pkg_changelog(newpkg); if (changelog != NULL && strstr(changelog, "(* Security fix *)") != NULL) state = PK_INFO_ENUM_SECURITY; else state = PK_INFO_ENUM_NORMAL; summary =_get_pkg_summary(newpkg); pk_backend_package (backend, state, new_package_id, summary); g_free((gpointer) summary); g_free((gpointer) new_package_id); g_free((gpointer) package_id); } slapt_free_pkg_list(available); slapt_free_pkg_list(installed); pk_backend_set_percentage (backend, 100); pk_backend_finished (backend); }
/* needed check to see if a package is conflicted */ int slapt_add_deps_to_trans(const slapt_rc_config *global_config, slapt_transaction_t *tran, slapt_pkg_list_t *avail_pkgs, slapt_pkg_list_t *installed_pkgs, slapt_pkg_info_t *pkg) { unsigned int c; int dep_return = -1; slapt_pkg_list_t *deps = NULL; if (global_config->disable_dep_check == SLAPT_TRUE) return 0; if (pkg == NULL) return 0; deps = slapt_init_pkg_list(); dep_return = slapt_get_pkg_dependencies( global_config,avail_pkgs,installed_pkgs,pkg, deps,tran->conflict_err,tran->missing_err ); /* check to see if there where issues with dep checking */ /* exclude the package if dep check barfed */ if ((dep_return == -1) && (global_config->ignore_dep == SLAPT_FALSE) && (slapt_get_exact_pkg(tran->exclude_pkgs,pkg->name,pkg->version) == NULL) ) { slapt_free_pkg_list(deps); return -1; } /* loop through the deps */ for (c = 0; c < deps->pkg_count; ++c) { unsigned int cindex = 0; slapt_pkg_info_t *dep = deps->pkgs[c]; slapt_pkg_info_t *dep_installed = NULL; slapt_pkg_list_t *conflicts = NULL; /* * the dep wouldn't get this far if it where excluded, * so we don't check for that here */ conflicts = slapt_is_conflicted(tran,avail_pkgs,installed_pkgs,dep); for (cindex = 0; cindex < conflicts->pkg_count;cindex++) { slapt_add_remove_to_transaction(tran,conflicts->pkgs[cindex]); } slapt_free_pkg_list(conflicts); dep_installed = slapt_get_newest_pkg(installed_pkgs,dep->name); if (dep_installed == NULL) { slapt_add_install_to_transaction(tran,dep); } else { /* add only if its a valid upgrade */ if (slapt_cmp_pkgs(dep_installed,dep) < 0) slapt_add_upgrade_to_transaction(tran,dep_installed,dep); } } slapt_free_pkg_list(deps); return 0; }
/** * backend_get_packages: */ static void backend_get_packages (PkBackend *backend, PkBitfield filters) { PkFilterEnum list_order[] = { PK_FILTER_ENUM_INSTALLED, PK_FILTER_ENUM_NOT_INSTALLED, PK_FILTER_ENUM_UNKNOWN }; PkFilterEnum *list_filter; slapt_pkg_list_t *pkglist; slapt_pkg_info_t *pkg; slapt_pkg_info_t *other_pkg; unsigned int i; const gchar *package_id; slapt_pkg_list_t *installed; slapt_pkg_list_t *available; PkInfoEnum state; const char *summary; installed = slapt_get_installed_pkgs(); available = slapt_get_available_pkgs(); pk_backend_set_status (backend, PK_STATUS_ENUM_REQUEST); for (list_filter = list_order; *list_filter != PK_FILTER_ENUM_UNKNOWN; list_filter++) { if (*list_filter == PK_FILTER_ENUM_INSTALLED) { if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) break; pkglist = installed; } else if (*list_filter == PK_FILTER_ENUM_NOT_INSTALLED) { if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) break; pkglist = available; } else { continue; } for (i = 0; i < pkglist->pkg_count; i++) { pkg = pkglist->pkgs[i]; /* check so that we don't show installed pkgs twice */ if (*list_filter == PK_FILTER_ENUM_NOT_INSTALLED && !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) { other_pkg = slapt_get_exact_pkg(installed, pkg->name, pkg->version); if (other_pkg != NULL) { continue; } } /* only display the newest pkg in each pkglist */ if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NEWEST)) { other_pkg = slapt_get_newest_pkg(pkglist, pkg->name); if (slapt_cmp_pkgs(pkg, other_pkg) <= 0) { continue; } } state = pkg->installed ? PK_INFO_ENUM_INSTALLED : PK_INFO_ENUM_AVAILABLE; package_id = _get_string_from_pkg(pkg); summary = _get_pkg_summary(pkg); pk_backend_package (backend, state, package_id, summary); g_free((gpointer) summary); g_free((gpointer) package_id); } } slapt_free_pkg_list(available); slapt_free_pkg_list(installed); pk_backend_finished (backend); }
END_TEST /* http://software.jaos.org/pipermail/slapt-get-devel/2008-November/000762.html * When comparing two packages on mirrors: - The package with the highest priority wins, but: - If the priorities tie, then the package with the highest version number wins. * When comparing an installed package with a mirror package: - If the two packages have *exactly* the same version string, then they compare equal, regardless of priorities. - Otherwise, the package with the highest priority wins. (Taking the priority of the installed package as zero). But: - If the priorities tie, then the package with the highest version number wins. */ START_TEST (test_pkg_version) { slapt_pkg_info_t mirror_pkg1 = { "8598a2a6d683d098b09cdc938de1e3c7", "gslapt", "0.3.15-i386-1", "http://software.jaos.org/slackpacks/11.0/", ".", "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n", "", "", "", ".tgz", 115, 440, SLAPT_PRIORITY_PREFERRED, SLAPT_FALSE }; slapt_pkg_info_t mirror_pkg2 = { "8598a2a6d683d098b09cdc938de1e3c7", "gslapt", "0.3.15-i386-2", "http://software.jaos.org/slackpacks/11.0/", ".", "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n", "", "", "", ".tgz", 115, 440, SLAPT_PRIORITY_DEFAULT, SLAPT_FALSE }; slapt_pkg_info_t installed_pkg = { "8598a2a6d683d098b09cdc938de1e3c7", "gslapt", "0.3.15-i386-1", "http://software.jaos.org/slackpacks/11.0/", ".", "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n", "", "", "", ".tgz", 115, 440, SLAPT_PRIORITY_DEFAULT, SLAPT_TRUE }; /* mirror_pkg1 has a higher priority, and should win */ fail_unless (slapt_cmp_pkgs(&mirror_pkg1,&mirror_pkg2) == 1); /* both have the same priority, mirror_pkg2 has a higher version and should win */ mirror_pkg1.priority = SLAPT_PRIORITY_DEFAULT; fail_unless (slapt_cmp_pkgs(&mirror_pkg1,&mirror_pkg2) == -1); /* installed_pkg and mirror_pkg1 have the exact same version and should be equal regardless of priority */ fail_unless (slapt_cmp_pkgs(&installed_pkg,&mirror_pkg1) == 0); /* installed_pkg has a higher priority and should win, regardless of the fact that mirror_pkg2 has a higher version */ installed_pkg.priority = SLAPT_PRIORITY_PREFERRED; fail_unless (slapt_cmp_pkgs(&installed_pkg,&mirror_pkg2) == 1); /* when the priorities are the same, the package with the higher version always wins */ installed_pkg.priority = SLAPT_PRIORITY_DEFAULT; fail_unless (slapt_cmp_pkgs(&installed_pkg,&mirror_pkg2) == -1); }