예제 #1
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;
}
예제 #2
0
파일: files.c 프로젝트: AWhetter/pacman
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;
}
예제 #3
0
/**
 * call-seq:
 *   name() → a_string
 *
 * Returns the name of the package database.
 */
static VALUE name(VALUE self)
{
  alpm_db_t* p_db = NULL;
  Data_Get_Struct(self, alpm_db_t, p_db);

  return rb_str_new2(alpm_db_get_name(p_db));
}
예제 #4
0
static int _add_mirror(alpm_db_t *db, char *value)
{
	const char *dbname = alpm_db_get_name(db);
	/* let's attempt a replacement for the current repo */
	char *temp = strreplace(value, "$repo", dbname);
	/* let's attempt a replacement for the arch */
	const char *arch = config->arch;
	char *server;
	if(arch) {
		server = strreplace(temp, "$arch", arch);
		free(temp);
	} else {
		if(strstr(temp, "$arch")) {
			free(temp);
			pm_printf(ALPM_LOG_ERROR,
					_("mirror '%s' contains the '%s' variable, but no '%s' is defined.\n"),
					value, "$arch", "Architecture");
			return 1;
		}
		server = temp;
	}

	if(alpm_db_add_server(db, server) != 0) {
		/* pm_errno is set by alpm_db_setserver */
		pm_printf(ALPM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
				dbname, server, alpm_strerror(alpm_errno(config->handle)));
		free(server);
		return 1;
	}

	free(server);
	return 0;
}
예제 #5
0
static gchar *
alpm_pkg_build_urls (pmpkg_t *pkg)
{
	GString *string = g_string_new ("");
#ifdef ALPM_PACKAGE_URL
	const gchar *name, *arch, *repo, *url;
#else
	const gchar *url;
#endif

	g_return_val_if_fail (pkg != NULL, NULL);

	/* grab the URL of the package... */
	url = alpm_pkg_get_url (pkg);
	if (url != NULL) {
		g_string_append_printf (string, "%s;Package website;", url);
	}

#ifdef ALPM_PACKAGE_URL
	/* ... and construct the distro URL if possible */
	name = alpm_pkg_get_name (pkg);
	arch = alpm_pkg_get_arch (pkg);
	repo = alpm_db_get_name (alpm_pkg_get_db (pkg));

	g_string_append_printf (string, ALPM_PACKAGE_URL ";Distribution page;",
				repo, arch, name);
#endif

	g_string_truncate (string, string->len - 1);
	return g_string_free (string, FALSE);
}
예제 #6
0
파일: package.c 프로젝트: tadzik/powaur
/* Returns a statically allocated string stating which db the pkg came from
 * @param sdbs sync dbs
 * @param pkgname package to search for
 * @param grp pointer to alpm_list_t * used to store the pkg's groups if any
 */
