summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am12
-rw-r--r--src/util/cleanupdelta.c12
-rw-r--r--src/util/pacsort.c2
-rw-r--r--src/util/pactree.c206
-rw-r--r--src/util/testdb.c107
-rw-r--r--src/util/testpkg.c5
6 files changed, 214 insertions, 130 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index e4af56cf..463abf7f 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -1,19 +1,23 @@
# paths set at make time
conffile = ${sysconfdir}/pacman.conf
dbpath = ${localstatedir}/lib/pacman/
+gpgdir = ${sysconfdir}/pacman.d/gnupg/
cachedir = ${localstatedir}/cache/pacman/pkg/
bin_PROGRAMS = vercmp testpkg testdb cleanupdelta pacsort pactree
DEFS = -DLOCALEDIR=\"@localedir@\" \
-DCONFFILE=\"$(conffile)\" \
- -DROOTDIR=\"$(ROOTDIR)\" \
-DDBPATH=\"$(dbpath)\" \
+ -DGPGDIR=\"$(gpgdir)\" \
-DCACHEDIR=\"$(cachedir)\" \
@DEFS@
-INCLUDES = -I$(top_srcdir)/lib/libalpm
-AM_CFLAGS = -pedantic -D_GNU_SOURCE
+AM_CPPFLAGS = \
+ -imacros $(top_builddir)/config.h \
+ -I$(top_srcdir)/lib/libalpm
+
+AM_CFLAGS = -pedantic -D_GNU_SOURCE $(WARNING_CFLAGS)
cleanupdelta_SOURCES = cleanupdelta.c
cleanupdelta_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
@@ -31,6 +35,6 @@ testpkg_SOURCES = testpkg.c
testpkg_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
vercmp_SOURCES = vercmp.c
-vercmp_LDADD = $(top_builddir)/lib/libalpm/version.lo
+vercmp_LDADD = $(top_builddir)/lib/libalpm/libalpm_la-version.lo
# vim:set ts=2 sw=2 noet:
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 6553e6f6..2f7720b5 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -17,8 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -56,10 +54,10 @@ 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 = alpm_list_getdata(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)) {
- char *delta = alpm_list_getdata(j);
+ const char *delta = j->data;
printf("%s\n", delta);
}
alpm_list_free(unused);
@@ -72,8 +70,8 @@ static void checkdbs(alpm_list_t *dbnames) {
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
for(i = dbnames; i; i = alpm_list_next(i)) {
- const char *dbname = alpm_list_getdata(i);
- db = alpm_db_register_sync(handle, dbname, level);
+ const char *dbname = i->data;
+ db = alpm_register_syncdb(handle, dbname, level);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database '%s' (%s)\n",
dbname, alpm_strerror(alpm_errno(handle)));
@@ -94,7 +92,7 @@ static void usage(void) {
int main(int argc, char *argv[])
{
const char *dbpath = DBPATH;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
int a = 1;
alpm_list_t *dbnames = NULL;
diff --git a/src/util/pacsort.c b/src/util/pacsort.c
index 0eedf59d..7275cc77 100644
--- a/src/util/pacsort.c
+++ b/src/util/pacsort.c
@@ -17,8 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
diff --git a/src/util/pactree.c b/src/util/pactree.c
index cee5433a..4488645f 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -17,8 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <ctype.h>
#include <getopt.h>
#include <stdio.h>
@@ -29,11 +27,18 @@
#define LINE_MAX 512
+typedef struct tdepth {
+ struct tdepth *prev;
+ struct tdepth *next;
+ int level;
+} tdepth;
+
/* output */
struct graph_style {
const char *provides;
const char *tip1;
const char *tip2;
+ const char *limb;
int indent;
};
@@ -41,6 +46,7 @@ static struct graph_style graph_default = {
" provides",
"|--",
"+--",
+ "|",
3
};
@@ -48,6 +54,7 @@ static struct graph_style graph_linear = {
"",
"",
"",
+ "",
0
};
@@ -119,13 +126,13 @@ char *strndup(const char *s, size_t n)
}
#endif
-static char *strtrim(char *str)
+static size_t strtrim(char *str)
{
- char *pch = str;
+ char *end, *pch = str;
if(str == NULL || *str == '\0') {
/* string is empty, so we're done. */
- return str;
+ return 0;
}
while(isspace((unsigned char)*pch)) {
@@ -142,21 +149,21 @@ static char *strtrim(char *str)
/* check if there wasn't anything but whitespace in the string. */
if(*str == '\0') {
- return str;
+ return 0;
}
- pch = (str + (strlen(str) - 1));
- while(isspace((unsigned char)*pch)) {
- pch--;
+ end = (str + strlen(str) - 1);
+ while(isspace((unsigned char)*end)) {
+ end--;
}
- *++pch = '\0';
+ *++end = '\0';
- return str;
+ return end - pch;
}
static int register_syncs(void) {
FILE *fp;
- char *ptr, *section = NULL;
+ char *section = NULL;
char line[LINE_MAX];
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
@@ -167,23 +174,26 @@ static int register_syncs(void) {
}
while(fgets(line, LINE_MAX, fp)) {
+ size_t linelen;
+ char *ptr;
+
/* ignore whole line and end of line comments */
if((ptr = strchr(line, '#'))) {
*ptr = '\0';
}
- strtrim(line);
+ linelen = strtrim(line);
- if(strlen(line) == 0) {
+ if(linelen == 0) {
continue;
}
- if(line[0] == '[' && line[strlen(line) - 1] == ']') {
+ if(line[0] == '[' && line[linelen - 1] == ']') {
free(section);
- section = strndup(&line[1], strlen(line) - 2);
+ section = strndup(&line[1], linelen - 2);
if(section && strcmp(section, "options") != 0) {
- alpm_db_register_sync(handle, section, level);
+ alpm_register_syncdb(handle, section, level);
}
}
}
@@ -291,28 +301,36 @@ static void cleanup(void)
}
/* pkg provides provision */
-static void print_text(const char *pkg, const char *provision, int depth)
+static void print_text(const char *pkg, const char *provision, tdepth *depth)
{
- int indent_sz = (depth + 1) * style->indent;
-
if(!pkg && !provision) {
/* not much we can do */
return;
}
+ /* print limbs */
+ while(depth->prev)
+ depth = depth->prev;
+ int level = 0;
+ printf("%s", color->branch1);
+ while(depth->next){
+ printf("%*s%-*s", style->indent * (depth->level - level), "",
+ style->indent, style->limb);
+ level = depth->level + 1;
+ depth = depth->next;
+ }
+ printf("%*s", style->indent * (depth->level - level), "");
+
+ /* print tip */
if(!pkg && provision) {
- /* we failed to resolve provision */
- printf("%s%*s%s%s%s [unresolvable]%s\n", color->branch1, indent_sz,
- style->tip1, color->leaf1, provision, color->branch1, color->off);
+ printf("%s%s%s%s [unresolvable]%s\n", style->tip1, color->leaf1,
+ provision, color->branch1, color->off);
} else if(provision && strcmp(pkg, provision) != 0) {
- /* pkg provides provision */
- printf("%s%*s%s%s%s%s %s%s%s\n", color->branch2, indent_sz, style->tip2,
- color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision,
+ printf("%s%s%s%s%s %s%s%s\n", style->tip2, color->leaf1, pkg,
+ color->leaf2, style->provides, color->leaf1, provision,
color->off);
} else {
- /* pkg is a normal package */
- printf("%s%*s%s%s%s\n", color->branch1, indent_sz, style->tip1, color->leaf1,
- pkg, color->off);
+ printf("%s%s%s%s\n", style->tip1, color->leaf1, pkg, color->off);
}
}
@@ -330,7 +348,7 @@ static void print_graph(const char *parentname, const char *pkgname, const char
}
/* parent depends on dep which is satisfied by pkg */
-static void print(const char *parentname, const char *pkgname, const char *depname, int depth)
+static void print(const char *parentname, const char *pkgname, const char *depname, tdepth *depth)
{
if(graphviz) {
print_graph(parentname, pkgname, depname);
@@ -346,7 +364,12 @@ static void print_start(const char *pkgname, const char *provname)
"node [style=filled, color=green];\n"
" \"START\" -> \"%s\";\n", pkgname);
} else {
- print_text(pkgname, provname, 0);
+ tdepth d = {
+ NULL,
+ NULL,
+ 0
+ };
+ print_text(pkgname, provname, &d);
}
}
@@ -358,92 +381,80 @@ static void print_end(void)
}
}
-static alpm_pkg_t *get_pkg_from_dbs(alpm_list_t *dbs, const char *needle) {
- alpm_list_t *i;
- alpm_pkg_t *ret;
-
- for(i = dbs; i; i = alpm_list_next(i)) {
- ret = alpm_db_get_pkg(alpm_list_getdata(i), needle);
- if(ret) {
- return ret;
- }
+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 NULL;
+ return names;
}
/**
- * walk dependencies in reverse, showing packages which require the target
+ * walk dependencies, showing dependencies of the target
*/
-static void walk_reverse_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
+static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev)
{
- alpm_list_t *required_by, *i;
+ alpm_list_t *deps, *i;
- if(!pkg || ((max_depth >= 0) && (depth == max_depth + 1))) {
+ if(!pkg || ((max_depth >= 0) && (depth->level > max_depth))) {
return;
}
walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
- required_by = alpm_pkg_compute_requiredby(pkg);
- for(i = required_by; i; i = alpm_list_next(i)) {
- const char *pkgname = alpm_list_getdata(i);
+ 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;
- if(alpm_list_find_str(walked, pkgname)) {
+ 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), pkgname, NULL, depth);
+ print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth);
}
} else {
- print(alpm_pkg_get_name(pkg), pkgname, NULL, depth);
- walk_reverse_deps(dblist, get_pkg_from_dbs(dblist, pkgname), depth + 1);
- }
- }
-
- FREELIST(required_by);
-}
-
-/**
- * walk dependencies, showing dependencies of the target
- */
-static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
-{
- alpm_list_t *i;
-
- if((max_depth >= 0) && (depth == max_depth + 1)) {
- return;
- }
-
- walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
-
- for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
- alpm_depend_t *depend = alpm_list_getdata(i);
- alpm_pkg_t *provider = alpm_find_dbs_satisfier(handle, dblist, depend->name);
-
- if(provider) {
- const char *provname = alpm_pkg_get_name(provider);
-
- if(alpm_list_find_str(walked, provname)) {
- /* 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), provname, depend->name, depth);
+ print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth);
+ if(dep_pkg) {
+ tdepth d = {
+ depth,
+ NULL,
+ depth->level + 1
+ };
+ depth->next = &d;
+ /* last dep, cut off the limb here */
+ if(!alpm_list_next(i)){
+ if(depth->prev){
+ depth->prev->next = &d;
+ d.prev = depth->prev;
+ depth = &d;
+ } else {
+ d.prev = NULL;
+ }
}
- } else {
- print(alpm_pkg_get_name(pkg), provname, depend->name, depth);
- walk_deps(dblist, provider, depth + 1);
+ walk_deps(dblist, dep_pkg, &d, rev);
+ depth->next = NULL;
}
- } else {
- /* unresolvable package */
- print(alpm_pkg_get_name(pkg), NULL, depend->name, depth);
}
}
+
+ if(rev) {
+ FREELIST(deps);
+ }
}
int main(int argc, char *argv[])
{
int freelist = 0, ret = 0;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
const char *target_name;
alpm_pkg_t *pkg;
alpm_list_t *dblist = NULL;
@@ -467,9 +478,9 @@ int main(int argc, char *argv[])
ret = 1;
goto finish;
}
- dblist = alpm_option_get_syncdbs(handle);
+ dblist = alpm_get_syncdbs(handle);
} else {
- dblist = alpm_list_add(dblist, alpm_option_get_localdb(handle));
+ dblist = alpm_list_add(dblist, alpm_get_localdb(handle));
freelist = 1;
}
@@ -485,11 +496,12 @@ int main(int argc, char *argv[])
print_start(alpm_pkg_get_name(pkg), target_name);
- if(reverse) {
- walk_reverse_deps(dblist, pkg, 1);
- } else {
- walk_deps(dblist, pkg, 1);
- }
+ tdepth d = {
+ NULL,
+ NULL,
+ 1
+ };
+ walk_deps(dblist, pkg, &d, reverse);
print_end();
diff --git a/src/util/testdb.c b/src/util/testdb.c
index d85687a4..2017b60f 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -17,8 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -94,17 +92,16 @@ static int check_localdb_files(void)
return ret;
}
-static int checkdeps(alpm_list_t *pkglist)
+static int check_deps(alpm_list_t *pkglist)
{
alpm_list_t *data, *i;
int ret = 0;
/* check dependencies */
data = alpm_checkdeps(handle, pkglist, NULL, pkglist, 0);
for(i = data; i; i = alpm_list_next(i)) {
- alpm_depmissing_t *miss = alpm_list_getdata(i);
+ alpm_depmissing_t *miss = i->data;
char *depstring = alpm_dep_compute_string(miss->depend);
- printf("missing dependency for %s : %s\n", miss->target,
- depstring);
+ printf("missing %s dependency for %s\n", depstring, miss->target);
free(depstring);
ret++;
}
@@ -112,14 +109,14 @@ static int checkdeps(alpm_list_t *pkglist)
return ret;
}
-static int checkconflicts(alpm_list_t *pkglist)
+static int check_conflicts(alpm_list_t *pkglist)
{
alpm_list_t *data, *i;
int ret = 0;
/* check conflicts */
data = alpm_checkconflicts(handle, pkglist);
for(i = data; i; i = i->next) {
- alpm_conflict_t *conflict = alpm_list_getdata(i);
+ alpm_conflict_t *conflict = i->data;
printf("%s conflicts with %s\n",
conflict->package1, conflict->package2);
ret++;
@@ -128,6 +125,77 @@ static int checkconflicts(alpm_list_t *pkglist)
return ret;
}
+struct fileitem {
+ alpm_file_t *file;
+ alpm_pkg_t *pkg;
+};
+
+static int fileitem_cmp(const void *p1, const void *p2)
+{
+ const struct fileitem * fi1 = p1;
+ const struct fileitem * fi2 = p2;
+ return strcmp(fi1->file->name, fi2->file->name);
+}
+
+static int check_filelists(alpm_list_t *pkglist)
+{
+ alpm_list_t *i;
+ int ret = 0;
+ size_t list_size = 4096;
+ size_t offset = 0, j;
+ struct fileitem *all_files;
+ struct fileitem *prev_fileitem = NULL;
+
+ all_files = malloc(list_size * sizeof(struct fileitem));
+
+ for(i = pkglist; i; i = i->next) {
+ alpm_pkg_t *pkg = i->data;
+ alpm_filelist_t *filelist = alpm_pkg_get_files(pkg);
+ for(j = 0; j < filelist->count; j++) {
+ alpm_file_t *file = filelist->files + j;
+ /* only add files, not directories, to our big list */
+ if(file->name[strlen(file->name) - 1] == '/') {
+ continue;
+ }
+
+ /* do we need to reallocate and grow our array? */
+ if(offset >= list_size) {
+ struct fileitem *new_files;
+ new_files = realloc(all_files, list_size * 2 * sizeof(struct fileitem));
+ if(!new_files) {
+ free(all_files);
+ return 1;
+ }
+ all_files = new_files;
+ list_size *= 2;
+ }
+
+ /* we can finally add it to the list */
+ all_files[offset].file = file;
+ all_files[offset].pkg = pkg;
+ offset++;
+ }
+ }
+
+ /* now sort the list so we can find duplicates */
+ qsort(all_files, offset, sizeof(struct fileitem), fileitem_cmp);
+
+ /* do a 'uniq' style check on the list */
+ for(j = 0; j < offset; j++) {
+ struct fileitem *fileitem = all_files + j;
+ if(prev_fileitem && fileitem_cmp(prev_fileitem, fileitem) == 0) {
+ printf("file owned by %s and %s: %s\n",
+ alpm_pkg_get_name(prev_fileitem->pkg),
+ alpm_pkg_get_name(fileitem->pkg),
+ fileitem->file->name);
+ }
+ prev_fileitem = fileitem;
+ }
+
+ free(all_files);
+ return ret;
+}
+
static int check_localdb(void)
{
int ret = 0;
@@ -139,10 +207,11 @@ static int check_localdb(void)
return ret;
}
- db = alpm_option_get_localdb(handle);
+ db = alpm_get_localdb(handle);
pkglist = alpm_db_get_pkgcache(db);
- ret += checkdeps(pkglist);
- ret += checkconflicts(pkglist);
+ ret += check_deps(pkglist);
+ ret += check_conflicts(pkglist);
+ ret += check_filelists(pkglist);
return ret;
}
@@ -154,8 +223,8 @@ static int check_syncdbs(alpm_list_t *dbnames)
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
for(i = dbnames; i; i = alpm_list_next(i)) {
- char *dbname = alpm_list_getdata(i);
- db = alpm_db_register_sync(handle, dbname, level);
+ const char *dbname = i->data;
+ db = alpm_register_syncdb(handle, dbname, level);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database (%s)\n",
alpm_strerror(alpm_errno(handle)));
@@ -165,7 +234,7 @@ static int check_syncdbs(alpm_list_t *dbnames)
pkglist = alpm_db_get_pkgcache(db);
syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist));
}
- ret += checkdeps(syncpkglist);
+ ret += check_deps(syncpkglist);
cleanup:
alpm_list_free(syncpkglist);
@@ -184,8 +253,8 @@ static void usage(void)
int main(int argc, char *argv[])
{
- int ret = 0;
- enum _alpm_errno_t err;
+ int errors = 0;
+ alpm_errno_t err;
const char *dbpath = DBPATH;
int a = 1;
alpm_list_t *dbnames = NULL;
@@ -216,13 +285,13 @@ int main(int argc, char *argv[])
alpm_option_set_logcb(handle, output_cb);
if(!dbnames) {
- ret = check_localdb();
+ errors = check_localdb();
} else {
- ret = check_syncdbs(dbnames);
+ errors = check_syncdbs(dbnames);
alpm_list_free(dbnames);
}
- cleanup(ret);
+ cleanup(errors > 0);
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index 90758e16..96400a75 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
{
int retval = 1; /* default = false */
alpm_handle_t *handle;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
alpm_pkg_t *pkg = NULL;
const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL;
@@ -59,6 +59,9 @@ int main(int argc, char *argv[])
/* let us get log messages from libalpm */
alpm_option_set_logcb(handle, output_cb);
+ /* set gpgdir to default */
+ alpm_option_set_gpgdir(handle, GPGDIR);
+
if(alpm_pkg_load(handle, argv[1], 1, level, &pkg) == -1
|| pkg == NULL) {
err = alpm_errno(handle);