From d48cc3bf5d0bc9aef5e816c81d3a0f6b8e2680c7 Mon Sep 17 00:00:00 2001 From: Judd Vinet Date: Tue, 11 Jan 2005 23:14:16 +0000 Subject: Imported from pacman-2.9.5.tar.gz --- ChangeLog | 6 +++++ Makefile.in | 2 +- src/convertdb.c | 2 +- src/db.c | 4 ++-- src/db.h | 2 +- src/list.c | 57 ++++++++++++++++++++++++++++++--------------- src/list.h | 3 ++- src/pacconf.h | 4 ++-- src/package.c | 9 ++++++-- src/package.h | 8 +++++-- src/pacman.c | 71 ++++++++++++++++++++++++++++++++++++--------------------- src/pacman.h | 4 ++-- src/pacsync.c | 2 +- src/pacsync.h | 2 +- src/rpmvercmp.c | 2 +- src/rpmvercmp.h | 2 +- src/util.c | 14 ++++++++++-- src/util.h | 2 +- src/vercmp.c | 2 +- 19 files changed, 131 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d9d4e2d..c6b9e42d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ VERSION DESCRIPTION ----------------------------------------------------------------------------- +2.9.5 - bugfix: missing files after re-ordering packages wrt + deps with --upgrade + - added "Repository" line to -Si output + - patch from Tommi Rantala to fix trim() behaviour with + empty or whitespace-only strings + - fixed removal order when using -Rc or -Rs 2.9.4 - fixed a bug that was introduced from another bugfix :-/ 2.9.3 - fixed a couple manpage typos - added --ignore to -S operations, works just like IgnorePkg diff --git a/Makefile.in b/Makefile.in index 2a9c733c..cd6b18bb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -34,7 +34,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) INSTALL_DATA = @INSTALL_DATA@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ -PACVER = 2.9.4 +PACVER = 2.9.5 TOPDIR = @srcdir@ SRCDIR = $(TOPDIR)/src/ diff --git a/src/convertdb.c b/src/convertdb.c index af083fb1..6fbebb23 100644 --- a/src/convertdb.c +++ b/src/convertdb.c @@ -1,7 +1,7 @@ /* * convertdb.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/db.c b/src/db.c index 8fb96fed..8dd12c98 100644 --- a/src/db.c +++ b/src/db.c @@ -1,7 +1,7 @@ /* * db.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -768,7 +768,7 @@ PMList* db_find_conflicts(pacdb_t *db, PMList *targets, char *root) for(k = dbpkg->files; k; k = k->next) { snprintf(str, PATH_MAX, "%s%s", root, (char*)k->data); stat(str, &buf2); - if(buf.st_ino == buf2.st_ino) { + if(buf.st_ino == buf2.st_ino && buf.st_dev == buf2.st_dev) { ok = 1; } } diff --git a/src/db.h b/src/db.h index eb346bdd..402280f8 100644 --- a/src/db.h +++ b/src/db.h @@ -1,7 +1,7 @@ /* * db.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/list.c b/src/list.c index 6abc0719..689a17d3 100644 --- a/src/list.c +++ b/src/list.c @@ -1,7 +1,7 @@ /* * list.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,27 +26,28 @@ #include #include "list.h" -/* 1: List seems to be OK. +/* Check PMList sanity + * + * 1: List seems to be OK. * 0: We're in deep ... */ - -int CheckList(PMList* list) +int check_list(PMList* list) { PMList* it = NULL; - if (list == NULL) - return 1; - - if (list->last == NULL) - return 0; - - for (it = list; it && it->next; it = it->next) - ; + if(list == NULL) { + return(1); + } + if(list->last == NULL) { + return(0); + } - if (it != list->last) - return 0; + for(it = list; it && it->next; it = it->next); + if(it != list->last) { + return(0); + } - return 1; + return(1); } PMList* list_new() @@ -119,7 +120,7 @@ PMList* list_add(PMList *list, void *data) PMList* list_remove(PMList* list, PMList* item) { - assert(CheckList(list)); + assert(check_list(list)); if (list == NULL || item == NULL) return NULL; @@ -157,7 +158,7 @@ PMList* list_remove(PMList* list, PMList* item) item->prev = item->next = NULL; list_free(item); - assert(CheckList(list)); + assert(check_list(list)); return list; } @@ -272,6 +273,24 @@ PMList *list_sort(PMList *list) return(lp); } +/* Reverse the order of a list + * + * The caller is responsible for freeing the old list + */ +PMList* list_reverse(PMList *list) +{ + /* simple but functional -- we just build a new list, starting + * with the old list's tail + */ + PMList *newlist = NULL; + PMList *lp; + + for(lp = list->last; lp; lp = lp->prev) { + newlist = list_add(newlist, lp->data); + } + return(newlist); +} + void list_display(const char *title, PMList *list) { PMList *lp; @@ -349,7 +368,7 @@ PMList* list_add_sorted(PMList *list, void *data, cmp_fn sortfunc) } if(prev != NULL) { - prev->next = add; /* In middle. */ + prev->next = add; /* In middle. */ } else { if (list == NULL) { add->last = add; @@ -357,7 +376,7 @@ PMList* list_add_sorted(PMList *list, void *data, cmp_fn sortfunc) add->last = list->last; list->last = NULL; } - list = add; /* Start or empty, new list head. */ + list = add; /* Start or empty, new list head. */ } return(list); diff --git a/src/list.h b/src/list.h index 4f8d917a..28ef2a6c 100644 --- a/src/list.h +++ b/src/list.h @@ -1,7 +1,7 @@ /* * list.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,6 +47,7 @@ PMList* list_merge(PMList *one, PMList *two); PMList* list_last(PMList* list); int list_strcmp(const void *s1, const void *s2); PMList *list_sort(PMList *list); +PMList *list_reverse(PMList *list); void list_display(const char *title, PMList *list); int strlist_cmp(const void *s1, const void *s2); diff --git a/src/pacconf.h b/src/pacconf.h index 889a6745..ceab2044 100644 --- a/src/pacconf.h +++ b/src/pacconf.h @@ -1,7 +1,7 @@ /* * pacconf.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #define _PAC_PACCONF_H #ifndef PACVER -#define PACVER "2.9.4" +#define PACVER "2.9.5" #endif #ifndef PACDBDIR diff --git a/src/package.c b/src/package.c index 644eea17..5eba3a49 100644 --- a/src/package.c +++ b/src/package.c @@ -1,7 +1,7 @@ /* * package.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -144,6 +144,8 @@ pkginfo_t* load_pkg(char *pkgfile) return(NULL); } + info->filename = strdup(pkgfile); + return(info); } @@ -260,6 +262,7 @@ pkginfo_t* newpkg() pkg->groups = NULL; pkg->provides = NULL; pkg->replaces = NULL; + pkg->filename = NULL; return(pkg); } @@ -278,6 +281,7 @@ void freepkg(pkginfo_t *pkg) FREELIST(pkg->groups); FREELIST(pkg->provides); FREELIST(pkg->replaces); + FREE(pkg->filename); FREE(pkg); return; } @@ -367,7 +371,7 @@ void dump_pkg_full(pkginfo_t *info) /* Display the content of a sync package */ -void dump_pkg_sync(pkginfo_t *info) +void dump_pkg_sync(pkginfo_t *info, char *treename) { PMList *pm; @@ -375,6 +379,7 @@ void dump_pkg_sync(pkginfo_t *info) return; } + printf("Repository : %s\n", treename); printf("Name : %s\n", info->name); printf("Version : %s\n", info->version); pm = list_sort(info->groups); diff --git a/src/package.h b/src/package.h index ea9a3248..ac300323 100644 --- a/src/package.h +++ b/src/package.h @@ -1,7 +1,7 @@ /* * package.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,6 +68,10 @@ typedef struct __pkginfo_t { PMList *requiredby; PMList *conflicts; PMList *provides; + /* if the package has an associated filename on the local system + * (eg, filename.pkg.tar.gz) then it will be stored here, otherwise NULL + */ + char *filename; } pkginfo_t; typedef struct __depend_t { @@ -89,7 +93,7 @@ void freepkg(pkginfo_t *pkg); int pkgcmp(const void *p1, const void *p2); int is_pkgin(pkginfo_t *needle, PMList *haystack); void dump_pkg_full(pkginfo_t *info); -void dump_pkg_sync(pkginfo_t *info); +void dump_pkg_sync(pkginfo_t *info, char *treename); int split_pkgname(char *pkgfile, char *name, char *version); #endif diff --git a/src/pacman.c b/src/pacman.c index 53fdd1cb..f12643e5 100644 --- a/src/pacman.c +++ b/src/pacman.c @@ -1,7 +1,7 @@ /* * pacman.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -75,13 +75,14 @@ unsigned short pmo_q_search = 0; unsigned short pmo_r_cascade = 0; unsigned short pmo_r_dbonly = 0; unsigned short pmo_r_recurse = 0; -unsigned short pmo_s_upgrade = 0; -unsigned short pmo_s_downloadonly = 0; -unsigned short pmo_s_printuris = 0; -unsigned short pmo_s_sync = 0; -unsigned short pmo_s_search = 0; unsigned short pmo_s_clean = 0; +unsigned short pmo_s_downloadonly = 0; PMList *pmo_s_ignore = NULL; +unsigned short pmo_s_info = 0; +unsigned short pmo_s_printuris = 0; +unsigned short pmo_s_search = 0; +unsigned short pmo_s_sync = 0; +unsigned short pmo_s_upgrade = 0; unsigned short pmo_group = 0; /* configuration file options */ char *pmo_dbpath = NULL; @@ -535,7 +536,7 @@ int pacman_sync(pacdb_t *db, PMList *targets) FREELIST(pkg); } FREELIST(groups); - } else if(pmo_q_info) { + } else if(pmo_s_info) { PMList *pkgs = NULL; int found; if(targets) { @@ -563,7 +564,7 @@ int pacman_sync(pacdb_t *db, PMList *targets) /* wtf */ continue; } - dump_pkg_sync(p); + dump_pkg_sync(p, dbs->sync->treename); printf("\n"); freepkg(p); found = 1; @@ -1445,9 +1446,8 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) char pm_install[PATH_MAX]; pkginfo_t *info = NULL; struct stat buf; - PMList *targ, *file, *lp, *j, *k; + PMList *targ, *lp, *j, *k; PMList *alltargs = NULL; - PMList *filenames = NULL; unsigned short real_pmo_upgrade; tartype_t gztype = { (openfunc_t) gzopen_frontend, @@ -1545,21 +1545,18 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) } /* check if an older version of said package is already in alltargs. * if so, replace it in the list */ - for(j = alltargs, k = filenames; j && j->data && k; j = j->next, k = k->next) { + for(j = alltargs; j && j->data; j = j->next) { pkginfo_t *pkg = (pkginfo_t*)j->data; if(!strcmp(pkg->name, info->name)) { if(rpmvercmp(pkg->version, info->version) < 0) { vprint("replacing older version in target list. "); FREEPKG(j->data); j->data = info; - FREE(k->data); - k->data = strdup(targ->data); } } } vprint("done\n"); alltargs = list_add(alltargs, info); - filenames = list_add(filenames, strdup(targ->data)); } printf("done.\n"); @@ -1670,7 +1667,7 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) /* re-order w.r.t. dependencies */ vprint("sorting by dependencies\n"); - lp = sortbydeps(alltargs); + lp = sortbydeps(alltargs, PM_ADD); /* free the old alltargs */ for(j = alltargs; j; j = j->next) { j->data = NULL; @@ -1708,7 +1705,7 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) * Install packages * */ - for(targ = alltargs, file = filenames; targ && file; targ = targ->next, file = file->next) { + for(targ = alltargs; targ; targ = targ->next) { pkginfo_t* oldpkg = NULL; info = (pkginfo_t*)targ->data; errors = 0; @@ -1733,7 +1730,7 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) /* pre_upgrade scriptlet */ if(info->scriptlet) { - runscriptlet(file->data, "pre_upgrade", info->version, oldpkg ? oldpkg->version : NULL); + runscriptlet(info->filename, "pre_upgrade", info->version, oldpkg ? oldpkg->version : NULL); } if(oldpkg) { @@ -1764,13 +1761,13 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) neednl = 1; /* pre_install scriptlet */ if(info->scriptlet) { - runscriptlet(file->data, "pre_install", info->version, NULL); + runscriptlet(info->filename, "pre_install", info->version, NULL); } } fflush(stdout); /* open the .tar.gz package */ - if(tar_open(&tar, (char*)file->data, &gztype, O_RDONLY, 0, TAR_GNU) == -1) { + if(tar_open(&tar, info->filename, &gztype, O_RDONLY, 0, TAR_GNU) == -1) { perror("could not open package"); return(1); } @@ -1990,7 +1987,7 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) * or installed as a dependency for another package */ info->reason = REASON_EXPLICIT; - if(is_in(file->data, dependonly) || pmo_d_resolve) { + if(is_in(info->filename, dependonly) || pmo_d_resolve) { info->reason = REASON_DEPEND; } /* make an install date (in UTC) */ @@ -2053,7 +2050,6 @@ int pacman_add(pacdb_t *db, PMList *targets, PMList *dependonly) FREEPKG(lp->data); } FREELIST(alltargs); - FREELIST(filenames); /* run ldconfig if it exists */ snprintf(expath, PATH_MAX, "%setc/ld.so.conf", pmo_root); @@ -2165,6 +2161,16 @@ int pacman_remove(pacdb_t *db, PMList *targets) alltargs = removedeps(db, alltargs); } + /* re-order w.r.t. dependencies */ + vprint("sorting by dependencies\n"); + lp = sortbydeps(alltargs, PM_REMOVE); + /* free the old alltargs */ + for(j = alltargs; j; j = j->next) { + j->data = NULL; + } + FREELIST(alltargs); + alltargs = lp; + if(pmo_r_recurse || pmo_r_cascade) { /* list targets */ list_display("\nTargets:", alltargs); @@ -2542,17 +2548,20 @@ int pacman_upgrade(pacdb_t *db, PMList *targets, PMList *dependonly) /* Re-order a list of target packages with respect to their dependencies. * - * Example: + * Example (PM_ADD): * A depends on C * B depends on A * Target order is A,B,C,D * * Should be re-ordered to C,A,B,D * + * mode should be either PM_ADD or PM_REMOVE. This affects the dependency + * order sortbydeps() will use. + * * This function returns the new PMList* target list. * */ -PMList* sortbydeps(PMList *targets) +PMList* sortbydeps(PMList *targets, int mode) { PMList *newtargs = NULL; PMList *i, *j, *k; @@ -2607,11 +2616,21 @@ PMList* sortbydeps(PMList *targets) for(i = targets; i; i = i->next) { i->data = NULL; } - list_free(targets); + FREELIST(targets); } targets = newtargs; clean = 1; } + if(mode == PM_REMOVE) { + /* we're removing packages, so reverse the order */ + newtargs = list_reverse(targets); + /* free the old one */ + for(i = targets; i; i = i->next) { + i->data = NULL; + } + FREELIST(targets); + targets = newtargs; + } return(targets); } @@ -3400,7 +3419,7 @@ int parseargs(int op, int argc, char **argv) case 'e': pmo_q_orphans = 1; break; case 'f': pmo_force = 1; break; case 'g': pmo_group = 1; break; - case 'i': pmo_q_info++; break; + case 'i': pmo_q_info++; pmo_s_info++; break; case 'k': pmo_r_dbonly = 1; break; case 'l': pmo_q_list = 1; break; case 'n': pmo_nosave = 1; break; @@ -3759,7 +3778,7 @@ void version(void) { printf("\n"); printf(" .--. Pacman v%s\n", PACVER); - printf("/ _.-' .-. .-. .-. Copyright (C) 2002-2004 Judd Vinet \n"); + printf("/ _.-' .-. .-. .-. Copyright (C) 2002-2005 Judd Vinet \n"); printf("\\ '-. '-' '-' '-' \n"); printf(" '--' This program may be freely redistributed under\n"); printf(" the terms of the GNU General Public License\n\n"); diff --git a/src/pacman.h b/src/pacman.h index e1a01e14..9e22bb31 100644 --- a/src/pacman.h +++ b/src/pacman.h @@ -1,7 +1,7 @@ /* * pacman.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ int pacman_query(pacdb_t *db, PMList *targets); int pacman_sync(pacdb_t *db, PMList *targets); int pacman_deptest(pacdb_t *db, PMList *targets); -PMList* sortbydeps(PMList *targets); +PMList* sortbydeps(PMList *targets, int mode); PMList* checkdeps(pacdb_t *db, unsigned short op, PMList *targets); PMList* removedeps(pacdb_t *db, PMList *targs); int resolvedeps(pacdb_t *local, PMList *databases, syncpkg_t *sync, PMList *list, PMList *trail); diff --git a/src/pacsync.c b/src/pacsync.c index 2b6e5b05..c2ff4bee 100644 --- a/src/pacsync.c +++ b/src/pacsync.c @@ -1,7 +1,7 @@ /* * pacsync.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/pacsync.h b/src/pacsync.h index 14675355..eb2505d8 100644 --- a/src/pacsync.h +++ b/src/pacsync.h @@ -1,7 +1,7 @@ /* * pacsync.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/rpmvercmp.c b/src/rpmvercmp.c index 5ea656e5..014e09ad 100644 --- a/src/rpmvercmp.c +++ b/src/rpmvercmp.c @@ -1,7 +1,7 @@ /* * rpmvercmp.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/rpmvercmp.h b/src/rpmvercmp.h index 14cf10f9..7c18e912 100644 --- a/src/rpmvercmp.h +++ b/src/rpmvercmp.h @@ -1,7 +1,7 @@ /* * rpmvercmp.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/util.c b/src/util.c index 0c922096..08241691 100644 --- a/src/util.c +++ b/src/util.c @@ -1,7 +1,7 @@ /* * util.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -281,12 +281,22 @@ char* strtoupper(char *str) char* trim(char *str) { char *pch = str; + + if(*str == '\0') + /* string is empty, so we're done. */ + return(str); + while(isspace(*pch)) { pch++; } if(pch != str) { memmove(str, pch, (strlen(pch) + 1)); } + + /* check if there wasn't anything but whitespace in the string. */ + if(*str == '\0') { + return(str); + } pch = (char*)(str + (strlen(str) - 1)); while(isspace(*pch)) { @@ -294,7 +304,7 @@ char* trim(char *str) } *++pch = '\0'; - return str; + return(str); } /* A cheap grep for text files, returns 1 if a substring diff --git a/src/util.h b/src/util.h index c2b9f250..2d711391 100644 --- a/src/util.h +++ b/src/util.h @@ -1,7 +1,7 @@ /* * util.h * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/vercmp.c b/src/vercmp.c index dc3833fb..0ed3da2e 100644 --- a/src/vercmp.c +++ b/src/vercmp.c @@ -1,7 +1,7 @@ /* * vercmp.c * - * Copyright (c) 2002-2004 by Judd Vinet + * Copyright (c) 2002-2005 by Judd Vinet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- cgit v1.2.3-24-g4f1b