/** Check if packages from list1 conflict with packages from list2. * This looks at the conflicts fields of all packages from list1, and sees * if they match packages from list2. * If a conflict (pkg1, pkg2) is found, it is added to the baddeps list * in this order if order >= 0, or reverse order (pkg2,pkg1) otherwise. * * @param list1 first list of packages * @param list2 second list of packages * @param *baddeps list to store conflicts * @param order if >= 0 the conflict order is preserved, if < 0 it's reversed */ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2, alpm_list_t **baddeps, int order) { alpm_list_t *i, *j, *k; if(!baddeps) { return; } for(i = list1; i; i = i->next) { pmpkg_t *pkg1 = i->data; const char *pkg1name = alpm_pkg_get_name(pkg1); for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) { const char *conflict = j->data; for(k = list2; k; k = k->next) { pmpkg_t *pkg2 = k->data; const char *pkg2name = alpm_pkg_get_name(pkg2); if(strcmp(pkg1name, pkg2name) == 0) { /* skip the package we're currently processing */ continue; } if(does_conflict(pkg1, conflict, pkg2)) { if(order >= 0) { add_conflict(baddeps, pkg1name, pkg2name); } else { add_conflict(baddeps, pkg2name, pkg1name); } } } } } }
/** 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; }
/* These parameters are messy. We check if this package, given a list of * targets and a db is safe to remove. We do NOT remove it if it is in the * target list, or if if the package was explictly installed and * include_explicit == 0 */ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets, int include_explicit) { alpm_list_t *i; if(_alpm_pkg_find(targets, alpm_pkg_get_name(pkg))) { return 0; } if(!include_explicit) { /* see if it was explicitly installed */ if(alpm_pkg_get_reason(pkg) == PM_PKG_REASON_EXPLICIT) { _alpm_log(db->handle, PM_LOG_DEBUG, "excluding %s -- explicitly installed\n", alpm_pkg_get_name(pkg)); return 0; } } /* TODO: checkdeps could be used here, it handles multiple providers * better, but that also makes it slower. * Also this would require to first add the package to the targets list, * then call checkdeps with it, then remove the package from the targets list * if checkdeps detected it would break something */ /* see if other packages need it */ for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { pmpkg_t *lpkg = i->data; if(_alpm_dep_edge(lpkg, pkg) && !_alpm_pkg_find(targets, lpkg->name)) { return 0; } } /* it's ok to remove */ return 1; }
static int display(alpm_pkg_t *pkg) { int ret = 0; if(config->op_q_info) { if(config->op_q_isfile) { dump_pkg_full(pkg, 0); } else { dump_pkg_full(pkg, config->op_q_info > 1); } } if(config->op_q_list) { dump_pkg_files(pkg, config->quiet); } if(config->op_q_changelog) { dump_pkg_changelog(pkg); } if(config->op_q_check) { ret = check(pkg); } if(!config->op_q_info && !config->op_q_list && !config->op_q_changelog && !config->op_q_check) { if(!config->quiet) { printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); } else { printf("%s\n", alpm_pkg_get_name(pkg)); } } return ret; }
/** Check for new version of pkg in sync repos * (only the first occurrence is considered in sync) */ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync) { alpm_list_t *i; alpm_pkg_t *spkg = NULL; ASSERT(pkg != NULL, return NULL); pkg->handle->pm_errno = 0; for(i = dbs_sync; !spkg && i; i = i->next) { spkg = _alpm_db_get_pkgfromcache(i->data, alpm_pkg_get_name(pkg)); } if(spkg == NULL) { _alpm_log(pkg->handle, ALPM_LOG_DEBUG, "'%s' not found in sync db => no upgrade\n", alpm_pkg_get_name(pkg)); return NULL; } /* compare versions and see if spkg is an upgrade */ if(_alpm_pkg_compare_versions(spkg, pkg) > 0) { _alpm_log(pkg->handle, ALPM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg), alpm_pkg_get_version(spkg)); return spkg; } /* spkg is not an upgrade */ return NULL; }
static int pkg_cmp(const void *p1, const void *p2) { /* explicit cast due to (un)necessary removal of const */ alpm_pkg_t *pkg1 = (alpm_pkg_t *)p1; alpm_pkg_t *pkg2 = (alpm_pkg_t *)p2; return strcmp(alpm_pkg_get_name(pkg1), alpm_pkg_get_name(pkg2)); }
static void print_query_fileowner(const char *filename, alpm_pkg_t *info) { if(!config->quiet) { printf(_("%s is owned by %s %s\n"), filename, alpm_pkg_get_name(info), alpm_pkg_get_version(info)); } else { printf("%s\n", alpm_pkg_get_name(info)); } }
/* 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; }
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; }
static int target_cmp(const void *p1, const void *p2) { const pm_target_t *targ1 = p1; const pm_target_t *targ2 = p2; /* explicit are always sorted after implicit (e.g. deps, pulled targets) */ if(targ1->is_explicit != targ2->is_explicit) { return targ1->is_explicit > targ2->is_explicit; } const char *name1 = targ1->install ? alpm_pkg_get_name(targ1->install) : alpm_pkg_get_name(targ1->remove); const char *name2 = targ2->install ? alpm_pkg_get_name(targ2->install) : alpm_pkg_get_name(targ2->remove); return strcmp(name1, name2); }
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; }
/** Check if pkg1 conflicts with pkg2 * @param pkg1 package we are looking at * @param conflict name of the possible conflict * @param pkg2 package to check * @return 0 for no conflict, non-zero otherwise */ static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2) { const char *pkg1name = alpm_pkg_get_name(pkg1); const char *pkg2name = alpm_pkg_get_name(pkg2); pmdepend_t *conf = _alpm_splitdep(conflict); int match = 0; match = alpm_depcmp(pkg2, conf); if(match) { _alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n", pkg1name, pkg2name, conflict); } _alpm_dep_free(conf); return(match); }
/* 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; }
/* 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; }
static pmpkg_t * alpm_pkg_find_update (pmpkg_t *pkg, const alpm_list_t *dbs) { const gchar *name; const alpm_list_t *i; g_return_val_if_fail (pkg != NULL, NULL); name = alpm_pkg_get_name (pkg); for (; dbs != NULL; dbs = dbs->next) { pmpkg_t *update = alpm_db_get_pkg (dbs->data, name); if (update != NULL) { if (alpm_pkg_vercmp (alpm_pkg_get_version (update), alpm_pkg_get_version (pkg)) > 0) { return update; } else { return NULL; } } i = alpm_db_get_pkgcache (dbs->data); for (; i != NULL; i = i->next) { if (alpm_list_find_str (alpm_pkg_get_replaces (i->data), name) != NULL) { return i->data; } } } return NULL; }
static void pk_backend_transaction_upgrade_done (PkBackend *self, alpm_pkg_t *pkg, alpm_pkg_t *old, gint direction) { const gchar *name, *pre, *post; g_return_if_fail (self != NULL); g_return_if_fail (pkg != NULL); g_return_if_fail (old != NULL || direction == 0); g_return_if_fail (alpm != NULL); name = alpm_pkg_get_name (pkg); if (direction != 0) { pre = alpm_pkg_get_version (old); } post = alpm_pkg_get_version (pkg); if (direction > 0) { alpm_logaction (alpm, PK_LOG_PREFIX, "upgraded %s (%s -> %s)\n", name, pre, post); } else if (direction < 0) { alpm_logaction (alpm, PK_LOG_PREFIX, "downgraded %s (%s -> %s)\n", name, pre, post); } else { alpm_logaction (alpm, PK_LOG_PREFIX, "reinstalled %s (%s)\n", name, post); } pk_backend_pkg (self, pkg, PK_INFO_ENUM_FINISHED); if (direction != 0) { pk_backend_transaction_process_new_optdepends (self, pkg, old); } pk_backend_output_end (self); }
static gboolean pk_alpm_pkg_is_local (PkBackendJob *job, alpm_pkg_t *pkg) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); alpm_pkg_t *local; g_return_val_if_fail (pkg != NULL, FALSE); /* find an installed package with the same name */ local = alpm_db_get_pkg (priv->localdb, alpm_pkg_get_name (pkg)); if (local == NULL) return FALSE; /* make sure the installed version is the same */ if (alpm_pkg_vercmp (alpm_pkg_get_version (local), alpm_pkg_get_version (pkg)) != 0) { return FALSE; } /* make sure the installed arch is the same */ if (g_strcmp0 (alpm_pkg_get_arch (local), alpm_pkg_get_arch (pkg)) != 0) { return FALSE; } return TRUE; }
static void pk_backend_transaction_add_done (PkBackend *self, alpm_pkg_t *pkg) { const gchar *name, *version; const alpm_list_t *i, *optdepends; g_return_if_fail (self != NULL); g_return_if_fail (pkg != NULL); g_return_if_fail (alpm != NULL); name = alpm_pkg_get_name (pkg); version = alpm_pkg_get_version (pkg); alpm_logaction (alpm, PK_LOG_PREFIX, "installed %s (%s)\n", name, version); pk_backend_pkg (self, pkg, PK_INFO_ENUM_FINISHED); optdepends = alpm_pkg_get_optdepends (pkg); if (optdepends != NULL) { pk_backend_output (self, "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); } } pk_backend_output_end (self); }
static void pk_backend_install_ignorepkg (PkBackend *self, alpm_pkg_t *pkg, gint *result) { gchar *output; g_return_if_fail (self != NULL); g_return_if_fail (pkg != NULL); g_return_if_fail (result != NULL); switch (pk_backend_job_get_role (self)) { case PK_ROLE_ENUM_INSTALL_PACKAGES: output = g_strdup_printf ("%s: was not ignored\n", alpm_pkg_get_name (pkg)); pk_backend_output (self, output); g_free (output); case PK_ROLE_ENUM_DOWNLOAD_PACKAGES: case PK_ROLE_ENUM_SIMULATE_INSTALL_PACKAGES: *result = 1; break; default: *result = 0; break; } }
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; }
static PyObject* pyalpm_pkg_str(PyObject *rawself) { AlpmPackage *self = (AlpmPackage *)rawself; return PyUnicode_FromFormat("alpm.Package(\"%s-%s-%s\")", alpm_pkg_get_name(self->c_data), alpm_pkg_get_version(self->c_data), alpm_pkg_get_arch(self->c_data)); }
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); }
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); }
/* verify that required db files exist */ static int check_db_files(alpm_pkg_t *pkg) { const char *pkgname = alpm_pkg_get_name(pkg); char *dbpath; int ret = 0; if((dbpath = get_db_path(pkg, "desc")) == NULL) { pu_ui_warn("%s: '%s' read error (%s)", pkgname, dbpath, strerror(errno)); } else if(check_file(pkgname, dbpath, 0) != 0) { ret = 1; } if((dbpath = get_db_path(pkg, "files")) == NULL) { pu_ui_warn("%s: '%s' read error (%s)", pkgname, dbpath, strerror(errno)); } else if(check_file(pkgname, dbpath, 0) != 0) { ret = 1; } if(!require_mtree) { return ret; } if((dbpath = get_db_path(pkg, "mtree")) == NULL) { pu_ui_warn("%s: '%s' read error (%s)", pkgname, dbpath, strerror(errno)); } else if(check_file(pkgname, dbpath, 0) != 0) { ret = 1; } return ret; }
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; } /* }}} */
/* -Qs, only 1 target for now */ static int query_search(alpm_db_t *localdb, const char *pkgname) { int ret, found; const char *repo; alpm_list_t *i, *k, *dbcache, *groups; alpm_list_t *syncdbs; alpm_pkg_t *pkg; dbcache = alpm_db_get_pkgcache(localdb); syncdbs = alpm_option_get_syncdbs(config->handle); for (k = dbcache; k; k = k->next) { pkg = k->data; groups = NULL; if (!strcmp(pkgname, alpm_pkg_get_name(pkg))) { repo = which_db(syncdbs, pkgname, &groups); color_repo(repo); printf("%s%s %s%s", color.bold, pkgname, color.bgreen, alpm_pkg_get_version(pkg)); color_groups(groups); printf("%s %s\n", TAB, alpm_pkg_get_desc(pkg)); found = 1; } } return found ? 0: -1; }
static int check_depends(alpm_pkg_t *p) { int ret = 0; alpm_list_t *i; for(i = alpm_pkg_get_depends(p); i; i = alpm_list_next(i)) { char *depstring = alpm_dep_compute_string(i->data); if(!alpm_find_satisfier(pkgcache, depstring)) { eprintf("%s: unsatisfied dependency '%s'\n", alpm_pkg_get_name(p), depstring); ret = 1; } free(depstring); } if(!quiet && !ret) { eprintf("%s: all dependencies satisfied\n", alpm_pkg_get_name(p)); } return ret; }
static gboolean pk_backend_match_name (alpm_pkg_t *pkg, GRegex *regex) { g_return_val_if_fail (pkg != NULL, FALSE); g_return_val_if_fail (regex != NULL, FALSE); /* match the name of the package */ return g_regex_match (regex, alpm_pkg_get_name (pkg), 0, NULL); }
static char *get_db_path(alpm_pkg_t *pkg, const char *path) { static char dbpath[PATH_MAX]; ssize_t len = snprintf(dbpath, PATH_MAX, "%slocal/%s-%s/%s", alpm_option_get_dbpath(handle), alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg), path); if(len < 0 || len >= PATH_MAX) { errno = ERANGE; return NULL; } /* TODO */ return dbpath; }
/* Loop through the files of the package to check if they exist. */ int check_pkg_fast(alpm_pkg_t *pkg) { const char *root, *pkgname; size_t errors = 0; size_t rootlen; char filepath[PATH_MAX]; alpm_filelist_t *filelist; size_t i; root = alpm_option_get_root(config->handle); rootlen = strlen(root); if(rootlen + 1 > PATH_MAX) { /* we are in trouble here */ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, ""); return 1; } strcpy(filepath, root); pkgname = alpm_pkg_get_name(pkg); filelist = alpm_pkg_get_files(pkg); for(i = 0; i < filelist->count; i++) { const alpm_file_t *file = filelist->files + i; struct stat st; int exists; const char *path = file->name; size_t plen = strlen(path); if(rootlen + 1 + plen > PATH_MAX) { pm_printf(ALPM_LOG_WARNING, _("path too long: %s%s\n"), root, path); continue; } strcpy(filepath + rootlen, path); exists = check_file_exists(pkgname, filepath, rootlen, &st); if(exists == 0) { int expect_dir = path[plen - 1] == '/' ? 1 : 0; int is_dir = S_ISDIR(st.st_mode) ? 1 : 0; if(expect_dir != is_dir) { pm_printf(ALPM_LOG_WARNING, _("%s: %s (File type mismatch)\n"), pkgname, filepath); ++errors; } } else if(exists == 1) { ++errors; } } if(!config->quiet) { printf(_n("%s: %jd total file, ", "%s: %jd total files, ", (unsigned long)filelist->count), pkgname, (intmax_t)filelist->count); printf(_n("%jd missing file\n", "%jd missing files\n", (unsigned long)errors), (intmax_t)errors); } return (errors != 0 ? 1 : 0); }