Exemplo n.º 1
0
Arquivo: expac.c Projeto: aissat/expac
int main(int argc, char *argv[])
{
  alpm_list_t *results = NULL, *targets = NULL;
  expac_t *expac = NULL;
  int r;

  r = parse_options(&argc, &argv);
  if(r < 0) {
    return 1;
  }

  targets = process_targets(argc, argv);

  r = expac_new(&expac, opt_config_file);
  if(r < 0) {
    return 1;
  }

  results = expac_search(expac, opt_corpus, targets);
  if(results == NULL) {
    return 1;
  }

  for(alpm_list_t *i = results; i; i = i->next) {
    print_pkg(i->data, opt_format);
  }

  alpm_list_free_inner(targets, free);
  alpm_list_free(targets);
  alpm_list_free(results);
  expac_free(expac);

  return 0;
}
Exemplo n.º 2
0
int config_free(config_t *oldconfig)
{
	if(oldconfig == NULL) {
		return -1;
	}

	alpm_list_free(oldconfig->explicit_adds);
	alpm_list_free(oldconfig->explicit_removes);

	alpm_list_free_inner(config->repos, (alpm_list_fn_free) config_repo_free);
	alpm_list_free(config->repos);

	FREELIST(oldconfig->holdpkg);
	FREELIST(oldconfig->ignorepkg);
	FREELIST(oldconfig->ignoregrp);
	FREELIST(oldconfig->assumeinstalled);
	FREELIST(oldconfig->noupgrade);
	FREELIST(oldconfig->noextract);
	free(oldconfig->configfile);
	free(oldconfig->rootdir);
	free(oldconfig->dbpath);
	free(oldconfig->logfile);
	free(oldconfig->gpgdir);
	FREELIST(oldconfig->cachedirs);
	free(oldconfig->xfercommand);
	free(oldconfig->print_format);
	free(oldconfig->arch);
	free(oldconfig);

	return 0;
}
gboolean
pk_backend_transaction_simulate (PkBackend *self, GError **error)
{
	alpm_list_t *data = NULL;
	gchar *prefix;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (alpm != NULL, FALSE);

	if (alpm_trans_prepare (alpm, &data) >= 0) {
		return TRUE;
	}

	switch (alpm_errno (alpm)) {
		case ALPM_ERR_PKG_INVALID_ARCH:
			prefix = alpm_pkg_build_list (data);
			alpm_list_free (data);
			break;

		case ALPM_ERR_UNSATISFIED_DEPS:
			prefix = alpm_miss_build_list (data);
			alpm_list_free_inner (data, alpm_depmissing_free);
			alpm_list_free (data);
			break;

		case ALPM_ERR_CONFLICTING_DEPS:
			prefix = alpm_conflict_build_list (data);
			alpm_list_free_inner (data, alpm_conflict_free);
			alpm_list_free (data);
			break;

		case ALPM_ERR_FILE_CONFLICTS:
			prefix = alpm_fileconflict_build_list (data);
			alpm_list_free_inner (data, alpm_fileconflict_free);
			alpm_list_free (data);
			break;

		default:
			prefix = NULL;
			if (data != NULL) {
				g_warning ("unhandled error %d",
					   alpm_errno (alpm));
			}
			break;
	}

	if (prefix != NULL) {
		alpm_errno_t errno = alpm_errno (alpm);
		g_set_error (error, ALPM_ERROR, errno, "%s: %s", prefix,
			     alpm_strerror (errno));
		g_free (prefix);
	} else {
		alpm_errno_t errno = alpm_errno (alpm);
		g_set_error_literal (error, ALPM_ERROR, errno,
				     alpm_strerror (errno));
	}

	return FALSE;
}
Exemplo n.º 4
0
/** Prepare a transaction. */
int SYMEXPORT alpm_trans_prepare(alpm_handle_t *handle, alpm_list_t **data)
{
	alpm_trans_t *trans;

	/* Sanity checks */
	CHECK_HANDLE(handle, return -1);
	ASSERT(data != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));

	trans = handle->trans;

	ASSERT(trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
	ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(handle, ALPM_ERR_TRANS_NOT_INITIALIZED, -1));

	/* If there's nothing to do, return without complaining */
	if(trans->add == NULL && trans->remove == NULL) {
		return 0;
	}

	alpm_list_t *invalid = check_arch(handle, trans->add);
	if(invalid) {
		if(data) {
			*data = invalid;
		}
		RET_ERR(handle, ALPM_ERR_PKG_INVALID_ARCH, -1);
	}

	if(trans->add == NULL) {
		if(_alpm_remove_prepare(handle, data) == -1) {
			/* pm_errno is set by _alpm_remove_prepare() */
			return -1;
		}
	}	else {
		if(_alpm_sync_prepare(handle, data) == -1) {
			/* pm_errno is set by _alpm_sync_prepare() */
			return -1;
		}
	}


	if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
		_alpm_log(handle, ALPM_LOG_DEBUG, "sorting by dependencies\n");
		if(trans->add) {
			alpm_list_t *add_orig = trans->add;
			trans->add = _alpm_sortbydeps(handle, add_orig, trans->remove, 0);
			alpm_list_free(add_orig);
		}
		if(trans->remove) {
			alpm_list_t *rem_orig = trans->remove;
			trans->remove = _alpm_sortbydeps(handle, rem_orig, NULL, 1);
			alpm_list_free(rem_orig);
		}
	}

	trans->state = STATE_PREPARED;

	return 0;
}
gboolean
pk_backend_transaction_commit (PkBackend *self, GError **error)
{
	alpm_list_t *data = NULL;
	gchar *prefix;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (alpm != NULL, FALSE);

	if (pk_backend_cancelled (self)) {
		return TRUE;
	}

	pk_backend_job_set_allow_cancel (self, FALSE);
	pk_backend_job_set_status (self, PK_STATUS_ENUM_RUNNING);

	if (alpm_trans_commit (alpm, &data) >= 0) {
		return TRUE;
	}

	switch (alpm_errno (alpm)) {
		case ALPM_ERR_FILE_CONFLICTS:
			prefix = alpm_fileconflict_build_list (data);
			alpm_list_free_inner (data, alpm_fileconflict_free);
			alpm_list_free (data);
			break;

		case ALPM_ERR_PKG_INVALID:
		case ALPM_ERR_DLT_INVALID:
			prefix = alpm_string_build_list (data);
			alpm_list_free (data);
			break;

		default:
			prefix = NULL;
			if (data != NULL) {
				g_warning ("unhandled error %d",
					   alpm_errno (alpm));
			}
			break;
	}

	if (prefix != NULL) {
		alpm_errno_t errno = alpm_errno (alpm);
		g_set_error (error, ALPM_ERROR, errno, "%s: %s", prefix,
			     alpm_strerror (errno));
		g_free (prefix);
	} else {
		alpm_errno_t errno = alpm_errno (alpm);
		g_set_error_literal (error, ALPM_ERROR, errno,
				     alpm_strerror (errno));
	}

	return FALSE;
}
Exemplo n.º 6
0
static void target_arg_free (target_arg_t *t)
{
	if (t) {
		if (t->free_fn) {
			alpm_list_free_inner (t->items, (alpm_list_fn_free) t->free_fn);
		}
		alpm_list_free (t->items);
		alpm_list_free (t->args);
		FREE (t);
	}
}
Exemplo n.º 7
0
target_t *target_arg_free (target_arg_t *t)
{
	if (t)
	{
		if (t->free_fn)
			alpm_list_free_inner (t->items, (alpm_list_fn_free) t->free_fn);
		alpm_list_free (t->items);
		alpm_list_free (t->args);
		FREE (t);
	}
	return NULL;
}
Exemplo n.º 8
0
static void _alpm_hook_free(struct _alpm_hook_t *hook)
{
	if(hook) {
		free(hook->name);
		free(hook->desc);
		_alpm_wordsplit_free(hook->cmd);
		alpm_list_free_inner(hook->triggers, (alpm_list_fn_free) _alpm_trigger_free);
		alpm_list_free(hook->triggers);
		alpm_list_free(hook->matches);
		FREELIST(hook->depends);
		free(hook);
	}
}
Exemplo n.º 9
0
static void table_free(alpm_list_t *headers, alpm_list_t *rows)
{
	alpm_list_t *i;

	alpm_list_free_inner(headers, table_free_cell);

	for(i = rows; i; i = alpm_list_next(i)) {
		alpm_list_free_inner(i->data, table_free_cell);
		alpm_list_free(i->data);
	}

	alpm_list_free(headers);
	alpm_list_free(rows);
}
Exemplo n.º 10
0
void package_free(pkg_t *pkg)
{
    free(pkg->filename);
    free(pkg->name);
    free(pkg->version);
    free(pkg->desc);
    free(pkg->url);
    free(pkg->packager);
    free(pkg->md5sum);
    free(pkg->sha256sum);
    free(pkg->base64sig);
    free(pkg->arch);

    alpm_list_free_inner(pkg->groups, free);
    alpm_list_free(pkg->groups);
    alpm_list_free_inner(pkg->licenses, free);
    alpm_list_free(pkg->licenses);
    alpm_list_free_inner(pkg->depends, free);
    alpm_list_free(pkg->depends);
    alpm_list_free_inner(pkg->conflicts, free);
    alpm_list_free(pkg->conflicts);
    alpm_list_free_inner(pkg->provides, free);
    alpm_list_free(pkg->provides);
    alpm_list_free_inner(pkg->optdepends, free);
    alpm_list_free(pkg->optdepends);
    alpm_list_free_inner(pkg->makedepends, free);
    alpm_list_free(pkg->makedepends);
    alpm_list_free_inner(pkg->files, free);
    alpm_list_free(pkg->files);

    free(pkg);
}
Exemplo n.º 11
0
void _alpm_trans_free(alpm_trans_t *trans)
{
    if(trans == NULL) {
        return;
    }

    alpm_list_free_inner(trans->add, (alpm_list_fn_free)_alpm_pkg_free_trans);
    alpm_list_free(trans->add);
    alpm_list_free_inner(trans->remove, (alpm_list_fn_free)_alpm_pkg_free);
    alpm_list_free(trans->remove);

    FREELIST(trans->skip_remove);

    FREE(trans);
}
Exemplo n.º 12
0
static int process_group(alpm_list_t *dbs, const char *group, int error)
{
	int ret = 0;
	alpm_list_t *i;
	alpm_list_t *pkgs = alpm_find_group_pkgs(dbs, group);
	int count = alpm_list_count(pkgs);

	if(!count) {
		printf("target not found: %s\n", group);
		return 1;
	}

	if(error) {
		/* we already know another target errored. there is no reason to prompt the
		 * user here; we already validated the group name so just move on since we
		 * won't actually be installing anything anyway. */
		goto cleanup;
	}

	for(i = pkgs; i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;

		if(process_pkg(pkg) == 1) {
			ret = 1;
			goto cleanup;
		}
	}

cleanup:
	alpm_list_free(pkgs);
	return ret;
}
Exemplo n.º 13
0
static void
pk_backend_config_free (PkBackendConfig *config)
{
	g_return_if_fail (config != NULL);

	g_free (config->arch);
	g_free (config->cleanmethod);
	g_free (config->dbpath);
	g_free (config->gpgdir);
	g_free (config->logfile);
	g_free (config->root);
	g_free (config->xfercmd);

	FREELIST (config->cachedirs);
	FREELIST (config->holdpkgs);
	FREELIST (config->ignoregroups);
	FREELIST (config->ignorepkgs);
	FREELIST (config->localfilesiglevels);
	FREELIST (config->noextracts);
	FREELIST (config->noupgrades);
	FREELIST (config->remotefilesiglevels);

	alpm_list_free_inner (config->sections, pk_backend_config_section_free);
	alpm_list_free (config->sections);

	g_regex_unref (config->xrepo);
	g_regex_unref (config->xarch);
}
Exemplo n.º 14
0
void show_results (void)
{
	if (!results) {
		return;
	}

	alpm_list_fn_cmp fn_cmp = NULL;
	switch (config.sort) {
		case S_NAME:  fn_cmp = (alpm_list_fn_cmp) results_cmp; break;
		case S_VOTE:  fn_cmp = (alpm_list_fn_cmp) results_votes_cmp; break;
		case S_POP:   fn_cmp = (alpm_list_fn_cmp) results_popularity_cmp; break;
		case S_IDATE: fn_cmp = (alpm_list_fn_cmp) results_installdate_cmp; break;
		case S_ISIZE: fn_cmp = (alpm_list_fn_cmp) results_isize_cmp; break;
		case S_REL:   fn_cmp = (alpm_list_fn_cmp) results_relevance_cmp; break;
	}
	if (fn_cmp) {
		results = alpm_list_msort (results, alpm_list_count (results), fn_cmp);
	}

	const alpm_list_nav fn_nav = config.rsort ? alpm_list_previous : alpm_list_next;
	const alpm_list_t *i_first = config.rsort ? alpm_list_last (results) : results;

	for (const alpm_list_t *i = i_first; i; i = fn_nav (i)) {
		const results_t *r = i->data;
		if (r && r->type == R_ALPM_PKG) {
			print_package ("", r->ele, alpm_pkg_get_str);
		} else if (r && r->type == R_AUR_PKG) {
			print_package ("", r->ele, aur_get_str);
		}
	}

	alpm_list_free_inner (results, (alpm_list_fn_free) results_free);
	alpm_list_free (results);
	results = NULL;
}
Exemplo n.º 15
0
/**
 * call-seq:
 *   search(*queries, ...) → an_array
 *
 * Search the database with POSIX regular expressions for packages.
 * === Parameters
 * [*queries (splat)]
 *   A list of strings interpreted as POSIX regular expressions.
 *   For a package to be found, it must match _all_ queries terms,
 *   not just a single one. Each query is matched against both
 *   the package name and the package description, where only
 *   one needs to match for the package to be considered.
 *
 *   Note that the match is not performed by Ruby or even Oniguruma/Onigmo,
 *   but directly in libalpm via the +regexp+ library in C.
 *
 * === Return value
 * An array of Package instances whose names matched _all_ regular expressions.
 */
