Esempio n. 1
0
char *concat_str_list (alpm_list_t *l)
{
	char *ret;
	int len=0, j=0;
	alpm_list_t *i;
	if (!l)
	{
		return NULL;
	}
	else
	{
		for(i = l; i; i = alpm_list_next(i)) 
		{
			/* data's len + space for separator */
			len += strlen (i->data) + strlen (config.delimiter);
		}
		if (len)
		{
			len++; /* '\0' at the end */
			CALLOC (ret, len, sizeof (char));
			strcpy (ret, "");
			for(i = l; i; i = alpm_list_next(i)) 
			{
				if (j++>0) strcat (ret, config.delimiter);
				strcat (ret, i->data);
			}
		}
		else
		{
			return NULL;
		}
	}
	return ret;
}
Esempio n. 2
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);
}
Esempio n. 3
0
char *concat_str_list (const alpm_list_t *l)
{
	char *ret = NULL;
	size_t len = 0;
	const size_t sep_len = strlen (config.delimiter);
	int j = 0;

	if (!l) {
		return NULL;
	}

	for (const alpm_list_t *i = l; i; i = alpm_list_next(i)) {
		if (i->data) {
			/* data's len + space for separator */
			len += strlen (i->data) + sep_len;
		}
	}

	if (!len) {
		return NULL;
	}

	len++; /* '\0' at the end */
	CALLOC (ret, len, sizeof (char));
	for (const alpm_list_t *i = l; i; i = alpm_list_next (i)) {
		if (i->data) {
			if (j++ > 0) strcat (ret, config.delimiter);
			strcat (ret, i->data);
		}
	}

	return ret;
}
Esempio n. 4
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;
}
Esempio n. 5
0
void list_display_linebreak(const char *title, const alpm_list_t *list,
		unsigned short maxcols)
{
	unsigned short len = 0;

	if(title) {
		len = (unsigned short)string_length(title) + 1;
		printf("%s ", title);
	}

	if(!list) {
		printf("%s\n", _("None"));
	} else {
		const alpm_list_t *i;
		/* Print the first element */
		indentprint((const char *)list->data, len, maxcols);
		printf("\n");
		/* Print the rest */
		for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
			size_t j;
			for(j = 1; j <= len; j++) {
				printf(" ");
			}
			indentprint((const char *)i->data, len, maxcols);
			printf("\n");
		}
	}
}
Esempio n. 6
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);
	}
}
Esempio n. 7
0
static int files_list(alpm_list_t *syncs, alpm_list_t *targets) {
	alpm_list_t *i, *j;
	int ret = 0, found = 0;

	if(targets != NULL) {
		for(i = targets; i; i = alpm_list_next(i)) {
			char *targ = i->data;
			char *repo = NULL;
			char *c = strchr(targ, '/');

			if(c) {
				if(! *(c + 1)) {
					pm_printf(ALPM_LOG_ERROR,
						_("invalid package: '%s'\n"), targ);
					ret += 1;
					continue;
				}

				repo = strndup(targ, c - targ);
				targ = c + 1;
			}

			for(j = syncs; j; j = alpm_list_next(j)) {
				alpm_pkg_t *pkg;
				alpm_db_t *db = j->data;

				if(repo) {
					if(strcmp(alpm_db_get_name(db), repo) != 0) {
						continue;
					}
				}

				if((pkg = alpm_db_get_pkg(db, targ)) != NULL) {
					found = 1;
					dump_file_list(pkg);
					break;
				}
			}
			if(!found) {
				targ = i->data;
				pm_printf(ALPM_LOG_ERROR,
						_("package '%s' was not found\n"), targ);
				ret += 1;
			}
			free(repo);
		}
	} else {
		for(i = syncs; i; i = alpm_list_next(i)) {
		alpm_db_t *db = i->data;

			for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
				alpm_pkg_t *pkg = j->data;
				dump_file_list(pkg);
			}
		}
	}

	return ret;
}
Esempio n. 8
0
/**
 * Find the max string width of each column. Also determines whether values
 * exist in the column and sets the value in has_data accordingly.
 * @param header a list of header strings
 * @param rows a list of lists of rows as strings
 * @param padding the amount of padding between columns
 * @param totalcols the total number of columns in the header and each row
 * @param widths a pointer to store width data
 * @param has_data a pointer to store whether column has data
 *
 * @return the total width of the table; 0 on failure
 */
