Example #1
0
void display_targets(void)
{
	alpm_list_t *i, *targets = NULL;
	alpm_db_t *db_local = alpm_get_localdb(config->handle);

	for(i = alpm_trans_get_add(config->handle); i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;
		pm_target_t *targ = calloc(1, sizeof(pm_target_t));
		if(!targ) return;
		targ->install = pkg;
		targ->remove = alpm_db_get_pkg(db_local, alpm_pkg_get_name(pkg));
		if(alpm_list_find(config->explicit_adds, pkg, pkg_cmp)) {
			targ->is_explicit = 1;
		}
		targets = alpm_list_add(targets, targ);
	}
	for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;
		pm_target_t *targ = calloc(1, sizeof(pm_target_t));
		if(!targ) return;
		targ->remove = pkg;
		if(alpm_list_find(config->explicit_removes, pkg, pkg_cmp)) {
			targ->is_explicit = 1;
		}
		targets = alpm_list_add(targets, targ);
	}

	targets = alpm_list_msort(targets, alpm_list_count(targets), target_cmp);
	_display_targets(targets, config->verbosepkglists);
	FREELIST(targets);
}
Example #2
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;
}
Example #3
0
File: deps.c Project: mineo/pacman
/* Convert a list of pmpkg_t * to a graph structure,
 * with a edge for each dependency.
 * Returns a list of vertices (one vertex = one package)
 * (used by alpm_sortbydeps)
 */
static alpm_list_t *dep_graph_init(alpm_list_t *targets)
{
	alpm_list_t *i, *j;
	alpm_list_t *vertices = NULL;
	/* We create the vertices */
	for(i = targets; i; i = i->next) {
		pmgraph_t *vertex = _alpm_graph_new();
		vertex->data = (void *)i->data;
		vertices = alpm_list_add(vertices, vertex);
	}

	/* We compute the edges */
	for(i = vertices; i; i = i->next) {
		pmgraph_t *vertex_i = i->data;
		pmpkg_t *p_i = vertex_i->data;
		/* TODO this should be somehow combined with alpm_checkdeps */
		for(j = vertices; j; j = j->next) {
			pmgraph_t *vertex_j = j->data;
			pmpkg_t *p_j = vertex_j->data;
			if(_alpm_dep_edge(p_i, p_j)) {
				vertex_i->children =
					alpm_list_add(vertex_i->children, vertex_j);
			}
		}
		vertex_i->childptr = vertex_i->children;
	}
	return vertices;
}
Example #4
0
static alpm_list_t *get_validation_method(alpm_pkg_t *pkg) {
  alpm_list_t *validation = NULL;

  alpm_pkgvalidation_t v = alpm_pkg_get_validation(pkg);

  if(v == ALPM_PKG_VALIDATION_UNKNOWN) {
    return alpm_list_add(validation, "Unknown");
  }

  if(v & ALPM_PKG_VALIDATION_NONE) {
    return alpm_list_add(validation, "None");
  }

  if(v & ALPM_PKG_VALIDATION_MD5SUM) {
    validation = alpm_list_add(validation, "MD5 Sum");
  }
  if(v & ALPM_PKG_VALIDATION_SHA256SUM) {
    validation = alpm_list_add(validation, "SHA256 Sum");
  }
  if(v & ALPM_PKG_VALIDATION_SIGNATURE) {
    validation = alpm_list_add(validation, "Signature");
  }

  return validation;
}
Example #5
0
/* Returns the difference of the provided two lists of files.
 * Pre-condition: both lists are sorted!
 * When done, free the list but NOT the contained data.
 */
