summaryrefslogtreecommitdiffstats
path: root/src/pacman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman.c')
-rw-r--r--src/pacman.c71
1 files changed, 45 insertions, 26 deletions
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 <jvinet@zeroflux.org>
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
*
* 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 <jvinet@zeroflux.org>\n");
+ printf("/ _.-' .-. .-. .-. Copyright (C) 2002-2005 Judd Vinet <jvinet@zeroflux.org>\n");
printf("\\ '-. '-' '-' '-' \n");
printf(" '--' This program may be freely redistributed under\n");
printf(" the terms of the GNU General Public License\n\n");