static size_t table_calc_widths(const alpm_list_t *header,
		const alpm_list_t *rows, short padding, size_t totalcols,
		size_t **widths, int **has_data)
{
	const alpm_list_t *i;
	size_t curcol, totalwidth = 0, usefulcols = 0;
	size_t *colwidths;
	int *coldata;

	if(totalcols <= 0) {
		return 0;
	}

	colwidths = malloc(totalcols * sizeof(size_t));
	coldata = calloc(totalcols, sizeof(int));
	if(!colwidths || !coldata) {
		return 0;
	}
	/* header determines column count and initial values of longest_strs */
	for(i = header, curcol = 0; i; i = alpm_list_next(i), curcol++) {
		colwidths[curcol] = string_length(i->data);
		/* note: header does not determine whether column has data */
	}

	/* now find the longest string in each column */
	for(i = rows; i; i = alpm_list_next(i)) {
		/* grab first column of each row and iterate through columns */
		const alpm_list_t *j = i->data;
		for(curcol = 0; j; j = alpm_list_next(j), curcol++) {
			const char *str = j->data;
			size_t str_len = string_length(str);

			if(str_len > colwidths[curcol]) {
				colwidths[curcol] = str_len;
			}
			if(str_len > 0) {
				coldata[curcol] = 1;
			}
		}
	}

	for(i = header, curcol = 0; i; i = alpm_list_next(i), curcol++) {
		/* only include columns that have data */
		if(coldata[curcol]) {
			usefulcols++;
			totalwidth += colwidths[curcol];
		}
	}

	/* add padding between columns */
	if(usefulcols > 0) {
		totalwidth += padding * (usefulcols - 1);
	}

	*widths = colwidths;
	*has_data = coldata;
	return totalwidth;
}
Esempio n. 9
0
File: query.c Progetto: 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;
}
Esempio n. 10
0
/**
 * @brief Upgrade a specified list of packages.
 *
 * @param targets a list of packages (as strings) to upgrade
 *
 * @return 0 on success, 1 on failure
 */