alpm_list_t *_alpm_filelist_difference(alpm_filelist_t *filesA,
		alpm_filelist_t *filesB)
{
	alpm_list_t *ret = NULL;
	size_t ctrA = 0, ctrB = 0;

	while(ctrA < filesA->count && ctrB < filesB->count) {
		char *strA = filesA->files[ctrA].name;
		char *strB = filesB->files[ctrB].name;

		int cmp = strcmp(strA, strB);
		if(cmp < 0) {
			/* item only in filesA, qualifies as a difference */
			ret = alpm_list_add(ret, strA);
			ctrA++;
		} else if(cmp > 0) {
			ctrB++;
		} else {
			ctrA++;
			ctrB++;
		}
	}

	/* ensure we have completely emptied pA */
	while(ctrA < filesA->count) {
		ret = alpm_list_add(ret, filesA->files[ctrA].name);
		ctrA++;
	}

	return ret;
}
Example #6
0
/** Splits a string into a list of strings using the chosen character as
 * a delimiter.
 *
 * @param str the string to split
 * @param splitchar the character to split at
 *
 * @return a list containing the duplicated strings
 */
alpm_list_t *strsplit(const char *str, const char splitchar)
{
	alpm_list_t *list = NULL;
	const char *prev = str;
	char *dup = NULL;

	while((str = strchr(str, splitchar))) {
		dup = strndup(prev, (size_t)(str - prev));
		if(dup == NULL) {
			return NULL;
		}
		list = alpm_list_add(list, dup);

		str++;
		prev = str;
	}

	dup = strdup(prev);
	if(dup == NULL) {
		return NULL;
	}
	list = alpm_list_add(list, dup);

	return list;
}
Example #7
0
File: remove.c Project: 7799/pacman
static int remove_target(const char *target)
{
	alpm_pkg_t *pkg;
	alpm_db_t *db_local = alpm_get_localdb(config->handle);
	alpm_list_t *p;

	if((pkg = alpm_db_get_pkg(db_local, target)) != NULL) {
		if(alpm_remove_pkg(config->handle, pkg) == -1) {
			pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target,
					alpm_strerror(alpm_errno(config->handle)));
			return -1;
		}
		config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
		return 0;
	}

		/* fallback to group */
	alpm_group_t *grp = alpm_db_get_group(db_local, target);
	if(grp == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), target);
		return -1;
	}
	for(p = grp->packages; p; p = alpm_list_next(p)) {
		pkg = p->data;
		if(alpm_remove_pkg(config->handle, pkg) == -1) {
			pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target,
					alpm_strerror(alpm_errno(config->handle)));
			return -1;
		}
		config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
	}
	return 0;
}
Example #8
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;
}
Example #9
0
/* Convert a list of alpm_pkg_t * to a graph structure,
 * with a edge for each dependency.
 * Returns a list of vertices (one vertex = one package)
 * (used by alpm_sortbydeps)
 */
