Ejemplo n.º 1
0
/**
 * backend_update_packages:
 */
static void
backend_update_packages (PkBackend *backend, gboolean only_trusted, gchar **package_ids)
{
	guint i;
	guint len;
	const gchar *package_id;
	int ret;

	slapt_pkg_list_t *installed;
	slapt_pkg_list_t *available;
	const gchar *search;
	slapt_pkg_list_t *results = NULL;
	slapt_transaction_t *transaction;
	slapt_pkg_info_t *pkg;
	slapt_pkg_info_t *oldpkg;

	/* FIXME: support only_trusted */

	pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
	pk_backend_set_percentage (backend, 0);

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

	transaction = slapt_init_transaction();

	len = g_strv_length (package_ids);
	for (i=0; i<len; i++) {
	    package_id = package_ids[i];
	    pkg = _get_pkg_from_string(package_id, available, installed);
	    if (pkg == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found");
		continue;
	    }
	    oldpkg = NULL;
	    search = g_strdup_printf("^%s$", pkg->name);
	    results = slapt_search_pkg_list(installed, search);
	    g_free((gpointer) search);
	    if (results->pkg_count > 0) {
		oldpkg = results->pkgs[0];
	    } else {
		continue;
	    }

	    slapt_add_upgrade_to_transaction(transaction, oldpkg, pkg);
	}

	ret = slapt_handle_transaction(_config, transaction);
	if (ret != 0) {
	    pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_ERROR, "install failed");
	}

	slapt_free_transaction(transaction);

	slapt_free_pkg_list(available);
	slapt_free_pkg_list(installed);

	pk_backend_set_percentage (backend, 100);
	pk_backend_finished (backend);
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
                                                   slapt_pkg_info_t *pkg)
{
  unsigned int i;
  slapt_transaction_t *new_tran = NULL;

  if (slapt_search_transaction_by_pkg(tran,pkg) == 0)
    return tran;

  /* since this is a pointer, slapt_malloc before calling init */
  new_tran = slapt_malloc(sizeof *new_tran);
  new_tran->install_pkgs = slapt_malloc(sizeof *new_tran->install_pkgs);
  new_tran->remove_pkgs = slapt_malloc(sizeof *new_tran->remove_pkgs);
  new_tran->upgrade_pkgs = slapt_malloc(sizeof *new_tran->upgrade_pkgs);
  new_tran->exclude_pkgs = slapt_malloc(sizeof *new_tran->exclude_pkgs);
  new_tran = slapt_init_transaction();

  for (i = 0;i < tran->install_pkgs->pkg_count; ++i) {
    slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];

    if (
      strcmp(pkg->name,p->name) == 0 &&
      strcmp(pkg->version,p->version) == 0 &&
      strcmp(pkg->location,p->location) == 0
   ) {
      continue;
    }

    slapt_add_install_to_transaction(new_tran,p);
  }

  for (i = 0;i < tran->remove_pkgs->pkg_count; ++i) {
    slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];

    if (
      strcmp(pkg->name,p->name) == 0 &&
      strcmp(pkg->version,p->version) == 0 &&
      strcmp(pkg->location,p->location) == 0
   ) {
      continue;
    }

    slapt_add_remove_to_transaction(new_tran,tran->remove_pkgs->pkgs[i]);
  }

  for (i = 0;i < tran->upgrade_pkgs->pkg_count; ++i) {
    slapt_pkg_info_t *u = tran->upgrade_pkgs->pkgs[i]->upgrade;
    slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->installed;

    if (
      strcmp(pkg->name,u->name) == 0 &&
      strcmp(pkg->version,u->version) == 0 &&
      strcmp(pkg->location,u->location) == 0
   ) {
      continue;
    }

    slapt_add_upgrade_to_transaction(new_tran, p, u);
  }

  for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
    slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];

    if (
      strcmp(pkg->name,p->name) == 0 &&
      strcmp(pkg->version,p->version) == 0 &&
      strcmp(pkg->location,p->location) == 0
   ) {
      continue;
    }

    slapt_add_exclude_to_transaction(new_tran,p);
  }

  return new_tran;
}