Esempio n. 1
0
/* make sure pkg isn't conflicted with what's already in the transaction */
slapt_pkg_list_t *slapt_is_conflicted(slapt_transaction_t *tran,
                                      slapt_pkg_list_t *avail_pkgs,
                                      slapt_pkg_list_t *installed_pkgs,
                                      slapt_pkg_info_t *pkg)
{
  unsigned int i;
  slapt_pkg_list_t *conflicts = NULL;
  slapt_pkg_list_t *conflicts_in_transaction = slapt_init_pkg_list();

  /* if conflicts exist, check to see if they are installed
     or in the current transaction
  */
  conflicts = slapt_get_pkg_conflicts(avail_pkgs,installed_pkgs,pkg);
  for (i = 0; i < conflicts->pkg_count; ++i) {
    slapt_pkg_info_t *p = conflicts->pkgs[i];

    if ( slapt_search_upgrade_transaction(tran,p) == 1
        || slapt_get_newest_pkg(tran->install_pkgs,p->name) != NULL
    ) {
      printf(gettext("%s, which is to be installed, conflicts with %s\n"), p->name,pkg->name);

      slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
    }
    if (slapt_get_newest_pkg(installed_pkgs,p->name) != NULL) {
      printf(gettext("Installed %s conflicts with %s\n"), p->name,pkg->name);

      slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
    }
  }

  slapt_free_pkg_list(conflicts);

  return conflicts_in_transaction;
}
Esempio n. 2
0
END_TEST


START_TEST (test_pkg_search)
{
  slapt_pkg_info_t *p         = NULL;
  slapt_pkg_list_t *l    = NULL;
  slapt_pkg_list_t *list = slapt_init_pkg_list();
  slapt_add_pkg_to_pkg_list(list, &pkg);

  p = slapt_get_newest_pkg(list, "gslapt");
  fail_if (p == NULL);

  p = slapt_get_exact_pkg(list, "gslapt", "0.3.15-i386-1");
  fail_if (p == NULL);

  p = slapt_get_pkg_by_details(list, "gslapt", "0.3.15-i386-1", ".");
  fail_if (p == NULL);

  l = slapt_search_pkg_list(list, "^gslapt$");
  fail_if (l == NULL);
  fail_unless (l->pkg_count == 1);

  slapt_free_pkg_list(list);

}
Esempio n. 3
0
/**
 * 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);
}
Esempio n. 4
0
/* 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;
}
Esempio n. 5
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);
}
Esempio n. 6
0
END_TEST


START_TEST (test_dependency)
{
  unsigned int i                    = 0;
  FILE *fh                          = NULL;
  slapt_pkg_info_t *p               = NULL;
  slapt_pkg_list_t *avail           = NULL;
  slapt_pkg_list_t *required_by     = slapt_init_pkg_list ();
  slapt_pkg_list_t *installed       = slapt_init_pkg_list ();
  slapt_pkg_list_t *pkgs_to_install = slapt_init_pkg_list ();
  slapt_pkg_list_t *pkgs_to_remove  = slapt_init_pkg_list ();
  slapt_pkg_list_t *conflicts       = NULL,
                   *deps            = slapt_init_pkg_list ();
  slapt_pkg_err_list_t *conflict    = slapt_init_pkg_err_list (),
                       *missing     = slapt_init_pkg_err_list ();
  slapt_rc_config *rc               = slapt_read_rc_config ("./data/rc1");
  
  fh = fopen ("data/avail_deps", "r");
  fail_unless (fh != NULL);
  avail = slapt_parse_packages_txt (fh);
  fclose (fh);

  fh = fopen ("data/installed_deps", "r");
  fail_unless (fh != NULL);
  installed = slapt_parse_packages_txt (fh);
  fclose (fh);

  /*
     dependency tests
  */
  p = slapt_get_newest_pkg(avail, "slapt-src");
  fail_unless (p != NULL);
  i = slapt_get_pkg_dependencies (rc, avail, installed, p, deps, conflict, missing);
  /* we expect 22 deps to return given our current hardcoded data files */
  fail_unless (i != 22);
  /* we should have slapt-get as a dependency for slapt-src */
  fail_unless ( slapt_search_pkg_list(deps, "slapt-get") != NULL);

  /*
     conflicts tests
  */
  /* scim conflicts with ibus */
  p = slapt_get_newest_pkg(avail, "scim");
  fail_unless (p != NULL);
  conflicts = slapt_get_pkg_conflicts (avail, installed, p);
  fail_unless (conflicts != NULL);
  fail_unless (conflicts->pkg_count == 1);
  fail_unless ( strcmp (conflicts->pkgs[0]->name, "ibus") == 0);
  slapt_free_pkg_list (conflicts);

  /*
     required by tests
  */
  /* slapt-get reverse dep test */
  p = slapt_get_newest_pkg(avail, "slapt-get");
  fail_unless (p != NULL);
  required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
  fail_unless (required_by->pkg_count == 5);
  fail_unless ( strcmp (required_by->pkgs[0]->name,"slapt-src") == 0);
  fail_unless ( strcmp (required_by->pkgs[1]->name,"gslapt") == 0);
  fail_unless ( strcmp (required_by->pkgs[2]->name,"foo") == 0);
  fail_unless ( strcmp (required_by->pkgs[3]->name,"boz") == 0);
  fail_unless ( strcmp (required_by->pkgs[4]->name,"bar") == 0);
  slapt_free_pkg_list (required_by);

  /* glib reverse dep test */
  p = slapt_get_newest_pkg(avail, "glib");
  fail_unless (p != NULL);
  required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
  fail_unless (required_by->pkg_count == 2);
  fail_unless ( strcmp (required_by->pkgs[0]->name,"xmms") == 0);
  fail_unless ( strcmp (required_by->pkgs[1]->name,"gtk+") == 0);
  slapt_free_pkg_list (required_by);

  /* glib2 reverse dep test */
  p = slapt_get_newest_pkg(avail, "glib2");
  fail_unless (p != NULL);
  required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
  fail_unless (required_by->pkg_count == 4);
  fail_unless ( strcmp (required_by->pkgs[0]->name,"ConsoleKit") == 0);
  fail_unless ( strcmp (required_by->pkgs[1]->name,"dbus-glib") == 0);
  fail_unless ( strcmp (required_by->pkgs[2]->name,"gslapt") == 0);
  fail_unless ( strcmp (required_by->pkgs[3]->name,"scim") == 0);
  slapt_free_pkg_list (required_by);

  slapt_free_pkg_list (installed);
  slapt_free_pkg_list (pkgs_to_install);
  slapt_free_pkg_list (pkgs_to_remove);
  slapt_free_pkg_list (avail);
  slapt_free_rc_config (rc);
}