static VALUE search(int argc, VALUE argv[], VALUE self)
{
  alpm_db_t* p_db = NULL;
  alpm_list_t* targets = NULL;
  alpm_list_t* packages = NULL;
  alpm_list_t* item = NULL;
  VALUE result = rb_ary_new();
  int i;

  Data_Get_Struct(self, alpm_db_t, p_db);

  /* Convert our Ruby array to an alpm_list with C strings */
  for(i=0; i < argc; i++) {
    VALUE term = rb_check_string_type(argv[i]);
    if (!RTEST(term)) {
      rb_raise(rb_eTypeError, "Argument is not a string (#to_str)");
      return Qnil;
    }

    targets = alpm_list_add(targets, StringValuePtr(term));
  }

  /* Perform the query */
  packages = alpm_db_search(p_db, targets);
  if (!packages)
    return result;

  for(item=packages; item; item = alpm_list_next(item))
    rb_ary_push(result, Data_Wrap_Struct(rb_cAlpm_Package, NULL, NULL, item->data));

  alpm_list_free(targets);
  return result;
}
Exemplo n.º 16
0
/**
 * @brief Remove needed packages from the removal transaction.
 *
 * @param handle the context handle
 * @param lp list of missing dependencies caused by the removal transaction
 */
static void remove_prepare_keep_needed(alpm_handle_t *handle, alpm_list_t *lp)
{
	alpm_trans_t *trans = handle->trans;

	/* Remove needed packages (which break dependencies) from target list */
	while(lp != NULL) {
		alpm_list_t *i;
		for(i = lp; i; i = i->next) {
			alpm_depmissing_t *miss = i->data;
			void *vpkg;
			alpm_pkg_t *pkg = alpm_pkg_find(trans->remove, miss->causingpkg);
			if(pkg == NULL) {
				continue;
			}
			trans->remove = alpm_list_remove(trans->remove, pkg, _alpm_pkg_cmp,
					&vpkg);
			pkg = vpkg;
			if(pkg) {
				_alpm_log(handle, ALPM_LOG_WARNING, _("removing %s from target list\n"),
						pkg->name);
				_alpm_pkg_free(pkg);
			}
		}
		alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
		alpm_list_free(lp);
		lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
				trans->remove, NULL, 1);
	}
}
Exemplo n.º 17
0
static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
{
	alpm_list_t *i, *errors = NULL;

	if(!deltas) {
		return 0;
	}

	/* Check integrity of deltas */
	EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_START, NULL, NULL);
	for(i = deltas; i; i = i->next) {
		alpm_delta_t *d = i->data;
		char *filepath = _alpm_filecache_find(handle, d->delta);

		if(_alpm_test_checksum(filepath, d->delta_md5, ALPM_PKG_VALIDATION_MD5SUM)) {
			errors = alpm_list_add(errors, filepath);
		} else {
			FREE(filepath);
		}
	}
	EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_DONE, NULL, NULL);

	if(errors) {
		for(i = errors; i; i = i->next) {
			char *filepath = i->data;
			prompt_to_delete(handle, filepath, ALPM_ERR_DLT_INVALID);
			FREE(filepath);
		}
		alpm_list_free(errors);
		handle->pm_errno = ALPM_ERR_DLT_INVALID;
		return -1;
	}
	return 0;
}
Exemplo n.º 18
0
/**
 * @brief Add dependencies to the removal transaction for cascading.
 *
 * @param handle the context handle
 * @param lp list of missing dependencies caused by the removal transaction
 *
 * @return 0 on success, -1 on error
 */
