示例#1
0
slapt_transaction_t *slapt_init_transaction(void)
{
  slapt_transaction_t *tran = slapt_malloc(sizeof *tran);

  tran->install_pkgs = slapt_init_pkg_list();
  tran->install_pkgs->free_pkgs = SLAPT_TRUE;

  tran->remove_pkgs = slapt_init_pkg_list();
  tran->remove_pkgs->free_pkgs = SLAPT_TRUE;

  tran->exclude_pkgs = slapt_init_pkg_list();
  tran->exclude_pkgs->free_pkgs = SLAPT_TRUE;

  tran->upgrade_pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs);
  tran->upgrade_pkgs->pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs->pkgs);
  tran->upgrade_pkgs->pkg_count = 0;
  tran->upgrade_pkgs->reinstall_count = 0;


  tran->suggests = slapt_init_list();

  tran->queue = slapt_queue_init();

  tran->conflict_err = slapt_init_pkg_err_list();
  tran->missing_err = slapt_init_pkg_err_list();

  return tran;
}
示例#2
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;
}
示例#3
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);

}
示例#4
0
END_TEST


START_TEST (test_pkg_list)
{
  slapt_pkg_list_t *list = slapt_init_pkg_list();
  fail_if (list == NULL);
  fail_unless (list->pkg_count == 0);

  slapt_add_pkg_to_pkg_list(list, &pkg);
  fail_unless (list->pkg_count == 1);

  slapt_free_pkg_list(list);
  list = NULL;

  list = slapt_get_installed_pkgs();
  fail_if (list == NULL);
  /* fail_unless (list->pkg_count == 0); could be anything */
  slapt_free_pkg_list(list);
  list = NULL;


  /* parse the PACKAGES.TXT file
  slapt_pkg_list_t *slapt_parse_packages_txt(FILE *);
  */

  /*
    return a list of available packages must be already chdir'd to
    rc_config->working_dir.  Otherwise, open a filehandle to the package data
    and pass it to slapt_parse_packages_txt();
  slapt_pkg_list_t *slapt_get_available_pkgs(void);
  */

  /* get a list of obsolete packages
  slapt_pkg_list_t *
    slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,
                              slapt_pkg_list_t *avail_pkgs,
                              slapt_pkg_list_t *installed_pkgs);
  */

  /*
    fill in the md5sum of the package
  void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file);
  */

}
示例#5
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;
}
示例#6
0
/**
 * backend_get_requires:
 */
static void
backend_get_requires (PkBackend *backend, PkBitfield filters, gchar **package_ids, gboolean recursive)
{
	guint i;
	guint len;
	const gchar *package_id;
	gchar *pi;

	slapt_pkg_info_t *pkg;

	slapt_pkg_list_t *installed;
	slapt_pkg_list_t *available;
	slapt_pkg_list_t *to_install;
	slapt_pkg_list_t *to_remove;

	slapt_pkg_list_t *requires;

	PkInfoEnum state;
	const char *summary;

	installed = slapt_get_installed_pkgs();
	available = slapt_get_available_pkgs();
	to_install = slapt_init_pkg_list();
	to_remove = slapt_init_pkg_list();

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	len = g_strv_length (package_ids);
	for (i=0; i<len; i++) {
	    pi = package_ids[i];
	    if (pi == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
		pk_backend_finished (backend);
		return;
	    }
	    pkg = _get_pkg_from_id(pi, available, installed);
	    if (pkg == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found");
		continue;
	    }

	    requires = slapt_is_required_by(_config, available, installed, to_install, to_remove, pkg);

	    for (i = 0; i < requires->pkg_count; i++) {
		pkg = requires->pkgs[i];

		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(requires);
	}

	slapt_free_pkg_list(available);
	slapt_free_pkg_list(installed);
	slapt_free_pkg_list(to_install);
	slapt_free_pkg_list(to_remove);

	pk_backend_finished (backend);
}
示例#7
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);
}
/**
 * backend_get_depends:
 */
static void
backend_get_depends (PkBackend *backend, PkBitfield filters, gchar **package_ids, gboolean recursive)
{
	guint i;
	guint len;
	const gchar *package_id;
	PkPackageId *pi;

	slapt_pkg_info_t *pkg;
	int ret;

	slapt_pkg_list_t *installed;
	slapt_pkg_list_t *available;

	slapt_pkg_list_t *depends;

	slapt_pkg_err_list_t *conflicts;
	slapt_pkg_err_list_t *missing;

	PkInfoEnum state;
	const char *summary;

	installed = slapt_get_installed_pkgs();
	available = slapt_get_available_pkgs();

	conflicts = slapt_init_pkg_err_list();
	missing = slapt_init_pkg_err_list();

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	len = g_strv_length (package_ids);
	for (i=0; i<len; i++) {
	    package_id = package_ids[i];
	    pi = pk_package_id_new_from_string (package_id);
	    if (pi == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
		pk_backend_finished (backend);
		return;
	    }
	    pkg = _get_pkg_from_id(pi, available, installed);
	    pk_package_id_free (pi);
	    if (pkg == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found");
		continue;
	    }

	    depends = slapt_init_pkg_list();

	    ret = slapt_get_pkg_dependencies(_config,
		available, installed, pkg, depends, conflicts, missing);

	    for (i = 0; i < depends->pkg_count; i++) {
		pkg = depends->pkgs[i];

		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(depends);
	}

	slapt_free_pkg_err_list(missing);
	slapt_free_pkg_err_list(conflicts);

	slapt_free_pkg_list(available);
	slapt_free_pkg_list(installed);

	pk_backend_finished (backend);
}