static alpm_list_t *dep_graph_init(alpm_handle_t *handle,
		alpm_list_t *targets, alpm_list_t *ignore)
{
	alpm_list_t *i, *j;
	alpm_list_t *vertices = NULL;
	alpm_list_t *localpkgs = alpm_list_diff(
			alpm_db_get_pkgcache(handle->db_local), ignore, ptr_cmp);

	/* We create the vertices */
	for(i = targets; i; i = i->next) {
		alpm_graph_t *vertex = _alpm_graph_new();
		vertex->data = (void *)i->data;
		vertices = alpm_list_add(vertices, vertex);
	}

	/* We compute the edges */
	for(i = vertices; i; i = i->next) {
		alpm_graph_t *vertex_i = i->data;
		alpm_pkg_t *p_i = vertex_i->data;
		/* TODO this should be somehow combined with alpm_checkdeps */
		for(j = vertices; j; j = j->next) {
			alpm_graph_t *vertex_j = j->data;
			alpm_pkg_t *p_j = vertex_j->data;
			if(_alpm_pkg_depends_on(p_i, p_j)) {
				vertex_i->children =
					alpm_list_add(vertex_i->children, vertex_j);
			}
		}

		/* lazily add local packages to the dep graph so they don't
		 * get resolved unnecessarily */
		j = localpkgs;
		while(j) {
			alpm_list_t *next = j->next;
			if(_alpm_pkg_depends_on(p_i, j->data)) {
				alpm_graph_t *vertex_j = _alpm_graph_new();
				vertex_j->data = (void *)j->data;
				vertices = alpm_list_add(vertices, vertex_j);
				vertex_i->children =
					alpm_list_add(vertex_i->children, vertex_j);
				localpkgs = alpm_list_remove_item(localpkgs, j);
				free(j);
			}
			j = next;
		}

		vertex_i->childptr = vertex_i->children;
	}
	alpm_list_free(localpkgs);
	return vertices;
}
Example #10
0
static alpm_list_t *
alpm_list_add_words (alpm_list_t *list, const gchar *words)
{
	gchar *str;

	while ((str = strchr (words, ' ')) != NULL) {
		/* allocate normally */
		gchar *word = malloc ((++str - words) * sizeof (gchar));
		g_strlcpy (word, words, str - words);
		list = alpm_list_add (list, word);
		words = str;
	}

	return alpm_list_add (list, strdup (words));
}
Example #11
0
/* returns package info as list of strings */
static alpm_list_t *create_verbose_row(pm_target_t *target)
{
	char *str;
	off_t size = 0;
	double human_size;
	const char *label;
	alpm_list_t *ret = NULL;

	/* a row consists of the package name, */
	if(target->install) {
		const alpm_db_t *db = alpm_pkg_get_db(target->install);
		if(db) {
			pm_asprintf(&str, "%s/%s", alpm_db_get_name(db), alpm_pkg_get_name(target->install));
		} else {
			pm_asprintf(&str, "%s", alpm_pkg_get_name(target->install));
		}
	} else {
		pm_asprintf(&str, "%s", alpm_pkg_get_name(target->remove));
	}
	ret = alpm_list_add(ret, str);

	/* old and new versions */
	pm_asprintf(&str, "%s",
			target->remove != NULL ? alpm_pkg_get_version(target->remove) : "");
	ret = alpm_list_add(ret, str);

	pm_asprintf(&str, "%s",
			target->install != NULL ? alpm_pkg_get_version(target->install) : "");
	ret = alpm_list_add(ret, str);

	/* and size */
	size -= target->remove ? alpm_pkg_get_isize(target->remove) : 0;
	size += target->install ? alpm_pkg_get_isize(target->install) : 0;
	human_size = humanize_size(size, 'M', 2, &label);
	pm_asprintf(&str, "%.2f %s", human_size, label);
	ret = alpm_list_add(ret, str);

	size = target->install ? alpm_pkg_download_size(target->install) : 0;
	if(size != 0) {
		human_size = humanize_size(size, 'M', 2, &label);
		pm_asprintf(&str, "%.2f %s", human_size, label);
	} else {
		str = NULL;
	}
	ret = alpm_list_add(ret, str);

	return ret;
}
Example #12
0
/* Returns the intersection of the provided two lists of files.
 * Pre-condition: both lists are sorted!
 * When done, free the list but NOT the contained data.
 */
alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
		alpm_filelist_t *filesB)
{
	alpm_list_t *ret = NULL;
	size_t ctrA = 0, ctrB = 0;
	alpm_file_t *arrA = filesA->files, *arrB = filesB->files;

	while(ctrA < filesA->count && ctrB < filesB->count) {
		const char *strA = arrA[ctrA].name, *strB = arrB[ctrB].name;
		int cmp = _alpm_filelist_pathcmp(strA, strB);
		if(cmp < 0) {
			ctrA++;
		} else if(cmp > 0) {
			ctrB++;
		} else {
			/* when not directories, item in both qualifies as an intersect */
			if(strA[strlen(strA) - 1] != '/' || strB[strlen(strB) - 1] != '/') {
				ret = alpm_list_add(ret, arrA[ctrA].name);
			}
			ctrA++;
			ctrB++;
		}
	}

	return ret;
}
Example #13
0
alpm_list_t *alpm_find_backups(alpm_pkg_t *pkg, int everything) /* {{{ */
{
	alpm_list_t *backups = NULL;
	const alpm_list_t *i;
	struct stat st;
	char path[PATH_MAX];

	const char *pkgname = alpm_pkg_get_name(pkg);

	for (i = alpm_pkg_get_backup(pkg); i; i = i->next) {
		const alpm_backup_t *backup = i->data;

		snprintf(path, PATH_MAX, "%s%s", PACMAN_ROOT, backup->name);

		/* check if we can access the file */
		if (access(path, R_OK) != 0) {
			cwr_fprintf(stderr, LOG_WARN, "can't access %s\n", path);
			continue;
		}

		/* check if there is a pacnew/pacsave/pacorig file */
		pacfiles_t pacfiles = check_pacfiles(path);
		if (pacfiles & CONF_PACNEW)
			cwr_fprintf(stderr, LOG_WARN, "pacnew file detected %s\n", path);
		if (pacfiles & CONF_PACSAVE)
			cwr_fprintf(stderr, LOG_WARN, "pacsave file detected %s\n", path);
		if (pacfiles & CONF_PACORIG)
			cwr_fprintf(stderr, LOG_WARN, "pacorig file detected %s\n", path);

		/* filter unmodified files */
		char *hash = get_hash(path);
		if (!everything && STREQ(backup->hash, hash)) {
			free(hash);
			continue;
		}

		cwr_fprintf(stderr, LOG_DEBUG, "found backup: %s\n", path);

		/* mark the file to be operated on then */
		backup_t *b = malloc(sizeof(backup_t));
		memset(b, 0, sizeof(backup_t));

		b->pkgname = pkgname;
		b->hash = backup->hash;
		file_init(&b->system, path, hash);

		/* look for a local copy */
		snprintf(path, PATH_MAX, "%s/%s", pkgname, backup->name);

		size_t status = stat(path, &st);
		if (status == 0 && S_ISREG (st.st_mode)) {
			cwr_fprintf(stderr, LOG_DEBUG, "found local copy: %s\n", path);
			file_init(&b->local, path, NULL);
		}

		backups = alpm_list_add(backups, b);
	}

	return backups;
} /* }}} */
Example #14
0
/* Returns the intersection of the provided two lists of files.
 * Pre-condition: both lists are sorted!
 * When done, free the list but NOT the contained data.
 */
alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
		alpm_filelist_t *filesB)
{
	alpm_list_t *ret = NULL;
	size_t ctrA = 0, ctrB = 0;

	while(ctrA < filesA->count && ctrB < filesB->count) {
		alpm_file_t *fileA = filesA->files + ctrA;
		alpm_file_t *fileB = filesB->files + ctrB;
		const char *strA = fileA->name;
		const char *strB = fileB->name;
		/* skip directories, we don't care about them */
		if(strA[strlen(strA)-1] == '/') {
			ctrA++;
		} else if(strB[strlen(strB)-1] == '/') {
			ctrB++;
		} else {
			int cmp = strcmp(strA, strB);
			if(cmp < 0) {
				ctrA++;
			} else if(cmp > 0) {
				ctrB++;
			} else {
				/* item in both, qualifies as an intersect */
				ret = alpm_list_add(ret, fileA);
				ctrA++;
				ctrB++;
			}
		}
	}

	return ret;
}
Example #15
0
int target_arg_add (target_arg_t *t, const char *s, void *item)
{
	int ret=1;
	if (t && config.just_one)
	{
		if ((t->cmp_fn && alpm_list_find (t->items, item, t->cmp_fn)) ||
		    (!t->cmp_fn && alpm_list_find_ptr (t->items, item)))
			ret = 0;
		else if (t->dup_fn)
			t->items = alpm_list_add (t->items, t->dup_fn (item));
		else
			t->items = alpm_list_add (t->items, item);
		t->args = alpm_list_add (t->args, (void *) s);
	}
	return ret;
}
Example #16
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;
}
Example #17
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;
}
Example #18
0
/**
 * Calculate a set of strings to represent the given GPGME signature summary
 * value. This is a bitmask so you may get any number of strings back.
 * @param sigsum a GPGME signature summary bitmask
 * @return the list of signature summary strings
 */