static int remove_prepare_cascade(alpm_handle_t *handle, alpm_list_t *lp)
{
	alpm_trans_t *trans = handle->trans;

	while(lp) {
		alpm_list_t *i;
		for(i = lp; i; i = i->next) {
			alpm_depmissing_t *miss = i->data;
			alpm_pkg_t *info = _alpm_db_get_pkgfromcache(handle->db_local, miss->target);
			if(info) {
				alpm_pkg_t *copy;
				if(!alpm_pkg_find(trans->remove, info->name)) {
					_alpm_log(handle, ALPM_LOG_DEBUG, "pulling %s in target list\n",
							info->name);
					if(_alpm_pkg_dup(info, &copy) == -1) {
						return -1;
					}
					trans->remove = alpm_list_add(trans->remove, copy);
				}
			} else {
				_alpm_log(handle, ALPM_LOG_ERROR,
						_("could not find %s in database -- skipping\n"), miss->target);
			}
		}
		alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
		alpm_list_free(lp);
		lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
				trans->remove, NULL, 1);
	}
	return 0;
}
static void
pk_backend_transaction_process_new_optdepends (PkBackend *self, alpm_pkg_t *pkg,
					       alpm_pkg_t *old)
{
	alpm_list_t *optdepends;
	const alpm_list_t *i;

	g_return_if_fail (self != NULL);
	g_return_if_fail (pkg != NULL);
	g_return_if_fail (old != NULL);

	optdepends = alpm_list_diff (alpm_pkg_get_optdepends (pkg),
				     alpm_pkg_get_optdepends (old),
				     alpm_depend_compare);
	if (optdepends == NULL) {
		return;
	}

	pk_backend_output (self, "New optional dependencies:\n");

	for (i = optdepends; i != NULL; i = i->next) {
		gchar *depend = alpm_dep_compute_string (i->data);
		gchar *output = g_strdup_printf ("%s\n", depend);
		free (depend);

		pk_backend_output (self, output);
		g_free (output);
	}

	alpm_list_free (optdepends);
}
Exemplo n.º 20
0
static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota)
{
	alpm_list_t *unused = NULL;
	alpm_list_t *vertices;
	alpm_list_t *i;
	vertices = graph_init(deltas, 1);

	for(i = vertices; i; i = i->next) {
		alpm_graph_t *v = i->data;
		alpm_delta_t *vdelta = v->data;
		if(strcmp(vdelta->to, to) == 0)
		{
			v->weight = vdelta->download_size;
		}
	}
	dijkstra(vertices);
	for(i = vertices; i; i = i->next) {
		alpm_graph_t *v = i->data;
		alpm_delta_t *vdelta = v->data;
		if(v->weight > quota) {
			unused = alpm_list_add(unused, vdelta->delta);
		}
	}
	alpm_list_free_inner(vertices, _alpm_graph_free);
	alpm_list_free(vertices);
	return unused;
}
Exemplo n.º 21
0
int pacman_deptest(alpm_list_t *targets)
{
	alpm_list_t *i;
	alpm_list_t *deps = NULL;
	alpm_db_t *localdb = alpm_get_localdb(config->handle);

	for(i = targets; i; i = alpm_list_next(i)) {
		char *target = i->data;

		if(!alpm_find_satisfier(alpm_db_get_pkgcache(localdb), target)) {
			deps = alpm_list_add(deps, target);
		}
	}

	if(deps == NULL) {
		return 0;
	}

	for(i = deps; i; i = alpm_list_next(i)) {
		const char *dep = i->data;

		printf("%s\n", dep);
	}
	alpm_list_free(deps);
	return 127;
}
Exemplo n.º 22
0
static off_t shortest_path(alpm_list_t *vertices, const char *to, alpm_list_t **path)
{
	alpm_list_t *i;
	alpm_graph_t *v = NULL;
	off_t bestsize = 0;
	alpm_list_t *rpath = NULL;

	for(i = vertices; i; i = i->next) {
		alpm_graph_t *v_i = i->data;
		alpm_delta_t *d_i = v_i->data;

		if(strcmp(d_i->to, to) == 0) {
			if(v == NULL || v_i->weight < v->weight) {
				v = v_i;
				bestsize = v->weight;
			}
		}
	}

	while(v != NULL) {
		alpm_delta_t *vdelta = v->data;
		rpath = alpm_list_add(rpath, vdelta);
		v = v->parent;
	}
	*path = alpm_list_reverse(rpath);
	alpm_list_free(rpath);

	return bestsize;
}
Exemplo n.º 23
0
/** Calculates the shortest path from one version to another.
 * The shortest path is defined as the path with the smallest combined
 * size, not the length of the path.
 * @param handle the context handle
 * @param deltas the list of alpm_delta_t * objects that a file has
 * @param to the file to start the search at
 * @param path the pointer to a list location where alpm_delta_t * objects that
 * have the smallest size are placed. NULL is set if there is no path
 * possible with the files available.
 * @return the size of the path stored, or LONG_MAX if path is unfindable
 */
