summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-01-05 21:29:36 +0000
committerAurelien Foret <aurelien@archlinux.org>2006-01-05 21:29:36 +0000
commitef8bbd2ac496604df949e0bce978a3c53dbaede3 (patch)
tree001130e87fe62a68344d88b65f11021c9312d48d /src
parent13cb20aeabe147629b22a6c85b6791044bbae465 (diff)
downloadpacman-ef8bbd2ac496604df949e0bce978a3c53dbaede3.tar.xz
various code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/pacman/list.h8
-rw-r--r--src/pacman/remove.c4
-rw-r--r--src/pacman/sync.c46
3 files changed, 31 insertions, 27 deletions
diff --git a/src/pacman/list.h b/src/pacman/list.h
index 79a4a3c0..ba72d784 100644
--- a/src/pacman/list.h
+++ b/src/pacman/list.h
@@ -30,6 +30,14 @@ typedef struct __list_t {
} list_t;
#define FREELIST(p) do { if(p) { list_free(p); p = NULL; } } while(0)
+#define FREELISTPTR(p) do { \
+ list_t *i; \
+ for(i = p; i; i = i->next) { \
+ i->data = NULL; \
+ } \
+ FREELIST(p); \
+} while(0)
+
list_t *list_new(void);
void list_free(list_t* list);
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 84cac94c..6dc3758c 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -138,7 +138,9 @@ int pacman_remove(list_t *targets)
error:
FREELIST(finaltargs);
- alpm_trans_release();
+ if(alpm_trans_release() == -1) {
+ ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
+ }
return(1);
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index aa4006b3..273636ac 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -327,10 +327,7 @@ static int sync_list(list_t *syncs, list_t *targets)
if(sync == NULL) {
ERR(NL, "repository \"%s\" was not found.\n", (char *)i->data);
- for(j = ls; j; j = j->next) {
- j->data = NULL;
- }
- list_free(ls);
+ FREELISTPTR(ls);
return(1);
}
@@ -352,10 +349,7 @@ static int sync_list(list_t *syncs, list_t *targets)
}
if(targets) {
- for(i = ls; i; i = i->next) {
- i->data = NULL;
- }
- list_free(ls);
+ FREELISTPTR(ls);
}
return(0);
@@ -514,19 +508,20 @@ int pacman_sync(list_t *targets)
goto cleanup;
}
+ packages = alpm_trans_getinfo(PM_TRANS_PACKAGES);
+ if(packages == NULL) {
+ retval = 0;
+ goto cleanup;
+ }
+
/* list targets and get confirmation */
if(!config->op_s_printuris) {
- list_t *list = NULL;
+ list_t *list_install = NULL;
+ list_t *list_remove = NULL;
char *str;
unsigned long totalsize = 0;
double mb;
- packages = alpm_trans_getinfo(PM_TRANS_PACKAGES);
- if(packages == NULL) {
- retval = 0;
- goto cleanup;
- }
-
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
PM_SYNCPKG *sync = alpm_list_getdata(lp);
if((int)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) {
@@ -535,18 +530,18 @@ int pacman_sync(list_t *targets)
for(j = alpm_list_first(data); j; j = alpm_list_next(j)) {
PM_PKG *p = alpm_list_getdata(j);
char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME);
- if(!list_is_strin(pkgname, list)) {
- list = list_add(list, strdup(pkgname));
+ if(!list_is_strin(pkgname, list_remove)) {
+ list_remove = list_add(list_remove, pkgname);
}
}
}
}
- if(list) {
+ if(list_remove) {
printf("\nRemove: ");
- str = buildstring(list);
+ str = buildstring(list_remove);
indentprint(str, 9);
printf("\n");
- FREELIST(list);
+ FREELISTPTR(list_remove);
FREE(str);
}
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
@@ -556,11 +551,10 @@ int pacman_sync(list_t *targets)
pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION);
+ totalsize += (int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
asprintf(&str, "%s-%s", pkgname, pkgver);
- list = list_add(list, str);
-
- totalsize += (int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
+ list_install = list_add(list_install, str);
}
mb = (double)(totalsize / 1048576.0);
/* round up to 0.1 */
@@ -568,10 +562,10 @@ int pacman_sync(list_t *targets)
mb = 0.1;
}
MSG(NL, "\nTargets: ");
- str = buildstring(list);
+ str = buildstring(list_install);
indentprint(str, 9);
MSG(NL, "\nTotal Package Size: %.1f MB\n", mb);
- FREELIST(list);
+ FREELIST(list_install);
FREE(str);
if(config->op_s_downloadonly) {
@@ -616,7 +610,6 @@ int pacman_sync(list_t *targets)
PM_DB *dbs = alpm_pkg_getinfo(spkg, PM_PKG_DATA);
if(current->db == dbs) {
- struct stat buf;
char path[PATH_MAX];
char *pkgname, *pkgver;
@@ -633,6 +626,7 @@ int pacman_sync(list_t *targets)
server->server, server->path, path);
}
} else {
+ struct stat buf;
snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, pkgname, pkgver);
if(stat(path, &buf)) {
/* file is not in the cache dir, so add it to the list */