mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
various code cleanup
This commit is contained in:
parent
13cb20aeab
commit
ef8bbd2ac4
@ -33,14 +33,11 @@ typedef struct __pmlist_t PMList;
|
||||
|
||||
#define FREELIST(p) do { if(p) { pm_list_free(p); p = NULL; } } while(0)
|
||||
#define FREELISTPTR(p) do { \
|
||||
if(p) { \
|
||||
PMList *i; \
|
||||
for(i = p; i; i = i->next) { \
|
||||
i->data = NULL; \
|
||||
} \
|
||||
pm_list_free(p); \
|
||||
p = NULL; \
|
||||
} \
|
||||
FREELIST(p); \
|
||||
} while(0)
|
||||
|
||||
/* Sort comparison callback function declaration */
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/* list targets and get confirmation */
|
||||
if(!config->op_s_printuris) {
|
||||
list_t *list = NULL;
|
||||
char *str;
|
||||
unsigned long totalsize = 0;
|
||||
double mb;
|
||||
|
||||
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_install = NULL;
|
||||
list_t *list_remove = NULL;
|
||||
char *str;
|
||||
unsigned long totalsize = 0;
|
||||
double mb;
|
||||
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user