off_t _alpm_shortest_delta_path(alpm_handle_t *handle, alpm_list_t *deltas,
		const char *to, alpm_list_t **path)
{
	alpm_list_t *bestpath = NULL;
	alpm_list_t *vertices;
	off_t bestsize = LONG_MAX;

	if(deltas == NULL) {
		*path = NULL;
		return bestsize;
	}

	_alpm_log(handle, ALPM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to);

	vertices = graph_init(deltas, 0);
	graph_init_size(handle, vertices);
	dijkstra(vertices);
	bestsize = shortest_path(vertices, to, &bestpath);

	_alpm_log(handle, ALPM_LOG_DEBUG, "delta shortest-path search complete : '%jd'\n", (intmax_t)bestsize);

	alpm_list_free_inner(vertices, _alpm_graph_free);
	alpm_list_free(vertices);

	*path = bestpath;
	return bestsize;
}
Exemplo n.º 24
0
/** Find group members across a list of databases.
 * If a member exists in several databases, only the first database is used.
 * IgnorePkg is also handled.
 * @param dbs the list of alpm_db_t *
 * @pram name the name of the group
 * @return the list of alpm_pkg_t * (caller is responsible for alpm_list_free)
 */
alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
		const char *name)
{
	alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL;

	for(i = dbs; i; i = i->next) {
		alpm_db_t *db = i->data;
		alpm_group_t *grp = alpm_db_readgroup(db, name);

		if(!grp)
			continue;

		for(j = grp->packages; j; j = j->next) {
			alpm_pkg_t *pkg = j->data;

			if(_alpm_pkg_find(ignorelist, alpm_pkg_get_name(pkg))) {
				continue;
			}
			if(_alpm_pkg_should_ignore(db->handle, pkg)) {
				ignorelist = alpm_list_add(ignorelist, pkg);
				int install = 0;
				QUESTION(db->handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
						NULL, NULL, &install);
				if(!install)
					continue;
			}
			if(!_alpm_pkg_find(pkgs, alpm_pkg_get_name(pkg))) {
				pkgs = alpm_list_add(pkgs, pkg);
			}
		}
	}
	alpm_list_free(ignorelist);
	return pkgs;
}
Exemplo n.º 25
0
/**
 * walk dependencies, showing dependencies of the target
 */