const char *which_db(alpm_list_t *sdbs, const char *pkgname, alpm_list_t **grp)
{
	const char *repo = NULL;
	alpm_list_t *i, *k;
	pmpkg_t *spkg;

	for (i = sdbs; i && !repo; i = i->next) {
		for (k = alpm_db_get_pkgcache(i->data); k; k = k->next) {
			spkg = k->data;
			if (!strcmp(alpm_pkg_get_name(spkg), pkgname)) {
				repo = alpm_db_get_name(i->data);
				if (grp) {
					*grp = alpm_pkg_get_groups(spkg);
				}

				break;
			}
		}
	}

	if (!repo) {
		repo = LOCAL;
	}

	return repo;
}
예제 #7
0
static gboolean
pk_backend_match_details (alpm_pkg_t *pkg, GRegex *regex)
{
	const gchar *desc;
	alpm_db_t *db;
	const alpm_list_t *i;

	g_return_val_if_fail (pkg != NULL, FALSE);
	g_return_val_if_fail (regex != NULL, FALSE);

	/* match the name first... */
	if (g_regex_match (regex, alpm_pkg_get_name (pkg), 0, NULL))
		return TRUE;

	/* ... then the description... */
	desc = alpm_pkg_get_desc (pkg);
	if (desc != NULL && g_regex_match (regex, desc, 0, NULL))
		return TRUE;

	/* ... then the database... */
	db = alpm_pkg_get_db (pkg);
	if (db != NULL && g_regex_match (regex, alpm_db_get_name (db),
					 G_REGEX_MATCH_ANCHORED, NULL))
		return TRUE;

	/* ... then the licenses */
	for (i = alpm_pkg_get_licenses (pkg); i != NULL; i = i->next) {
		if (g_regex_match (regex, i->data, G_REGEX_MATCH_ANCHORED, NULL))
			return TRUE;
	}

	return FALSE;
}
예제 #8
0
void pu_fprint_pkgspec(FILE *stream, alpm_pkg_t *pkg)
{
	const char *c;
	switch(alpm_pkg_get_origin(pkg)) {
		case ALPM_PKG_FROM_FILE:
			c = alpm_pkg_get_filename(pkg);
			if(strstr(c, "://")) {
				fprintf(stream, "%s", alpm_pkg_get_filename(pkg));
			} else {
				char *real = realpath(c, NULL);
				fprintf(stream, "file://%s", real);
				free(real);
			}
			break;
		case ALPM_PKG_FROM_LOCALDB:
			fprintf(stream, "local/%s", alpm_pkg_get_name(pkg));
			break;
		case ALPM_PKG_FROM_SYNCDB:
			fprintf(stream, "%s/%s",
					alpm_db_get_name(alpm_pkg_get_db(pkg)), alpm_pkg_get_name(pkg));
			break;
		default:
			/* no idea where this package came from, fall back to its name */
			fputs(alpm_pkg_get_name(pkg), stream);
			break;
	}
}
예제 #9
0
static gboolean
disabled_repos_configure (GHashTable *table, GError **error)
{
	const alpm_list_t *i;

	g_debug ("reading config from %s", PK_BACKEND_CONFIG_FILE);

	/* read configuration from pacman.conf file */
	if (!pk_backend_configure (PK_BACKEND_CONFIG_FILE, error)) {
		return FALSE;
	}

	/* disable disabled repos */
	for (i = alpm_option_get_syncdbs (); i != NULL;) {
		pmdb_t *db = (pmdb_t *) i->data;
		const gchar *repo = alpm_db_get_name (db);

		if (g_hash_table_lookup (table, repo) == NULL) {
			/* repo is not disabled */
			i = i->next;
			continue;
		}

		if (alpm_db_unregister (db) < 0) {
			g_set_error (error, ALPM_ERROR, pm_errno, "[%s]: %s",
				     repo, alpm_strerrorlast ());
			return FALSE;
		}

		/* start again because the list gets invalidated */
		i = alpm_option_get_syncdbs ();
	}

	return TRUE;
}
예제 #10
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;
}
예제 #11
0
파일: types.c 프로젝트: juster/perl-alpm
SV*
c2p_db(void *db)
{
    if(strcmp(alpm_db_get_name(db), "local") == 0) {
        return c2p_localdb(db);
    } else {
        return c2p_syncdb(db);
    }
}
예제 #12
0
/**
 * call-seq:
 *   inspect() → a_string
 *
 * Human-readable description.
 */
static VALUE inspect(VALUE self)
{
  alpm_db_t* p_db = NULL;
  int len;
  char buf[256];
  Data_Get_Struct(self, alpm_db_t, p_db);

  len = sprintf(buf, "#<%s %s>", rb_obj_classname(self), alpm_db_get_name(p_db));
  return rb_str_new(buf, len);
}
예제 #13
0
/**
 * Open a package changelog for reading. Similar to fopen in functionality,
 * except that the returned 'file stream' is from the database.
 * @param pkg the package (from db) to read the changelog
 * @return a 'file stream' to the package changelog
 */