static alpm_list_t *list_sigsum(gpgme_sigsum_t sigsum)
{
	alpm_list_t *summary = NULL;
	/* The docs say this can be a bitmask...not sure I believe it, but we'll code
	 * for it anyway and show all possible flags in the returned string. */

	/* The signature is fully valid.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_VALID, "valid");
	/* The signature is good.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_GREEN, "green");
	/* The signature is bad.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_RED, "red");
	/* One key has been revoked.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_REVOKED, "key revoked");
	/* One key has expired.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_EXPIRED, "key expired");
	/* The signature has expired.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_SIG_EXPIRED, "sig expired");
	/* Can't verify: key missing.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_MISSING, "key missing");
	/* CRL not available.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_CRL_MISSING, "crl missing");
	/* Available CRL is too old.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_CRL_TOO_OLD, "crl too old");
	/* A policy was not met.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_BAD_POLICY, "bad policy");
	/* A system error occurred.  */
	sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_SYS_ERROR, "sys error");
	/* Fallback case */
	if(!sigsum) {
		summary = alpm_list_add(summary, (void *)"(empty)");
	}
	return summary;
}
static alpm_list_t *
pk_backend_find_requirer (PkBackend *self, alpm_list_t *pkgs, const gchar *name,
			  GError **error)
{
	alpm_pkg_t *requirer;

	g_return_val_if_fail (self != NULL, pkgs);
	g_return_val_if_fail (name != NULL, pkgs);
	g_return_val_if_fail (localdb != NULL, pkgs);

	if (alpm_list_find_pkg (pkgs, name) != NULL) {
		return pkgs;
	}

	/* look for local requirers */
	requirer = alpm_db_get_pkg (localdb, name);

	if (requirer != NULL) {
		pk_backend_pkg (self, requirer, PK_INFO_ENUM_INSTALLED);
		if (pk_backend_get_bool (self, "recursive")) {
			pkgs = alpm_list_add (pkgs, requirer);
		}
	} else {
		int code = ALPM_ERR_PKG_NOT_FOUND;
		g_set_error (error, ALPM_ERROR, code, "%s: %s", name,
			     alpm_strerror (code));
	}

	return pkgs;
}
Example #20
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;
}
Example #21
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;
}
Example #22
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;
}
Example #23
0
/**
 * @brief Add a package removal action to the transaction.
 *
 * @param handle the context handle
 * @param pkg the package to uninstall
 *
 * @return 0 on success, -1 on error
 */
