summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/callback.c21
-rw-r--r--src/pacman/conf.c5
-rw-r--r--src/pacman/conf.h2
-rw-r--r--src/pacman/package.c4
-rw-r--r--src/pacman/pacman.c12
-rw-r--r--src/pacman/query.c36
-rw-r--r--src/pacman/remove.c23
-rw-r--r--src/pacman/sync.c71
-rw-r--r--src/pacman/upgrade.c2
-rw-r--r--src/pacman/util.c48
-rw-r--r--src/pacman/util.h4
-rw-r--r--src/util/testdb.c175
12 files changed, 263 insertions, 140 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 6f41df7c..6e7930cb 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -201,7 +201,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
(char *)alpm_pkg_get_name(data1),
(char *)alpm_pkg_get_version(data2),
(char *)alpm_pkg_get_version(data1));
- display_optdepends(data1);
+ display_new_optdepends(data2,data1);
break;
case PM_TRANS_EVT_INTEGRITY_START:
printf(_("checking package integrity...\n"));
@@ -224,9 +224,6 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
case PM_TRANS_EVT_SCRIPTLET_INFO:
printf("%s", (char*)data1);
break;
- case PM_TRANS_EVT_PRINTURI:
- printf("%s/%s\n", (char*)data1, (char*)data2);
- break;
case PM_TRANS_EVT_RETRIEVE_START:
printf(_(":: Retrieving packages from %s...\n"), (char*)data1);
break;
@@ -253,33 +250,29 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
case PM_TRANS_CONV_INSTALL_IGNOREPKG:
if(data2) {
/* TODO we take this route based on data2 being not null? WTF */
- *response = yesno(1, _(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway?"),
+ *response = yesno(_(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway?"),
alpm_pkg_get_name(data2),
alpm_pkg_get_name(data1));
} else {
- *response = yesno(1, _(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
+ *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
alpm_pkg_get_name(data1));
}
break;
- case PM_TRANS_CONV_REMOVE_HOLDPKG:
- *response = yesno(1, _(":: %s is designated as a HoldPkg. Remove anyway?"),
- alpm_pkg_get_name(data1));
- break;
case PM_TRANS_CONV_REPLACE_PKG:
- *response = yesno(1, _(":: Replace %s with %s/%s?"),
+ *response = yesno(_(":: Replace %s with %s/%s?"),
alpm_pkg_get_name(data1),
(char *)data3,
alpm_pkg_get_name(data2));
break;
case PM_TRANS_CONV_CONFLICT_PKG:
- *response = yesno(1, _(":: %s conflicts with %s. Remove %s?"),
+ *response = yesno(_(":: %s conflicts with %s. Remove %s?"),
(char *)data1,
(char *)data2,
(char *)data2);
break;
case PM_TRANS_CONV_LOCAL_NEWER:
if(!config->op_s_downloadonly) {
- *response = yesno(1, _(":: %s-%s: local version is newer. Upgrade anyway?"),
+ *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"),
alpm_pkg_get_name(data1),
alpm_pkg_get_version(data1));
} else {
@@ -287,7 +280,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
}
break;
case PM_TRANS_CONV_CORRUPTED_PKG:
- *response = yesno(1, _(":: File %s is corrupted. Do you want to delete it?"),
+ *response = yesno(_(":: File %s is corrupted. Do you want to delete it?"),
(char *)data1);
break;
}
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 48c927bf..ca5cd123 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -44,10 +44,6 @@ config_t *config_new(void)
newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
/* CONFFILE is defined at compile-time */
newconfig->configfile = strdup(CONFFILE);
- newconfig->rootdir = NULL;
- newconfig->dbpath = NULL;
- newconfig->logfile = NULL;
- newconfig->syncfirst = NULL;
return(newconfig);
}
@@ -58,6 +54,7 @@ int config_free(config_t *oldconfig)
return(-1);
}
+ FREELIST(oldconfig->holdpkg);
FREELIST(oldconfig->syncfirst);
free(oldconfig->configfile);
free(oldconfig->rootdir);
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 9d2318df..466d9832 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -57,6 +57,7 @@ typedef struct __config_t {
unsigned short op_s_sync;
unsigned short op_s_search;
unsigned short op_s_upgrade;
+ unsigned short op_s_printuris;
unsigned short group;
pmtransflag_t flags;
@@ -68,6 +69,7 @@ typedef struct __config_t {
* downloaded of the total download list */
unsigned short totaldownload;
unsigned short cleanmethod; /* select -Sc behavior */
+ alpm_list_t *holdpkg;
alpm_list_t *syncfirst;
} config_t;
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 71be2d8c..b23c577f 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -79,7 +79,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
/* turn depends list into a text list */
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
pmdepend_t *dep = (pmdepend_t*)alpm_list_getdata(i);
- depstrings = alpm_list_add(depstrings, alpm_dep_get_string(dep));
+ depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
}
if(level>0) {
@@ -176,7 +176,7 @@ void dump_pkg_backups(pmpkg_t *pkg)
snprintf(path, PATH_MAX-1, "%s%s", root, str);
/* if we find the file, calculate checksums, otherwise it is missing */
if(access(path, R_OK) == 0) {
- char *md5sum = alpm_get_md5sum(path);
+ char *md5sum = alpm_compute_md5sum(path);
if(md5sum == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR,
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index c7db3b48..59916d62 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -113,7 +113,7 @@ static void usage(int op, const char * const myname)
printf(_(" -p, --file <package> query a package file instead of the database\n"));
printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n"));
printf(_(" -t, --unrequired list all packages not required by any package\n"));
- printf(_(" -u, --upgrades list all packages that can be upgraded\n"));
+ printf(_(" -u, --upgrades list all outdated packages\n"));
printf(_(" -q, --quiet show less information for query and search\n"));
} else if(op == PM_OP_SYNC) {
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
@@ -478,7 +478,8 @@ static int parseargs(int argc, char *argv[])
case 'o': config->op_q_owns = 1; break;
case 'p':
config->op_q_isfile = 1;
- config->flags |= PM_TRANS_FLAG_PRINTURIS;
+ config->op_s_printuris = 1;
+ config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break;
case 'q':
config->quiet = 1;
@@ -539,6 +540,11 @@ static int parseargs(int argc, char *argv[])
}
/* helper for being used with setrepeatingoption */
+static void option_add_holdpkg(const char *name) {
+ config->holdpkg = alpm_list_add(config->holdpkg, strdup(name));
+}
+
+/* helper for being used with setrepeatingoption */
static void option_add_syncfirst(const char *name) {
config->syncfirst = alpm_list_add(config->syncfirst, strdup(name));
}
@@ -701,7 +707,7 @@ static int _parseconfig(const char *file, const char *givensection,
} else if(strcmp(key, "IgnoreGroup") == 0) {
setrepeatingoption(ptr, "IgnoreGroup", alpm_option_add_ignoregrp);
} else if(strcmp(key, "HoldPkg") == 0) {
- setrepeatingoption(ptr, "HoldPkg", alpm_option_add_holdpkg);
+ setrepeatingoption(ptr, "HoldPkg", option_add_holdpkg);
} else if(strcmp(key, "SyncFirst") == 0) {
setrepeatingoption(ptr, "SyncFirst", option_add_syncfirst);
} else if(strcmp(key, "DBPath") == 0) {
diff --git a/src/pacman/query.c b/src/pacman/query.c
index d899539f..0d48638f 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -103,7 +103,7 @@ static int query_fileowner(alpm_list_t *targets)
root = alpm_option_get_root();
- for(i = alpm_db_getpkgcache(db_local); i && !found; i = alpm_list_next(i)) {
+ for(i = alpm_db_get_pkgcache(db_local); i && !found; i = alpm_list_next(i)) {
pmpkg_t *info = alpm_list_getdata(i);
for(j = alpm_pkg_get_files(info); j && !found; j = alpm_list_next(j)) {
@@ -154,7 +154,7 @@ static int query_search(alpm_list_t *targets)
searchlist = alpm_db_search(db_local, targets);
freelist = 1;
} else {
- searchlist = alpm_db_getpkgcache(db_local);
+ searchlist = alpm_db_get_pkgcache(db_local);
freelist = 0;
}
if(searchlist == NULL) {
@@ -215,7 +215,7 @@ static int query_group(alpm_list_t *targets)
char *grpname = NULL;
int ret = 0;
if(targets == NULL) {
- for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) {
+ for(j = alpm_db_get_grpcache(db_local); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j);
const alpm_list_t *p, *packages;
const char *grpname;
@@ -251,24 +251,6 @@ static int query_group(alpm_list_t *targets)
return ret;
}
-static int query_upgrades(void)
-{
- alpm_list_t *syncpkgs = NULL;
- printf(_("Checking for package upgrades... \n"));
-
- alpm_list_t *syncdbs = alpm_option_get_syncdbs();
- if(alpm_sync_sysupgrade(db_local, syncdbs, &syncpkgs) == -1) {
- return(-1);
- }
- if(syncpkgs) {
- display_synctargets(syncpkgs);
- return(0);
- }
-
- printf(_("no upgrades found.\n"));
- return(1);
-}
-
static int is_foreign(pmpkg_t *pkg)
{
const char *pkgname = alpm_pkg_get_name(pkg);
@@ -320,6 +302,10 @@ static int filter(pmpkg_t *pkg)
if(config->op_q_unrequired && !is_unrequired(pkg)) {
return(0);
}
+ /* check if this pkg is outdated */
+ if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) {
+ return(0);
+ }
return(1);
}
@@ -361,12 +347,6 @@ int pacman_query(alpm_list_t *targets)
return(ret);
}
- /* check for package upgrades */
- if(config->op_q_upgrade) {
- ret = query_upgrades();
- return(ret);
- }
-
/* looking for groups */
if(config->group) {
ret = query_group(targets);
@@ -391,7 +371,7 @@ int pacman_query(alpm_list_t *targets)
return(1);
}
- for(i = alpm_db_getpkgcache(db_local); i; i = alpm_list_next(i)) {
+ for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
if(filter(pkg)) {
display(pkg);
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index f091fa4d..11bc157f 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -75,10 +75,10 @@ int pacman_remove(alpm_list_t *targets)
}
printf(_(":: group %s:\n"), targ);
list_display(" ", pkgnames);
- int all = yesno(1, _(" Remove whole content?"));
+ int all = yesno(_(" Remove whole content?"));
for(p = pkgnames; p; p = alpm_list_next(p)) {
char *pkgn = alpm_list_getdata(p);
- if(all || yesno(1, _(":: Remove %s from group %s?"), pkgn, targ)) {
+ if(all || yesno(_(":: Remove %s from group %s?"), pkgn, targ)) {
if(alpm_trans_addtarget(pkgn) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
alpm_strerrorlast());
@@ -107,7 +107,7 @@ int pacman_remove(alpm_list_t *targets)
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
- char *depstring = alpm_dep_get_string(dep);
+ char *depstring = alpm_dep_compute_string(dep);
printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
depstring);
free(depstring);
@@ -121,6 +121,21 @@ int pacman_remove(alpm_list_t *targets)
goto cleanup;
}
+ /* Search for holdpkg in target list */
+ int holdpkg = 0;
+ for(i = alpm_trans_get_pkgs(); i; i = alpm_list_next(i)) {
+ pmpkg_t *pkg = alpm_list_getdata(i);
+ if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) {
+ pm_printf(PM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
+ alpm_pkg_get_name(pkg));
+ holdpkg = 1;
+ }
+ }
+ if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
+ retval = 1;
+ goto cleanup;
+ }
+
/* Warn user in case of dangerous operation */
if(config->flags & PM_TRANS_FLAG_RECURSE ||
config->flags & PM_TRANS_FLAG_CASCADE) {
@@ -131,7 +146,7 @@ int pacman_remove(alpm_list_t *targets)
printf("\n");
/* get confirmation */
- if(yesno(1, _("Do you want to remove these packages?")) == 0) {
+ if(yesno(_("Do you want to remove these packages?")) == 0) {
retval = 1;
goto cleanup;
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 00e477af..d8a63481 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -85,7 +85,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
/* We have a directory that doesn't match any syncdb.
* Ask the user if he wants to remove it. */
if(!found) {
- if(!yesno(1, _("Do you want to remove %s?"), path)) {
+ if(!yesno(_("Do you want to remove %s?"), path)) {
continue;
}
@@ -105,7 +105,7 @@ static int sync_cleandb_all(void) {
char newdbpath[PATH_MAX];
printf(_("Database directory: %s\n"), dbpath);
- if(!yesno(1, _("Do you want to remove unused repositories?"))) {
+ if(!yesno(_("Do you want to remove unused repositories?"))) {
return(0);
}
/* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/,
@@ -135,12 +135,12 @@ static int sync_cleancache(int level)
printf(_("Cache directory: %s\n"), cachedir);
switch(config->cleanmethod) {
case PM_CLEAN_KEEPINST:
- if(!yesno(1, _("Do you want to remove uninstalled packages from cache?"))) {
+ if(!yesno(_("Do you want to remove uninstalled packages from cache?"))) {
return(0);
}
break;
case PM_CLEAN_KEEPCUR:
- if(!yesno(1, _("Do you want to remove outdated packages from cache?"))) {
+ if(!yesno(_("Do you want to remove outdated packages from cache?"))) {
return(0);
}
break;
@@ -215,7 +215,7 @@ static int sync_cleancache(int level)
} else {
/* full cleanup */
printf(_("Cache directory: %s\n"), cachedir);
- if(!yesno(0, _("Do you want to remove ALL packages from cache?"))) {
+ if(!noyes(_("Do you want to remove ALL packages from cache?"))) {
return(0);
}
printf(_("removing all packages from cache... "));
@@ -286,7 +286,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
ret = alpm_db_search(db, targets);
freelist = 1;
} else {
- ret = alpm_db_getpkgcache(db);
+ ret = alpm_db_get_pkgcache(db);
freelist = 0;
}
if(ret == NULL) {
@@ -371,7 +371,7 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);
- for(j = alpm_db_getgrpcache(db); j; j = alpm_list_next(j)) {
+ for(j = alpm_db_get_grpcache(db); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j);
const char *grpname = alpm_grp_get_name(grp);
@@ -425,7 +425,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
return(1);
}
- for(k = alpm_db_getpkgcache(db); k; k = alpm_list_next(k)) {
+ for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
pmpkg_t *pkg = alpm_list_getdata(k);
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
@@ -446,7 +446,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
for(j = syncs; j; j = alpm_list_next(j)) {
pmdb_t *db = alpm_list_getdata(j);
- for(k = alpm_db_getpkgcache(db); k; k = alpm_list_next(k)) {
+ for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
pmpkg_t *pkg = alpm_list_getdata(k);
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
@@ -467,7 +467,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);
- for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) {
+ for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db));
}
}
@@ -510,7 +510,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
for(i = ls; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);
- for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) {
+ for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
pmpkg_t *pkg = alpm_list_getdata(j);
if (!config->quiet) {
printf("%s %s %s\n", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
@@ -605,14 +605,14 @@ static int sync_trans(alpm_list_t *targets)
(char*)alpm_pkg_get_name(k->data));
}
list_display(" ", pkgnames);
- if(yesno(1, _(":: Install whole content?"))) {
+ if(yesno(_(":: Install whole content?"))) {
for(k = pkgnames; k; k = alpm_list_next(k)) {
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
}
} else {
for(k = pkgnames; k; k = alpm_list_next(k)) {
char *pkgname = alpm_list_getdata(k);
- if(yesno(1, _(":: Install %s from group %s?"), pkgname, targ)) {
+ if(yesno(_(":: Install %s from group %s?"), pkgname, targ)) {
targets = alpm_list_add(targets, strdup(pkgname));
}
}
@@ -640,7 +640,7 @@ static int sync_trans(alpm_list_t *targets)
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
- char *depstring = alpm_dep_get_string(dep);
+ char *depstring = alpm_dep_compute_string(dep);
printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
depstring);
free(depstring);
@@ -667,23 +667,32 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
- int confirm;
+ /* Step 3: actually perform the operation */
+ if(config->op_s_printuris) {
+ /* print uris */
+ alpm_list_t *i;
+ for(i = packages; i; i = alpm_list_next(i)) {
+ pmpkg_t *pkg = alpm_sync_get_pkg((pmsyncpkg_t *)alpm_list_getdata(i));
+ pmdb_t *db = alpm_pkg_get_db(pkg);
+ printf("%s/%s\n", alpm_db_get_url(db), alpm_pkg_get_filename(pkg));
+ }
+ /* we are done */
+ goto cleanup;
+ }
- display_synctargets(packages);
- printf("\n");
+ display_synctargets(packages);
+ printf("\n");
- if(config->op_s_downloadonly) {
- confirm = yesno(1, _("Proceed with download?"));
- } else {
- confirm = yesno(1, _("Proceed with installation?"));
- }
- if(!confirm) {
- goto cleanup;
- }
- }/* else 'print uris' requested. We're done at this point */
+ int confirm;
+ if(config->op_s_downloadonly) {
+ confirm = yesno(_("Proceed with download?"));
+ } else {
+ confirm = yesno(_("Proceed with installation?"));
+ }
+ if(!confirm) {
+ goto cleanup;
+ }
- /* Step 3: actually perform the installation */
if(alpm_trans_commit(&data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast());
@@ -740,7 +749,7 @@ int pacman_sync(alpm_list_t *targets)
alpm_list_t *sync_dbs = NULL;
/* Display only errors with -Sp and -Sw operations */
- if(config->flags & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS)) {
+ if((config->flags & PM_TRANS_FLAG_DOWNLOADONLY) || config->op_s_printuris) {
config->logmask &= ~PM_LOG_WARNING;
}
@@ -812,13 +821,13 @@ int pacman_sync(alpm_list_t *targets)
}
alpm_list_t *targs = alpm_list_strdup(targets);
- if(!(config->flags & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS))) {
+ if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY) && !config->op_s_printuris) {
/* check for newer versions of packages to be upgraded first */
alpm_list_t *packages = syncfirst();
if(packages) {
printf(_(":: The following packages should be upgraded first :\n"));
list_display(" ", packages);
- if(yesno(1, _(":: Do you want to cancel the current operation\n"
+ if(yesno(_(":: Do you want to cancel the current operation\n"
":: and upgrade these packages now?"))) {
FREELIST(targs);
targs = packages;
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index c54b3ed7..2c996883 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -90,7 +90,7 @@ int pacman_upgrade(alpm_list_t *targets)
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
- char *depstring = alpm_dep_get_string(dep);
+ char *depstring = alpm_dep_compute_string(dep);
/* TODO indicate if the error was a virtual package or not:
* :: %s: requires %s, provided by %s
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 8cfa675a..b80b09ad 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -610,6 +610,25 @@ void display_synctargets(const alpm_list_t *syncpkgs)
alpm_list_free(rpkglist);
}
+/* Helper function for comparing strings using the
+ * alpm "compare func" signature */
+int str_cmp(const void *s1, const void *s2)
+{
+ return(strcmp(s1, s2));
+}
+
+void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg)
+{
+ alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
+ alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
+ alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
+ if(optdeps) {
+ printf(_("New optional dependencies for %s\n"), alpm_pkg_get_name(newpkg));
+ list_display_linebreak(" ", optdeps);
+ }
+ alpm_list_free(optdeps);
+}
+
void display_optdepends(pmpkg_t *pkg)
{
alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
@@ -620,10 +639,9 @@ void display_optdepends(pmpkg_t *pkg)
}
/* presents a prompt and gets a Y/N answer */
-int yesno(short preset, char *fmt, ...)
+static int question(short preset, char *fmt, va_list args)
{
char response[32];
- va_list args;
FILE *stream;
if(config->noconfirm) {
@@ -633,9 +651,7 @@ int yesno(short preset, char *fmt, ...)
stream = stderr;
}
- va_start(args, fmt);
vfprintf(stream, fmt, args);
- va_end(args);
if(preset) {
fprintf(stream, " %s ", _("[Y/n]"));
@@ -663,6 +679,30 @@ int yesno(short preset, char *fmt, ...)
return(0);
}
+int yesno(char *fmt, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, fmt);
+ ret = question(1, fmt, args);
+ va_end(args);
+
+ return(ret);
+}
+
+int noyes(char *fmt, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, fmt);
+ ret = question(0, fmt, args);
+ va_end(args);
+
+ return(ret);
+}
+
int pm_printf(pmloglevel_t level, const char *format, ...)
{
int ret;
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 5eeec8d2..64168587 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -54,8 +54,10 @@ void list_display(const char *title, const alpm_list_t *list);
void list_display_linebreak(const char *title, const alpm_list_t *list);
void display_targets(const alpm_list_t *pkgs, int install);
void display_synctargets(const alpm_list_t *syncpkgs);
+void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg);
void display_optdepends(pmpkg_t *pkg);
-int yesno(short preset, char *fmt, ...);
+int yesno(char *fmt, ...);
+int noyes(char *fmt, ...);
int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 87bfcf96..cbff5784 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -56,7 +56,7 @@ void output_cb(pmloglevel_t level, char *fmt, va_list args)
}
}
-static int db_test(char *dbpath)
+static int db_test(char *dbpath, int local)
{
struct dirent *ent;
char path[PATH_MAX];
@@ -70,7 +70,8 @@ static int db_test(char *dbpath)
}
while ((ent = readdir(dir)) != NULL) {
- if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
+ if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")
+ || ent->d_name[0] == '.') {
continue;
}
/* check for desc, depends, and files */
@@ -84,36 +85,133 @@ static int db_test(char *dbpath)
printf("%s: dependency file is missing\n", ent->d_name);
ret++;
}
- snprintf(path, PATH_MAX, "%s/%s/files", dbpath, ent->d_name);
- if(access(path, F_OK)) {
- printf("%s: file list is missing\n", ent->d_name);
- ret++;
+ if(local) {
+ snprintf(path, PATH_MAX, "%s/%s/files", dbpath, ent->d_name);
+ if(access(path, F_OK)) {
+ printf("%s: file list is missing\n", ent->d_name);
+ ret++;
+ }
}
}
return(ret);
}
-int main(int argc, char **argv)
+int checkdeps(alpm_list_t *pkglist)
{
- int retval = 0; /* default = false */
- pmdb_t *db = NULL;
- char *dbpath;
- char localdbpath[PATH_MAX];
- alpm_list_t *i;
+ alpm_list_t *data, *i;
+ int ret = 0;
+ /* check dependencies */
+ data = alpm_checkdeps(pkglist, 0, NULL, pkglist);
+ for(i = data; i; i = alpm_list_next(i)) {
+ pmdepmissing_t *miss = alpm_list_getdata(i);
+ pmdepend_t *dep = alpm_miss_get_dep(miss);
+ char *depstring = alpm_dep_compute_string(dep);
+ printf("missing dependency for %s : %s\n", alpm_miss_get_target(miss),
+ depstring);
+ free(depstring);
+ ret++;
+ }
+ return(ret);
+}
- if(argc == 1) {
- dbpath = DBPATH;
- } else if(argc == 3 && strcmp(argv[1], "-b") == 0) {
- dbpath = argv[2];
- } else {
- fprintf(stderr, "usage: %s -b <pacman db>\n", BASENAME);
- return(1);
+int checkconflicts(alpm_list_t *pkglist)
+{
+ alpm_list_t *data, *i;
+ int ret = 0;
+ /* check conflicts */
+ data = alpm_checkconflicts(pkglist);
+ for(i = data; i; i = i->next) {
+ pmconflict_t *conflict = alpm_list_getdata(i);
+ printf("%s conflicts with %s\n", alpm_conflict_get_package1(conflict),
+ alpm_conflict_get_package2(conflict));
+ ret++;
}
+ return(ret);
+}
+
+int check_localdb(char *dbpath) {
+ char localdbpath[PATH_MAX];
+ int ret = 0;
+ pmdb_t *db = NULL;
+ alpm_list_t *pkglist;
snprintf(localdbpath, PATH_MAX, "%s/local", dbpath);
- retval = db_test(localdbpath);
- if(retval) {
- return(retval);
+ ret = db_test(localdbpath, 1);
+ if(ret) {
+ return(ret);
+ }
+
+ db = alpm_db_register_local();
+ if(db == NULL) {
+ fprintf(stderr, "error: could not register 'local' database (%s)\n",
+ alpm_strerrorlast());
+ cleanup(EXIT_FAILURE);
+ }
+ pkglist = alpm_db_get_pkgcache(db);
+ ret += checkdeps(pkglist);
+ ret += checkconflicts(pkglist);
+ return(ret);
+}
+
+int check_syncdbs(char *dbpath, alpm_list_t *dbnames) {
+ char syncdbpath[PATH_MAX];
+ int ret = 0;
+ pmdb_t *db = NULL;
+ alpm_list_t *i, *pkglist, *syncpkglist = NULL;
+
+ for(i = dbnames; i; i = alpm_list_next(i)) {
+ char *dbname = alpm_list_getdata(i);
+ snprintf(syncdbpath, PATH_MAX, "%s/sync/%s", dbpath, dbname);
+ ret = db_test(syncdbpath, 0);
+ if(ret) {
+ return(ret);
+ }
+ db = alpm_db_register_sync(dbname);
+ if(db == NULL) {
+ fprintf(stderr, "error: could not register sync database (%s)\n",
+ alpm_strerrorlast());
+ cleanup(EXIT_FAILURE);
+ }
+ pkglist = alpm_db_get_pkgcache(db);
+ syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist));
+ }
+ ret += checkdeps(syncpkglist);
+ alpm_list_free(syncpkglist);
+
+ alpm_db_unregister_all();
+ return(ret);
+}
+
+void usage() {
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr,
+ "\t%s [-b <pacman db>] : check the local database\n", BASENAME);
+ fprintf(stderr,
+ "\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME);
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ int ret = 0;
+ char *dbpath = DBPATH;
+ int a = 1;
+ alpm_list_t *dbnames = NULL;
+
+ while(a < argc) {
+ if(strcmp(argv[a], "-b") == 0) {
+ if(++a < argc) {
+ dbpath = argv[a];
+ } else {
+ usage();
+ }
+ } else if(strcmp(argv[a], "-h") == 0 ||
+ strcmp(argv[a], "--help") == 0 ) {
+ usage();
+ } else {
+ dbnames = alpm_list_add(dbnames, argv[a]);
+ }
+ a++;
}
if(alpm_initialize() == -1) {
@@ -126,34 +224,15 @@ int main(int argc, char **argv)
alpm_option_set_dbpath(dbpath);
- db = alpm_db_register_local();
- if(db == NULL) {
- fprintf(stderr, "error: could not register 'local' database (%s)\n",
- alpm_strerrorlast());
- cleanup(EXIT_FAILURE);
- }
-
- /* check dependencies */
- alpm_list_t *data;
- data = alpm_checkdeps(db, 0, NULL, alpm_db_getpkgcache(db));
- for(i = data; i; i = alpm_list_next(i)) {
- pmdepmissing_t *miss = alpm_list_getdata(i);
- pmdepend_t *dep = alpm_miss_get_dep(miss);
- char *depstring = alpm_dep_get_string(dep);
- printf("missing dependency for %s : %s\n", alpm_miss_get_target(miss),
- depstring);
- free(depstring);
- }
-
- /* check conflicts */
- data = alpm_checkdbconflicts(db);
- for(i = data; i; i = i->next) {
- pmconflict_t *conflict = alpm_list_getdata(i);
- printf("%s conflicts with %s\n", alpm_conflict_get_package1(conflict),
- alpm_conflict_get_package2(conflict));
+ if(!dbnames) {
+ printf("Checking the integrity of the local database in %s\n",dbpath);
+ ret = check_localdb(dbpath);
+ } else {
+ printf("Checking the integrity of the sync databases in %s\n",dbpath);
+ ret = check_syncdbs(dbpath,dbnames);
}
- cleanup(retval);
+ cleanup(ret);
}
/* vim: set ts=2 sw=2 noet: */