int pacman_upgrade(alpm_list_t *targets)
{
	alpm_list_t *i;
	alpm_siglevel_t level = alpm_option_get_default_siglevel(config->handle);

	if(targets == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
		return 1;
	}

	/* Check for URL targets and process them
	 */
	for(i = targets; i; i = alpm_list_next(i)) {
		if(strstr(i->data, "://")) {
			char *str = alpm_fetch_pkgurl(config->handle, i->data);
			if(str == NULL) {
				pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n",
						(char *)i->data, alpm_strerror(alpm_errno(config->handle)));
				return 1;
			} else {
				free(i->data);
				i->data = str;
			}
		}
	}

	/* Step 1: create a new transaction */
	if(trans_init(config->flags, 1) == -1) {
		return 1;
	}

	printf(_("loading packages...\n"));
	/* add targets to the created transaction */
	for(i = targets; i; i = alpm_list_next(i)) {
		char *targ = alpm_list_getdata(i);
		alpm_pkg_t *pkg;

		if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) {
			pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			trans_release();
			return 1;
		}
		if(alpm_add_pkg(config->handle, pkg) == -1) {
			pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			alpm_pkg_free(pkg);
			trans_release();
			return 1;
		}
		config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
	}

	/* now that targets are resolved, we can hand it all off to the sync code */
	return sync_prepare_execute();
}
Esempio n. 11
0
static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
	int ret = 0;
	alpm_list_t *t;

	for(t = targets; t; t = alpm_list_next(t)) {
		char *filename = NULL, *f;
		int found = 0;
		alpm_list_t *s;
		size_t len;

		if((filename = strdup(t->data)) == NULL) {
			goto notfound;
		}

		len = strlen(filename);
		f = filename;
		while(len > 1 && f[0] == '/') {
			f = f + 1;
			len--;
		}

		for(s = syncs; s; s = alpm_list_next(s)) {
			alpm_list_t *p;
			alpm_db_t *repo = s->data;
			alpm_list_t *packages = alpm_db_get_pkgcache(repo);

			for(p = packages; p; p = alpm_list_next(p)) {
				alpm_pkg_t *pkg = p->data;
				alpm_filelist_t *files = alpm_pkg_get_files(pkg);

				if(alpm_filelist_contains(files, f)) {

					if(!config->quiet) {
						printf(_("%s is owned by %s/%s %s\n"), f,
								alpm_db_get_name(repo), alpm_pkg_get_name(pkg),
								alpm_pkg_get_version(pkg));
					} else {
						printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
					}

					found = 1;
				}
			}
		}

		free(filename);

notfound:
		if(!found) {
			ret++;
		}
	}

	return 0;
}
Esempio n. 12
0
void calculate_results_relevance (alpm_list_t *targets)
{
	for (const alpm_list_t *t = targets; t; t = alpm_list_next (t)) {
		const char *target = t->data;
		for (const alpm_list_t *r = results; r; r = alpm_list_next(r)) {
			const char *result = results_name (r->data);
			const size_t lev_dst = levenshtein_distance (target, result);
			if (lev_dst < ((results_t *) r->data)->rel) {
				((results_t *) r->data)->rel = lev_dst;
			}
		}
	}
}
Esempio n. 13
0
static void checkpkgs(alpm_list_t *pkglist)
{
	alpm_list_t *i, *j;
	for(i = pkglist; i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;
		alpm_list_t *unused = alpm_pkg_unused_deltas(pkg);
		for(j = unused; j; j = alpm_list_next(j)) {
			const char *delta = j->data;
			printf("%s\n", delta);
		}
		alpm_list_free(unused);
	}
}
Esempio n. 14
0
static alpm_list_t *resolve_pkg(alpm_list_t *targets) {
  char *pkgname, *reponame;
  alpm_list_t *t, *r, *ret = NULL;

  if (targets == NULL) {
    return all_packages(dblist);
  } else if (opt_search) {
    return search_packages(dblist, targets);
  } else if (opt_groups) {
    return search_groups(dblist, targets);
  }

  /* resolve each target individually from the repo pool */
  for (t = targets; t; t = alpm_list_next(t)) {
    alpm_pkg_t *pkg = NULL;
    int found = 0;

    pkgname = reponame = t->data;
    if (strchr(pkgname, '/')) {
      strsep(&pkgname, "/");
    } else {
      reponame = NULL;
    }

    for (r = dblist; r; r = alpm_list_next(r)) {
      alpm_db_t *repo = r->data;

      if (reponame && strcmp(reponame, alpm_db_get_name(repo)) != 0) {
        continue;
      }

      pkg = alpm_db_get_pkg(repo, pkgname);
      if (pkg == NULL) {
        continue;
      }

      found = 1;
      ret = alpm_list_add(ret, pkg);
      if (opt_readone) {
        break;
      }
    }

    if (!found && opt_verbose) {
      fprintf(stderr, "error: package `%s' not found\n", pkgname);
    }
  }

  return ret;
}
Esempio n. 15
0
static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
	int ret = 0;
	alpm_list_t *t;

	for(t = targets; t; t = alpm_list_next(t)) {
		char *filename = t->data;
		int found = 0;
		alpm_list_t *s;
		size_t len = strlen(filename);

		while(len > 1 && filename[0] == '/') {
			filename++;
			len--;
		}

		for(s = syncs; s; s = alpm_list_next(s)) {
			alpm_list_t *p;
			alpm_db_t *repo = s->data;
			alpm_list_t *packages = alpm_db_get_pkgcache(repo);

			for(p = packages; p; p = alpm_list_next(p)) {
				alpm_pkg_t *pkg = p->data;
				alpm_filelist_t *files = alpm_pkg_get_files(pkg);

				if(alpm_filelist_contains(files, filename)) {
					if(config->op_f_machinereadable) {
						print_line_machinereadable(repo, pkg, filename);
					} else if(!config->quiet) {
						const colstr_t *colstr = &config->colstr;
						printf(_("%s is owned by %s%s/%s%s %s%s\n"), filename,
								colstr->repo, alpm_db_get_name(repo), colstr->title,
								alpm_pkg_get_name(pkg), colstr->version,
								alpm_pkg_get_version(pkg));
					} else {
						printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
					}

					found = 1;
				}
			}
		}

		if(!found) {
			ret++;
		}
	}

	return 0;
}
Esempio n. 16
0
File: ab.c Progetto: tfarina/rsc
int ab_print_contact_records(void) {
  ft_table_t *table;
  alpm_list_t *i;

  ft_set_default_border_style(FT_BASIC2_STYLE);
  table = ft_create_table();
  ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
  ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);

  ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
  ft_write_ln(table, "ID", "First Name", "Last Name", "Email");

  for (i = contact_list; i; i = alpm_list_next(i)) {
    ab_contact_t *contact = (ab_contact_t *)i->data;
    int length = snprintf(NULL, 0, "%d", contact->id);
    char* idstr = malloc(length + 1);
    snprintf(idstr, length + 1, "%d", contact->id);
    ft_write_ln(table, idstr, contact->fname, contact->lname, contact->email);
    free(idstr);
  }

  printf("%s\n", ft_to_string(table));
  ft_destroy_table(table);

  return 0;
}
Esempio n. 17
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;
}
Esempio n. 18
0
static void table_print_line(const alpm_list_t *line, short col_padding,
		size_t colcount, size_t *widths, int *has_data)
{
	size_t i;
	int need_padding = 0;
	const alpm_list_t *curcell;

	for(i = 0, curcell = line; curcell && i < colcount;
			i++, curcell = alpm_list_next(curcell)) {
		const struct table_cell_t *cell = curcell->data;
		const char *str = (cell->label ? cell->label : "");
		int cell_width;

		if(!has_data[i]) {
			continue;
		}

		cell_width = (cell->mode & CELL_RIGHT_ALIGN ? (int)widths[i] : -(int)widths[i]);

		if(need_padding) {
			printf("%*s", col_padding, "");
		}

		if(cell->mode & CELL_TITLE) {
			printf("%s%*s%s", config->colstr.title, cell_width, str, config->colstr.nocolor);
		} else {
			printf("%*s", cell_width, str);
		}
		need_padding = 1;
	}

	printf("\n");
}
Esempio n. 19
0
static int print_list(alpm_list_t *list, extractfn fn) {
  alpm_list_t *i;
  int out = 0;

  if (!list) {
    if (opt_verbose) {
      out += printf("None");
    }
    return out;
  }

  i = list;
  while (1) {
    char *item = (char*)(fn ? fn(i->data) : i->data);
    if (item == NULL) {
      continue;
    }

    out += printf("%s", item);

    if ((i = alpm_list_next(i))) {
      out += print_escaped(opt_listdelim);
    } else {
      break;
    }
  }

  return out;
}
Esempio n. 20
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;
}
Esempio n. 21
0
File: remove.c Progetto: 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;
}
Esempio n. 22
0
bool does_name_contain_targets (const alpm_list_t *targets, const char *name, bool use_regex)
{
	if (!targets || !name) {
		return false;
	}

	for (const alpm_list_t *t = targets; t; t = alpm_list_next (t)) {
		const char *target = (const char *)(t->data);
		if (!target) {
			continue;
		}

		if (use_regex) {
			regex_t reg;
			if (regcomp (&reg, target, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
				return false;
			}
			if (regexec (&reg, name, 0, 0, 0) != 0 && strstr (name, target) == NULL) {
				regfree (&reg);
				return false;
			}
			regfree (&reg);
		} else if (strcasestr (name, target) == NULL) {
			return false;
		}
	}

	return true;
}
Esempio n. 23
0
static int register_repo(config_repo_t *repo)
{
	alpm_list_t *i;
	alpm_db_t *db;

	repo->siglevel = merge_siglevel(config->siglevel,
			repo->siglevel, repo->siglevel_mask);

	db = alpm_register_syncdb(config->handle, repo->name, repo->siglevel);
	if(db == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
				repo->name, alpm_strerror(alpm_errno(config->handle)));
		return 1;
	}

	pm_printf(ALPM_LOG_DEBUG,
			"setting usage of %d for %s repository\n",
			repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage,
			repo->name);
	alpm_db_set_usage(db, repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage);

	for(i = repo->servers; i; i = alpm_list_next(i)) {
		char *value = i->data;
		if(_add_mirror(db, value) != 0) {
			pm_printf(ALPM_LOG_ERROR,
					_("could not add mirror '%s' to database '%s' (%s)\n"),
					value, repo->name, alpm_strerror(alpm_errno(config->handle)));
			return 1;
		}
	}

	return 0;
}
Esempio n. 24
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;
}
Esempio n. 25
0
/*
 * Return: 0 for success.
 */