int SYMEXPORT alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg)
{
	const char *pkgname;
	alpm_trans_t *trans;
	alpm_pkg_t *copy;

	/* Sanity checks */
	CHECK_HANDLE(handle, return -1);
	ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
	ASSERT(handle == pkg->handle, 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));

	pkgname = pkg->name;

	if(alpm_pkg_find(trans->remove, pkgname)) {
		RET_ERR(handle, ALPM_ERR_TRANS_DUP_TARGET, -1);
	}

	_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s to the transaction remove list\n",
			pkgname);
	if(_alpm_pkg_dup(pkg, &copy) == -1) {
		return -1;
	}
	trans->remove = alpm_list_add(trans->remove, copy);
	return 0;
}
Example #24
0
static alpm_list_t *gather_packages(alpm_handle_t *alpm, alpm_list_t *targets) {
  alpm_list_t *results = NULL;

  if (opt_localpkg) {
    alpm_list_t *i;

    /* load each target as a package */
    for (i = targets; i; i = alpm_list_next(i)) {
      alpm_pkg_t *pkg;
      int err;

      err = alpm_pkg_load(alpm, i->data, 0, 0, &pkg);
      if (err) {
        fprintf(stderr, "error: %s: %s\n", (const char*)i->data,
            alpm_strerror(alpm_errno(alpm)));
        continue;
      }
      results = alpm_list_add(results, pkg);
    }
  } else {
    results = resolve_pkg(targets);
  }

  return results;
}
Example #25
0
static void sigsum_test_bit(gpgme_sigsum_t sigsum, alpm_list_t **summary,
		gpgme_sigsum_t bit, const char *value)
{
	if(sigsum & bit) {
		*summary = alpm_list_add(*summary, (void *)value);
	}
}
Example #26
0
File: expac.c Project: aissat/expac
static int read_targets_from_file(FILE *in, alpm_list_t **targets)
{
  char line[BUFSIZ];
  int i = 0, end = 0;
  while(!end) {
    line[i] = fgetc(in);

    if(line[i] == EOF)
      end = 1;

    if(isspace(line[i]) || end) {
      line[i] = '\0';
      /* avoid adding zero length arg, if multiple spaces separate args */
      if(i > 0) {
        if(!alpm_list_find_str(*targets, line))
          *targets = alpm_list_add(*targets, strdup(line));
        i = 0;
      }
    } else {
      ++i;
      if(i >= BUFSIZ) {
        fprintf(stderr, "error: buffer overflow on stdin\n");
        return -1;
      }
    }
  }

  return 0;
}
Example #27
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;
}
Example #28
0
static int _alpm_hook_parse_cb(const char *file, int line,
		const char *section, char *key, char *value, void *data)
{
	struct _alpm_hook_cb_ctx *ctx = data;
	alpm_handle_t *handle = ctx->handle;
	struct _alpm_hook_t *hook = ctx->hook;

#define error(...) _alpm_log(handle, ALPM_LOG_ERROR, __VA_ARGS__); return 1;

	if(!section && !key) {
		error(_("error while reading hook %s: %s\n"), file, strerror(errno));
	} else if(!section) {
		error(_("hook %s line %d: invalid option %s\n"), file, line, key);
	} else if(!key) {
		/* beginning a new section */
		if(strcmp(section, "Trigger") == 0) {
			struct _alpm_trigger_t *t;
			CALLOC(t, sizeof(struct _alpm_trigger_t), 1, return 1);
			hook->triggers = alpm_list_add(hook->triggers, t);
		} else if(strcmp(section, "Action") == 0) {
			/* no special processing required */
		} else {
			error(_("hook %s line %d: invalid section %s\n"), file, line, section);
		}
	} else if(strcmp(section, "Trigger") == 0) {
Example #29
0
alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
		alpm_siglevel_t level)
{
	alpm_db_t *db;

	_alpm_log(handle, ALPM_LOG_DEBUG, "registering sync database '%s'\n", treename);

#ifndef HAVE_LIBGPGME
	if(level != 0 && level != ALPM_SIG_USE_DEFAULT) {
		RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL);
	}
#endif

	db = _alpm_db_new(treename, 0);
	if(db == NULL) {
		RET_ERR(handle, ALPM_ERR_DB_CREATE, NULL);
	}
	db->ops = &sync_db_ops;
	db->handle = handle;
	db->siglevel = level;

	sync_db_validate(db);

	handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
	return db;
}
Example #30
0
static gboolean
pk_backend_config_add_server (PkBackendConfig *config,
			      PkBackendConfigSection *section,
			      const gchar *address, GError **e)
{
	gchar *url;

	g_return_val_if_fail (config != NULL, FALSE);
	g_return_val_if_fail (section != NULL, FALSE);
	g_return_val_if_fail (address != NULL, FALSE);

	url = g_regex_replace_literal (config->xrepo, address, -1, 0,
				       section->name, 0, e);
	if (url == NULL) {
		return FALSE;
	}

	if (config->arch != NULL) {
		gchar *temp = url;
		url = g_regex_replace_literal (config->xarch, temp, -1, 0,
					       config->arch, 0, e);
		g_free (temp);

		if (url == NULL) {
			return FALSE;
		}
	} else if (strstr (url, "$arch") != NULL) {
		g_set_error (e, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID,
			     "url contained $arch, which is not set");
	}

	section->servers = alpm_list_add (section->servers, url);

	return TRUE;
}