static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev)
{
	alpm_list_t *deps, *i;

	if(!pkg || ((max_depth >= 0) && (depth->level > max_depth))) {
		return;
	}

	walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));

	if(rev) {
		deps = alpm_pkg_compute_requiredby(pkg);
	} else {
		deps = get_pkg_dep_names(pkg);
	}

	for(i = deps; i; i = alpm_list_next(i)) {
		const char *pkgname = i->data;
		int last = alpm_list_next(i) ? 0 : 1;

		alpm_pkg_t *dep_pkg = alpm_find_dbs_satisfier(handle, dblist, pkgname);

		if(alpm_list_find_str(walked, dep_pkg ? alpm_pkg_get_name(dep_pkg) : pkgname)) {
			/* if we've already seen this package, don't print in "unique" output
			 * and don't recurse */
			if(!unique) {
				print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last);
			}
		} else {
			print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last);
			if(dep_pkg) {
				tdepth d = {
					depth,
					NULL,
					depth->level + 1
				};
				depth->next = &d;
				/* last dep, cut off the limb here */
				if(last) {
					if(depth->prev) {
						depth->prev->next = &d;
						d.prev = depth->prev;
						depth = &d;
					} else {
						d.prev = NULL;
					}
				}
				walk_deps(dblist, dep_pkg, &d, rev);
				depth->next = NULL;
			}
		}
	}

	if(rev) {
		FREELIST(deps);
	} else {
		alpm_list_free(deps);
	}
}
Exemplo n.º 26
0
/**
 * @brief Find the items in list `lhs` that are not present in list `rhs`.
 *
 * @param lhs the first list
 * @param rhs the second list
 * @param fn  the comparison function
 *
 * @return a list containing all items in `lhs` not present in `rhs`
 */