static void *_cache_changelog_open(pmpkg_t *pkg)
{
    char clfile[PATH_MAX];
    snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog",
             alpm_option_get_dbpath(pkg->handle),
             alpm_db_get_name(alpm_pkg_get_db(pkg)),
             alpm_pkg_get_name(pkg),
             alpm_pkg_get_version(pkg));
    return fopen(clfile, "r");
}
예제 #14
0
static alpm_db_t *get_db(const char *dbname)
{
	alpm_list_t *i;
	for(i = alpm_get_syncdbs(handle); i; i = i->next) {
		alpm_db_t *db = i->data;
		if(strcmp(alpm_db_get_name(db), dbname) == 0) {
			return db;
		}
	}
	return NULL;
}
예제 #15
0
int ipacman_refresh_databases(void)
{
	alpm_list_t *sync_dbs = NULL;
	alpm_list_t *i;
	unsigned int success = 0;

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

	printf("Synchronizing package databases...\n");
	alpm_logaction(handle, PACMAN_CALLER_PREFIX, "synchronizing package lists\n");

	for(i = sync_dbs; i; i = alpm_list_next(i)) {
		alpm_db_t *db = i->data;

		int ret = alpm_db_update(1, db);
		if(ret < 0) {
			printf("failed to update %s (%s)\n",
					alpm_db_get_name(db), alpm_strerror(alpm_errno(handle)));
		} else if(ret == 1) {
			printf(" %s is up to date\n", alpm_db_get_name(db));
			success++;
		} else {
			success++;
		}
	}

	/* We should always succeed if at least one DB was upgraded - we may possibly
	 * fail later with unresolved deps, but that should be rare, and would be
	 * expected
	 */
	if(!success) {
		printf("failed to synchronize any databases\n");
		trans_init_error(handle);
		return success;
	}
	return 0;
}
예제 #16
0
파일: files.c 프로젝트: AWhetter/pacman
static void print_line_machinereadable(alpm_db_t *db, alpm_pkg_t *pkg, char *filename)
{
	/* Fields are repo, pkgname, pkgver, filename separated with \0 */
	fputs(alpm_db_get_name(db), stdout);
	fputc(0, stdout);
	fputs(alpm_pkg_get_name(pkg), stdout);
	fputc(0, stdout);
	fputs(alpm_pkg_get_version(pkg), stdout);
	fputc(0, stdout);
	fputs(filename, stdout);
	fputs("\n", stdout);
}
예제 #17
0
파일: pkg.c 프로젝트: juster/ocaml-alpm
CAMLprim value oalpm_pkg_checkmd5sum ( value package )
{
    pmpkg_t * pkg;
    pmdb_t  * db;
    CAMLparam1( package );
    pkg = Package_val( package );
    db  = alpm_pkg_get_db( pkg );
    if ( strcmp( alpm_db_get_name( db ), "local" ) == 0 ) {
        caml_failwith( FAIL_CHECK_LOCALPKG );
    }
    OALPMreturn( alpm_pkg_checkmd5sum( pkg ));
}
예제 #18
0
파일: util.c 프로젝트: sandsmark/pacman
void print_packages(const alpm_list_t *packages)
{
	const alpm_list_t *i;
	if(!config->print_format) {
		config->print_format = strdup("%l");
	}
	for(i = packages; i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;
		char *string = strdup(config->print_format);
		char *temp = string;
		/* %n : pkgname */
		if(strstr(temp, "%n")) {
			string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));
			free(temp);
			temp = string;
		}
		/* %v : pkgver */
		if(strstr(temp, "%v")) {
			string = strreplace(temp, "%v", alpm_pkg_get_version(pkg));
			free(temp);
			temp = string;
		}
		/* %l : location */
		if(strstr(temp, "%l")) {
			char *pkgloc = pkg_get_location(pkg);
			string = strreplace(temp, "%l", pkgloc);
			free(pkgloc);
			free(temp);
			temp = string;
		}
		/* %r : repo */
		if(strstr(temp, "%r")) {
			const char *repo = "local";
			alpm_db_t *db = alpm_pkg_get_db(pkg);
			if(db) {
				repo = alpm_db_get_name(db);
			}
			string = strreplace(temp, "%r", repo);
			free(temp);
			temp = string;
		}
		/* %s : size */
		if(strstr(temp, "%s")) {
			char *size;
			pm_asprintf(&size, "%jd", (intmax_t)pkg_get_size(pkg));
			string = strreplace(temp, "%s", size);
			free(size);
			free(temp);
		}
		printf("%s\n", string);
		free(string);
	}
}
예제 #19
0
static gboolean
pk_backend_update_databases (PkBackend *self, gint force, GError **error) {
	alpm_cb_download dlcb;
	alpm_cb_totaldl totaldlcb;
	const alpm_list_t *i;

	g_return_val_if_fail (self != NULL, FALSE);

	if (!pk_backend_transaction_initialize (self, 0, error)) {
		return FALSE;
	}

	alpm_logaction ("synchronizing package lists\n");

	dlcb = alpm_option_get_dlcb ();
	totaldlcb = alpm_option_get_totaldlcb ();

	/* set total size to minus the number of databases */
	i = alpm_option_get_syncdbs ();
	totaldlcb (-alpm_list_count (i));

	for (; i != NULL; i = i->next) {
		gint result;

		if (pk_backend_cancelled (self)) {
			/* pretend to be finished */
			i = NULL;
			break;
		}

		result = alpm_db_update (force, i->data);

		if (result > 0) {
			/* fake the download when already up to date */
			dlcb ("", 1, 1);
		} else if (result < 0) {
			g_set_error (error, ALPM_ERROR, pm_errno, "[%s]: %s",
				     alpm_db_get_name (i->data),
				     alpm_strerrorlast ());
			break;
		}
	}

	totaldlcb (0);

	if (i == NULL) {
		return pk_backend_transaction_end (self, error);
	} else {
		pk_backend_transaction_end (self, NULL);
		return FALSE;
	}
}
예제 #20
0
alpm_pkg_t *
pk_backend_find_pkg (PkBackend *self, const gchar *package_id, GError **error)
{
	gchar **package;
	const gchar *repo_id;
	alpm_db_t *db = NULL;
	alpm_pkg_t *pkg;

	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (package_id != NULL, NULL);
	g_return_val_if_fail (alpm != NULL, NULL);
	g_return_val_if_fail (localdb != NULL, NULL);

	package = pk_package_id_split (package_id);
	repo_id = package[PK_PACKAGE_ID_DATA];

	/* find the database to search in */
	if (g_strcmp0 (repo_id, "installed") == 0) {
		db = localdb;
	} else {
		const alpm_list_t *i = alpm_get_syncdbs (alpm);
		for (; i != NULL; i = i->next) {
			const gchar *repo = alpm_db_get_name (i->data);

			if (g_strcmp0 (repo, repo_id) == 0) {
				db = i->data;
				break;
			}
		}
	}

	if (db != NULL) {
		pkg = alpm_db_get_pkg (db, package[PK_PACKAGE_ID_NAME]);
	} else {
		pkg = NULL;
	}

	if (pkg != NULL) {
		const gchar *version = alpm_pkg_get_version (pkg);
		if (g_strcmp0 (version, package[PK_PACKAGE_ID_VERSION]) != 0) {
			pkg = NULL;
		}
	}

	if (pkg == NULL) {
		int code = ALPM_ERR_PKG_NOT_FOUND;
		g_set_error (error, ALPM_ERROR, code, "%s: %s", package_id,
			     alpm_strerror (code));
	}
	g_strfreev (package);
	return pkg;
}
예제 #21
0
파일: expac.c 프로젝트: Acidburn0zzz/expac
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;
}
예제 #22
0
파일: util.c 프로젝트: sandsmark/pacman
/* 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;
}
예제 #23
0
static gboolean
pk_backend_repo_disable_thread (PkBackend *self)
{
	const alpm_list_t *i;
	const gchar *repo;

	GError *error = NULL;

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

	repo = pk_backend_get_string (self, "repo_id");

	g_return_val_if_fail (repo != NULL, FALSE);

	for (i = alpm_get_syncdbs (alpm); i != NULL; i = i->next) {
		alpm_db_t *db = (alpm_db_t *) i->data;
		const gchar *name = alpm_db_get_name (db);

		if (g_strcmp0 (repo, name) == 0) {
			if (alpm_db_unregister (db) < 0) {
				alpm_errno_t errno = alpm_errno (alpm);
				g_set_error (&error, ALPM_ERROR, errno,
					     "[%s]: %s", repo,
					     alpm_strerror (errno));
			} else {
				g_hash_table_insert (disabled, g_strdup (repo),
						     GINT_TO_POINTER (1));
			}
			break;
		}
	}

	if (i == NULL) {
		int code = ALPM_ERR_DB_NULL;
		g_set_error (&error, ALPM_ERROR, code, "[%s]: %s", repo,
			     alpm_strerror (code));
	}

	if (error != NULL) {
		pk_backend_error (self, error);
		g_error_free (error);
	}

	pk_backend_thread_finished (self);
	return (error == NULL);
}
예제 #24
0
static void
pk_backend_get_repo_list_thread (PkBackendJob *job, GVariant *params, gpointer data)
{
	PkBackend *backend = pk_backend_job_get_backend (job);
	PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
	const alpm_list_t *i;

	/* emit enabled repos */
	for (i = alpm_get_syncdbs (priv->alpm); i != NULL; i = i->next) {
		alpm_db_t *db = (alpm_db_t *) i->data;
		const gchar *repo = alpm_db_get_name (db);
		if (pk_backend_job_is_cancelled (job))
			return;
		pk_backend_repo_info (job, repo, TRUE);
	}
}
예제 #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();
}
예제 #26
0
파일: expac.c 프로젝트: aissat/expac
static alpm_list_t *search_exact(alpm_list_t *dblist, alpm_list_t *targets)
{
  char *pkgname, *reponame;
  alpm_list_t *results = NULL;

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

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

    for(r = dblist; r; r = r->next) {
      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;
      results = alpm_list_add(results, pkg);
      if(opt_readone) {
        break;
      }
    }

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

  return results;
}
예제 #27
0
alpm_pkg_t *pu_find_pkgspec(alpm_handle_t *handle, const char *pkgspec)
{
	char *c;

	if(strstr(pkgspec, "://")) {
		alpm_pkg_t *pkg;
		alpm_siglevel_t sl
			= strncmp(pkgspec, "file://", 7) == 0
			? alpm_option_get_local_file_siglevel(handle)
			: alpm_option_get_remote_file_siglevel(handle);
		char *path = alpm_fetch_pkgurl(handle, pkgspec);
		int err = alpm_pkg_load(handle, path ? path : pkgspec, 1, sl, &pkg);
		free(path);
		if(!err) {
			return pkg;
		}
	} else if((c = strchr(pkgspec, '/')))  {
		alpm_db_t *db = NULL;
		size_t dblen = c - pkgspec;

		if(dblen == strlen("local") && memcmp(pkgspec, "local", dblen) == 0) {
			db = alpm_get_localdb(handle);
		} else {
			alpm_list_t *i;
			for(i = alpm_get_syncdbs(handle); i; i = i->next) {
				const char *dbname = alpm_db_get_name(i->data);
				if(dblen == strlen(dbname) && strncmp(pkgspec, dbname, dblen) == 0) {
					db = i->data;
					break;
				}
			}
		}

		if(!db) {
			return NULL;
		} else {
			return alpm_db_get_pkg(db, c + 1);
		}
	}

	return NULL;
}
예제 #28
0
static void
pk_backend_repo_disable_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	const alpm_list_t *i;
	const gchar *repo;

	GError *error = NULL;

	repo = pk_backend_get_string (self, "repo_id");

	for (i = alpm_option_get_syncdbs (); i != NULL; i = i->next) {
		pmdb_t *db = (pmdb_t *) i->data;
		const gchar *name = alpm_db_get_name (db);

		if (g_strcmp0 (repo, name) == 0) {
			if (alpm_db_unregister (db) < 0) {
				g_set_error (&error, ALPM_ERROR, pm_errno,
					     "[%s]: %s", repo,
					     alpm_strerrorlast ());
			} else {
				g_hash_table_insert (disabled, g_strdup (repo),
						     GINT_TO_POINTER (1));
			}
			break;
		}
	}

	if (i == NULL) {
		int code = PM_ERR_DB_NULL;
		g_set_error (&error, ALPM_ERROR, code, "[%s]: %s", repo,
			     alpm_strerror (code));
	}

	if (error != NULL) {
		pk_backend_error (self, error);
		g_error_free (error);
	}

	pk_backend_job_finished (self);
}
예제 #29
0
static gboolean
pk_backend_get_repo_list_thread (PkBackend *self)
{
	const alpm_list_t *i;
	GHashTableIter iter;
	gpointer key, value;

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

	/* emit enabled repos */
	for (i = alpm_get_syncdbs (alpm); i != NULL; i = i->next) {
		alpm_db_t *db = (alpm_db_t *) i->data;
		const gchar *repo = alpm_db_get_name (db);

		if (pk_backend_cancelled (self)) {
			goto out;
		} else {
			pk_backend_repo_info (self, repo, TRUE);
		}
	}

	/* emit disabled repos */
	g_hash_table_iter_init (&iter, disabled);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		const gchar *repo = (const gchar *) key;

		if (pk_backend_cancelled (self)) {
			goto out;
		} else {
			pk_backend_repo_info (self, repo, FALSE);
		}
	}

out:
	return pk_backend_finish (self, NULL);
}
예제 #30
0
static void
pk_backend_get_repo_list_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	const alpm_list_t *i;
	GHashTableIter iter;
	gpointer key, value;

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

	/* emit enabled repos */
	for (i = alpm_option_get_syncdbs (); i != NULL; i = i->next) {
		pmdb_t *db = (pmdb_t *) i->data;
		const gchar *repo = alpm_db_get_name (db);

		if (pk_backend_cancelled (self)) {
			goto out;
		} else {
			pk_backend_repo_info (self, repo, TRUE);
		}
	}

	/* emit disabled repos */
	g_hash_table_iter_init (&iter, disabled);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		const gchar *repo = (const gchar *) key;

		if (pk_backend_cancelled (self)) {
			goto out;
		} else {
			pk_backend_repo_info (self, repo, FALSE);
		}
	}

out:
	pk_backend_finish (self, NULL);
}