int ipacman_sync_packages(alpm_list_t *targets)
{
	int ret = 0;
	alpm_list_t *i;
	alpm_list_t *sync_dbs = alpm_get_syncdbs(handle);

	if(sync_dbs == NULL) {
		printf("no usable package repositories configured.\n");
		return 1;
	}

	/* ensure all known dbs are valid */
	for(i = sync_dbs; i; i = alpm_list_next(i)) {
		alpm_db_t *db = i->data;
		if(alpm_db_get_valid(db)) {
			printf("database '%s' is not valid (%s)\n",
					alpm_db_get_name(db), alpm_strerror(alpm_errno(handle)));
			ret = 1;
		}
	}
	if (ret)
		return ret;

	/* Step 1: create a new transaction... */
	ret = alpm_trans_init(handle, ALPM_TRANS_FLAG_FORCE);
	if(ret == -1) {
		trans_init_error(handle);
		return 1;
	}

	/* process targets */
	for(i = targets; i; i = alpm_list_next(i)) {
		const char *targ = i->data;
		if(process_target(targ, ret) == 1) {
			ret = 1;
		}
	}

	if(ret) {
		if(alpm_trans_release(handle) == -1) {
			printf("failed to release transaction (%s)\n", alpm_strerror(alpm_errno(handle)));
		}
		return ret;
	}

	return sync_prepare_execute();
}
Esempio n. 26
0
void* alpm_list_iterator_next_value (alpm_list_iterator_t *iter) {
	if (iter->pos) {
		void* result = alpm_list_get_data (iter->pos);
		iter->pos = alpm_list_next (iter->pos);
		return result;
	}
	else return NULL;
}
Esempio n. 27
0
static alpm_list_t *get_pkg_dep_names(alpm_pkg_t *pkg)
{
	alpm_list_t *i, *names = NULL;
	for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
		alpm_depend_t *d = i->data;
		names = alpm_list_add(names, d->name);
	}
	return names;
}
Esempio n. 28
0
alpm_list_t *find_str(alpm_list_t *haystack, const char *needle)
{
	for(; haystack; haystack = alpm_list_next(haystack)) {
		if(strcasecmp(haystack->data, needle) == 0) {
			return haystack;
		}
	}
	return NULL;
}
Esempio n. 29
0
/**
 * @brief Send a callback for any optdepend being removed.
 *
 * @param handle the context handle
 * @param lp list of packages to be removed
 */
static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *lp)
{
	alpm_list_t *i;

	for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;
		alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);

		if(optdeps && !alpm_pkg_find(lp, pkg->name)) {
			alpm_list_t *j;
			for(j = optdeps; j; j = alpm_list_next(j)) {
				alpm_depend_t *optdep = j->data;
				if(alpm_pkg_find(lp, optdep->name)) {
					EVENT(handle, ALPM_EVENT_OPTDEP_REQUIRED, pkg, optdep);
				}
			}
		}
	}
}
Esempio n. 30
0
char *concat_dep_list (alpm_list_t *deps)
{
	alpm_list_t *i, *deps_str = NULL;
	char *ret;
	for (i=deps; i; i = alpm_list_next (i))
		deps_str = alpm_list_add (deps_str, alpm_dep_compute_string (i->data));
	ret = concat_str_list (deps_str);
	FREELIST (deps_str);
	return ret;
}