alpm_list_t SYMEXPORT *alpm_list_diff(const alpm_list_t *lhs,
		const alpm_list_t *rhs, alpm_list_fn_cmp fn)
{
	alpm_list_t *left, *right;
	alpm_list_t *ret = NULL;

	left = alpm_list_copy(lhs);
	left = alpm_list_msort(left, alpm_list_count(left), fn);
	right = alpm_list_copy(rhs);
	right = alpm_list_msort(right, alpm_list_count(right), fn);

	alpm_list_diff_sorted(left, right, fn, &ret, NULL);

	alpm_list_free(left);
	alpm_list_free(right);
	return ret;
}
Exemplo n.º 27
0
/* Generates the list of packages we are going to install from the AUR, in
 * topological order.
 *
 * @param hashdb hash database
 * @param graph graph of package strings
 * @param topost stack containing topological order of packages
 */
static alpm_list_t *topo_get_targets(struct pw_hashdb *hashdb, struct graph *graph,
									 struct stack *topost)
{
	int curVertex, cnt = 0;
	const char *pkgname;
	enum pkgfrom_t *from = NULL;
	struct pkgpair pkgpair;
	alpm_list_t *final_targets = NULL;

	pw_printf(PW_LOG_VDEBUG, "\n%sDependency graph:\n%s", color.bold, color.nocolor);
	while (!stack_empty(topost)) {
		stack_pop(topost, &curVertex);
		pkgname = graph_get_vertex_data(graph, curVertex);
		from = hashmap_search(hashdb->pkg_from, (void *) pkgname);

		if (!from) {
			alpm_list_free(final_targets);
			return NULL;
		}

		if (cnt++) {
			pw_printf(PW_LOG_VDEBUG, " -> ");
		}
		switch (*from) {
		case PKG_FROM_LOCAL:
			pw_printf(PW_LOG_VDEBUG, "%s%s (installed)%s", color.bgreen, pkgname,
					  color.nocolor);
			break;
		case PKG_FROM_SYNC:
			pw_printf(PW_LOG_VDEBUG, "%s%s (found in sync)%s", color.bblue, pkgname,
					  color.nocolor);
			break;
		case PKG_FROM_AUR:
			/* Magic happens here */
			if (hash_search(hashdb->aur_outdated, (void *) pkgname)) {
				pw_printf(PW_LOG_VDEBUG, "%s%s (AUR target)%s",
						  color.bred, pkgname, color.nocolor);
				final_targets = alpm_list_add(final_targets, (void *) pkgname);
			} else {
				pkgpair.pkgname = pkgname;
				if (hash_search(hashdb->aur, &pkgpair)) {
					pw_printf(PW_LOG_VDEBUG, "%s%s (installed AUR)%s", color.bblue,
							  pkgname, color.nocolor);
				} else {
					/* New AUR package */
					pw_printf(PW_LOG_VDEBUG, "%s%s (AUR dep)%s", color.bmag, pkgname,
							  color.nocolor);
					final_targets = alpm_list_add(final_targets, (void *) pkgname);
				}
			}
			break;
		}
	}

