mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-10 11:35:00 -05: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 FREELIST(p) do { if(p) { pm_list_free(p); p = NULL; } } while(0)
|
||||||
#define FREELISTPTR(p) do { \
|
#define FREELISTPTR(p) do { \
|
||||||
if(p) { \
|
|
||||||
PMList *i; \
|
PMList *i; \
|
||||||
for(i = p; i; i = i->next) { \
|
for(i = p; i; i = i->next) { \
|
||||||
i->data = NULL; \
|
i->data = NULL; \
|
||||||
} \
|
} \
|
||||||
pm_list_free(p); \
|
FREELIST(p); \
|
||||||
p = NULL; \
|
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/* Sort comparison callback function declaration */
|
/* Sort comparison callback function declaration */
|
||||||
|
@ -30,6 +30,14 @@ typedef struct __list_t {
|
|||||||
} list_t;
|
} list_t;
|
||||||
|
|
||||||
#define FREELIST(p) do { if(p) { list_free(p); p = NULL; } } while(0)
|
#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);
|
list_t *list_new(void);
|
||||||
void list_free(list_t* list);
|
void list_free(list_t* list);
|
||||||
|
@ -138,7 +138,9 @@ int pacman_remove(list_t *targets)
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
alpm_trans_release();
|
if(alpm_trans_release() == -1) {
|
||||||
|
ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
|
||||||
|
}
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
@ -327,10 +327,7 @@ static int sync_list(list_t *syncs, list_t *targets)
|
|||||||
|
|
||||||
if(sync == NULL) {
|
if(sync == NULL) {
|
||||||
ERR(NL, "repository \"%s\" was not found.\n", (char *)i->data);
|
ERR(NL, "repository \"%s\" was not found.\n", (char *)i->data);
|
||||||
for(j = ls; j; j = j->next) {
|
FREELISTPTR(ls);
|
||||||
j->data = NULL;
|
|
||||||
}
|
|
||||||
list_free(ls);
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,10 +349,7 @@ static int sync_list(list_t *syncs, list_t *targets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(targets) {
|
if(targets) {
|
||||||
for(i = ls; i; i = i->next) {
|
FREELISTPTR(ls);
|
||||||
i->data = NULL;
|
|
||||||
}
|
|
||||||
list_free(ls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
@ -514,19 +508,20 @@ int pacman_sync(list_t *targets)
|
|||||||
goto cleanup;
|
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);
|
packages = alpm_trans_getinfo(PM_TRANS_PACKAGES);
|
||||||
if(packages == NULL) {
|
if(packages == NULL) {
|
||||||
retval = 0;
|
retval = 0;
|
||||||
goto cleanup;
|
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)) {
|
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
||||||
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
||||||
if((int)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) {
|
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)) {
|
for(j = alpm_list_first(data); j; j = alpm_list_next(j)) {
|
||||||
PM_PKG *p = alpm_list_getdata(j);
|
PM_PKG *p = alpm_list_getdata(j);
|
||||||
char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME);
|
char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME);
|
||||||
if(!list_is_strin(pkgname, list)) {
|
if(!list_is_strin(pkgname, list_remove)) {
|
||||||
list = list_add(list, strdup(pkgname));
|
list_remove = list_add(list_remove, pkgname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(list) {
|
if(list_remove) {
|
||||||
printf("\nRemove: ");
|
printf("\nRemove: ");
|
||||||
str = buildstring(list);
|
str = buildstring(list_remove);
|
||||||
indentprint(str, 9);
|
indentprint(str, 9);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
FREELIST(list);
|
FREELISTPTR(list_remove);
|
||||||
FREE(str);
|
FREE(str);
|
||||||
}
|
}
|
||||||
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
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);
|
pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
|
||||||
pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION);
|
pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION);
|
||||||
|
totalsize += (int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
|
||||||
|
|
||||||
asprintf(&str, "%s-%s", pkgname, pkgver);
|
asprintf(&str, "%s-%s", pkgname, pkgver);
|
||||||
list = list_add(list, str);
|
list_install = list_add(list_install, str);
|
||||||
|
|
||||||
totalsize += (int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
|
|
||||||
}
|
}
|
||||||
mb = (double)(totalsize / 1048576.0);
|
mb = (double)(totalsize / 1048576.0);
|
||||||
/* round up to 0.1 */
|
/* round up to 0.1 */
|
||||||
@ -568,10 +562,10 @@ int pacman_sync(list_t *targets)
|
|||||||
mb = 0.1;
|
mb = 0.1;
|
||||||
}
|
}
|
||||||
MSG(NL, "\nTargets: ");
|
MSG(NL, "\nTargets: ");
|
||||||
str = buildstring(list);
|
str = buildstring(list_install);
|
||||||
indentprint(str, 9);
|
indentprint(str, 9);
|
||||||
MSG(NL, "\nTotal Package Size: %.1f MB\n", mb);
|
MSG(NL, "\nTotal Package Size: %.1f MB\n", mb);
|
||||||
FREELIST(list);
|
FREELIST(list_install);
|
||||||
FREE(str);
|
FREE(str);
|
||||||
|
|
||||||
if(config->op_s_downloadonly) {
|
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);
|
PM_DB *dbs = alpm_pkg_getinfo(spkg, PM_PKG_DATA);
|
||||||
|
|
||||||
if(current->db == dbs) {
|
if(current->db == dbs) {
|
||||||
struct stat buf;
|
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char *pkgname, *pkgver;
|
char *pkgname, *pkgver;
|
||||||
|
|
||||||
@ -633,6 +626,7 @@ int pacman_sync(list_t *targets)
|
|||||||
server->server, server->path, path);
|
server->server, server->path, path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
struct stat buf;
|
||||||
snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, pkgname, pkgver);
|
snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, pkgname, pkgver);
|
||||||
if(stat(path, &buf)) {
|
if(stat(path, &buf)) {
|
||||||
/* file is not in the cache dir, so add it to the list */
|
/* file is not in the cache dir, so add it to the list */
|
||||||
|
Loading…
Reference in New Issue
Block a user