	pw_printf(PW_LOG_VDEBUG, "\n");
	print_immediate_deps(hashdb);
	return final_targets;
}
Exemplo n.º 28
0
Arquivo: query.c Projeto: moben/pacman
/* search the local database for a matching package */
static int query_search(alpm_list_t *targets)
{
	alpm_list_t *i, *searchlist;
	int freelist;
	alpm_db_t *db_local = alpm_option_get_localdb(config->handle);

	/* if we have a targets list, search for packages matching it */
	if(targets) {
		searchlist = alpm_db_search(db_local, targets);
		freelist = 1;
	} else {
		searchlist = alpm_db_get_pkgcache(db_local);
		freelist = 0;
	}
	if(searchlist == NULL) {
		return 1;
	}

	for(i = searchlist; i; i = alpm_list_next(i)) {
		alpm_list_t *grp;
		alpm_pkg_t *pkg = alpm_list_getdata(i);

		if(!config->quiet) {
			printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
		} else {
			printf("%s", alpm_pkg_get_name(pkg));
		}


		if(!config->quiet) {
			if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
				alpm_list_t *k;
				printf(" (");
				for(k = grp; k; k = alpm_list_next(k)) {
					const char *group = alpm_list_getdata(k);
					printf("%s", group);
					if(alpm_list_next(k)) {
						/* only print a spacer if there are more groups */
						printf(" ");
					}
				}
				printf(")");
			}

			/* we need a newline and initial indent first */
			printf("\n    ");
			indentprint(alpm_pkg_get_desc(pkg), 4);
		}
		printf("\n");
	}

	/* we only want to free if the list was a search list */
	if(freelist) {
		alpm_list_free(searchlist);
	}
	return 0;
}
Exemplo n.º 29
0
/* -M (--maintainer) search. */
int powaur_maint(alpm_list_t *targets)
{
	if (!targets) {
		pw_printf(PW_LOG_ERROR, "argument needed for -M\n");
		return -1;
	} else if (alpm_list_count(targets) > 1) {
		pw_printf(PW_LOG_ERROR, "-M only takes 1 argument\n");
		return -1;
	}

	int ret;
	size_t listsz;
	alpm_list_t *i, *results;
	struct aurpkg_t *pkg;
	CURL *curl;

	curl = curl_easy_new();
	if (!curl) {
		return error(PW_ERR_CURL_INIT);
	}

	/* Clear pwerrno */
	CLEAR_ERRNO();
	results = query_aur(curl, targets->data, AUR_QUERY_MSEARCH);

	if (pwerrno != PW_ERR_OK) {
		ret = -1;
		goto cleanup;
	} else if (!results) {
		printf("No packages found.\n");
		ret = -1;
		goto cleanup;
	}

	/* Sort by alphabetical order */
	listsz = alpm_list_count(results);
	results = alpm_list_msort(results, listsz, aurpkg_name_cmp);

	if (config->sort_votes) {
		results = alpm_list_msort(results, listsz, aurpkg_vote_cmp);
	}

	for (i = results; i; i = i->next) {
		pkg = i->data;
		printf("%saur/%s%s%s %s%s %s(%d)%s\n", color.bmag, color.nocolor,
			   color.bold, pkg->name, color.bgreen, pkg->version,
			   color.byellow, pkg->votes, color.nocolor);
		printf("%s%s\n", TAB, pkg->desc);
	}

cleanup:
	alpm_list_free_inner(results, (alpm_list_fn_free) aurpkg_free);
	alpm_list_free(results);
	curl_easy_cleanup(curl);

	return 0;
}
Exemplo n.º 30
0
int main(int argc, char *argv[]) {
  int ret = 1;
  alpm_handle_t *alpm;
  alpm_list_t *results = NULL, *i;

  alpm = alpm_init();
  if (!alpm) {
    return ret;
  }

  ret = parse_options(argc, argv, alpm);
  if (ret != 0) {
    goto finish;
  }

  /* ensure sane defaults */
  if (!dblist && !opt_localpkg) {
    opt_local = true;
    dblist = alpm_list_add(dblist, db_local);
  }

  results = gather_packages(alpm, targets);
  if (results == NULL) {
    ret = 1;
    goto finish;
  }

  for (i = results; i; i = alpm_list_next(i)) {
    alpm_pkg_t *pkg = i->data;
    ret += print_pkg(pkg, opt_format);
  }
  ret = !!ret; /* clamp to zero/one */

  if(opt_localpkg) {
    alpm_list_free_inner(results, (alpm_list_fn_free)alpm_pkg_free);
  }
  alpm_list_free(results);

finish:
  alpm_list_free(dblist);
  alpm_list_free(targets);
  alpm_release(alpm);
  return ret;
}