Merged frugalware changes. Added a few other minor things too, but there's alot
to list. The diff should show you 8)
This commit is contained in:
parent
d37ad04873
commit
3f27542156
@ -9,17 +9,15 @@ AM_CFLAGS = -D_GNU_SOURCE \
|
||||
-I$(top_srcdir)/lib/libalpm \
|
||||
-I$(top_srcdir)/lib/libftp
|
||||
|
||||
pacman_SOURCES = util.c log.c list.c package.c db.c download.c trans.c add.c \
|
||||
pacman_SOURCES = util.c log.c list.c package.c download.c trans.c add.c \
|
||||
remove.c upgrade.c query.c sync.c conf.c deptest.c pacman.c
|
||||
|
||||
pacman_static_SOURCES = $(pacman_SOURCES)
|
||||
|
||||
pacman_LDADD = \
|
||||
$(top_srcdir)/lib/libalpm/libalpm.la \
|
||||
$(top_srcdir)/lib/libftp/libftp.la
|
||||
$(top_srcdir)/lib/libalpm/libalpm.la
|
||||
|
||||
pacman_static_LDADD = \
|
||||
$(top_srcdir)/lib/libalpm/.libs/libalpm.a \
|
||||
$(top_srcdir)/lib/libftp/.libs/libftp.a $(LDFLAGS)
|
||||
$(top_srcdir)/lib/libalpm/.libs/libalpm.a $(LDFLAGS)
|
||||
|
||||
pacman_static_LDFLAGS = -all-static
|
||||
|
@ -50,7 +50,7 @@ int pacman_add(list_t *targets)
|
||||
*/
|
||||
for(i = targets; i; i = i->next) {
|
||||
if(strstr(i->data, "://")) {
|
||||
char *str = fetch_pkgurl(i->data);
|
||||
char *str = alpm_fetch_pkgurl(i->data);
|
||||
if(str == NULL) {
|
||||
return(1);
|
||||
} else {
|
||||
@ -63,11 +63,11 @@ int pacman_add(list_t *targets)
|
||||
/* Step 1: create a new transaction
|
||||
*/
|
||||
if(alpm_trans_init((config->upgrade == 0) ? PM_TRANS_TYPE_ADD : PM_TRANS_TYPE_UPGRADE,
|
||||
config->flags, cb_trans_evt, cb_trans_conv) == -1) {
|
||||
config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
|
||||
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
||||
MSG(NL, _(" if you're sure a package manager is not already running,\n"
|
||||
" you can remove %s\n"), PM_LOCK);
|
||||
" you can remove %s%s\n"), config->root, PM_LOCK);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
@ -86,6 +86,7 @@ int pacman_add(list_t *targets)
|
||||
/* Step 2: "compute" the transaction based on targets and flags
|
||||
*/
|
||||
if(alpm_trans_prepare(&data) == -1) {
|
||||
long long *pkgsize, *freespace;
|
||||
PM_LIST *i;
|
||||
|
||||
ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
@ -95,7 +96,7 @@ int pacman_add(list_t *targets)
|
||||
PM_DEPMISS *miss = alpm_list_getdata(i);
|
||||
MSG(NL, _(":: %s: requires %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET),
|
||||
alpm_dep_getinfo(miss, PM_DEP_NAME));
|
||||
switch((int)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
||||
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
||||
case PM_DEP_MOD_EQ: MSG(CL, "=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
case PM_DEP_MOD_GE: MSG(CL, ">=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
case PM_DEP_MOD_LE: MSG(CL, "<=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
@ -115,16 +116,18 @@ int pacman_add(list_t *targets)
|
||||
case PM_ERR_FILE_CONFLICTS:
|
||||
for(i = alpm_list_first(data); i; i = alpm_list_next(i)) {
|
||||
PM_CONFLICT *conflict = alpm_list_getdata(i);
|
||||
switch((int)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
|
||||
switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
|
||||
case PM_CONFLICT_TYPE_TARGET:
|
||||
MSG(NL, _("%s exists in \"%s\" (target) and \"%s\" (target)"),
|
||||
MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"),
|
||||
config->root,
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_FILE),
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_TARGET),
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_CTARGET));
|
||||
break;
|
||||
case PM_CONFLICT_TYPE_FILE:
|
||||
MSG(NL, _("%s: %s exists in filesystem"),
|
||||
MSG(NL, _("%s: %s%s exists in filesystem"),
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_TARGET),
|
||||
config->root,
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_FILE));
|
||||
break;
|
||||
}
|
||||
@ -132,10 +135,19 @@ int pacman_add(list_t *targets)
|
||||
alpm_list_free(data);
|
||||
MSG(NL, _("\nerrors occurred, no packages were upgraded.\n"));
|
||||
break;
|
||||
case PM_ERR_DISK_FULL:
|
||||
i = alpm_list_first(data);
|
||||
pkgsize = alpm_list_getdata(i);
|
||||
i = alpm_list_next(i);
|
||||
freespace = alpm_list_getdata(i);
|
||||
MSG(NL, _(":: %.1f MB required, have %.1f MB"),
|
||||
(double)(*pkgsize / 1048576.0), (double)(*freespace / 1048576.0));
|
||||
alpm_list_free(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
retval = 1;
|
||||
retval=1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -143,16 +155,14 @@ int pacman_add(list_t *targets)
|
||||
*/
|
||||
if(alpm_trans_commit(NULL) == -1) {
|
||||
ERR(NL, _("failed to commit transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
retval=1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Step 4: release transaction resources
|
||||
*/
|
||||
cleanup:
|
||||
if(alpm_trans_release() == -1) {
|
||||
ERR(NL, _("failed to release transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
retval=1;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
|
@ -34,8 +34,6 @@
|
||||
#include "download.h"
|
||||
#include "conf.h"
|
||||
|
||||
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
|
||||
|
||||
extern list_t *pmc_syncs;
|
||||
|
||||
config_t *config_new()
|
||||
@ -56,303 +54,21 @@ int config_free(config_t *config)
|
||||
}
|
||||
|
||||
FREE(config->root);
|
||||
FREE(config->dbpath);
|
||||
FREE(config->cachedir);
|
||||
FREE(config->configfile);
|
||||
FREELIST(config->op_s_ignore);
|
||||
FREE(config->proxyhost);
|
||||
FREE(config->xfercommand);
|
||||
FREELIST(config->holdpkg);
|
||||
free(config);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int parseconfig(char *file, config_t *config)
|
||||
void cb_db_register(char *section, PM_DB *db)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char line[PATH_MAX+1];
|
||||
char *ptr = NULL;
|
||||
char *key = NULL;
|
||||
int linenum = 0;
|
||||
char section[256] = "";
|
||||
sync_t *sync = NULL;
|
||||
sync_t *sync;
|
||||
|
||||
if(config == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
fp = fopen(file, "r");
|
||||
if(fp == NULL) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
while(fgets(line, PATH_MAX, fp)) {
|
||||
linenum++;
|
||||
strtrim(line);
|
||||
if(strlen(line) == 0 || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
if(line[0] == '[' && line[strlen(line)-1] == ']') {
|
||||
/* new config section */
|
||||
ptr = line;
|
||||
ptr++;
|
||||
strncpy(section, ptr, min(255, strlen(ptr)-1));
|
||||
section[min(255, strlen(ptr)-1)] = '\0';
|
||||
vprint(_("config: new section '%s'\n"), section);
|
||||
if(!strlen(section)) {
|
||||
ERR(NL, _("config: line %d: bad section name\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
if(!strcmp(section, "local")) {
|
||||
ERR(NL, _("config: line %d: '%s' is reserved and cannot be used as a package tree\n"),
|
||||
linenum, section);
|
||||
return(1);
|
||||
}
|
||||
if(strcmp(section, "options")) {
|
||||
list_t *i;
|
||||
int found = 0;
|
||||
for(i = pmc_syncs; i && !found; i = i->next) {
|
||||
sync = (sync_t *)i->data;
|
||||
if(!strcmp(sync->treename, section)) {
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
/* start a new sync record */
|
||||
MALLOC(sync, sizeof(sync_t));
|
||||
sync->treename = strdup(section);
|
||||
sync->servers = NULL;
|
||||
pmc_syncs = list_add(pmc_syncs, sync);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* directive */
|
||||
ptr = line;
|
||||
key = strsep(&ptr, "=");
|
||||
if(key == NULL) {
|
||||
ERR(NL, _("config: line %d: syntax error\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
strtrim(key);
|
||||
key = strtoupper(key);
|
||||
if(!strlen(section) && strcmp(key, "INCLUDE")) {
|
||||
ERR(NL, _("config: line %d: all directives must belong to a section\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
if(ptr == NULL) {
|
||||
if(!strcmp(key, "NOPASSIVEFTP")) {
|
||||
config->nopassiveftp = 1;
|
||||
vprint(_("config: nopassiveftp\n"));
|
||||
} else if(!strcmp(key, "USESYSLOG")) {
|
||||
if(alpm_set_option(PM_OPT_USESYSLOG, (long)1) == -1) {
|
||||
ERR(NL, _("failed to set option USESYSLOG (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: usesyslog\n"));
|
||||
} else if(!strcmp(key, "ILOVECANDY")) {
|
||||
config->chomp = 1;
|
||||
} else {
|
||||
ERR(NL, _("config: line %d: syntax error\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
} else {
|
||||
strtrim(ptr);
|
||||
if(!strcmp(key, "INCLUDE")) {
|
||||
char conf[PATH_MAX];
|
||||
strncpy(conf, ptr, PATH_MAX);
|
||||
vprint(_("config: including %s\n"), conf);
|
||||
parseconfig(conf, config);
|
||||
} else if(!strcmp(section, "options")) {
|
||||
if(!strcmp(key, "NOUPGRADE")) {
|
||||
char *p = ptr;
|
||||
char *q;
|
||||
while((q = strchr(p, ' '))) {
|
||||
*q = '\0';
|
||||
if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) {
|
||||
ERR(NL, _("failed to set option NOUPGRADE (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: noupgrade: %s\n"), p);
|
||||
p = q;
|
||||
p++;
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) {
|
||||
ERR(NL, _("failed to set option NOUPGRADE (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: noupgrade: %s\n"), p);
|
||||
} else if(!strcmp(key, "NOEXTRACT")) {
|
||||
char *p = ptr;
|
||||
char *q;
|
||||
while((q = strchr(p, ' '))) {
|
||||
*q = '\0';
|
||||
if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) {
|
||||
ERR(NL, _("failed to set option NOEXTRACT (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: noextract: %s\n"), p);
|
||||
p = q;
|
||||
p++;
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) {
|
||||
ERR(NL, _("failed to set option NOEXTRACT (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: noextract: %s\n"), p);
|
||||
} else if(!strcmp(key, "IGNOREPKG")) {
|
||||
char *p = ptr;
|
||||
char *q;
|
||||
while((q = strchr(p, ' '))) {
|
||||
*q = '\0';
|
||||
if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) {
|
||||
ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: ignorepkg: %s\n"), p);
|
||||
p = q;
|
||||
p++;
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) {
|
||||
ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: ignorepkg: %s\n"), p);
|
||||
} else if(!strcmp(key, "HOLDPKG")) {
|
||||
char *p = ptr;
|
||||
char *q;
|
||||
while((q = strchr(p, ' '))) {
|
||||
*q = '\0';
|
||||
config->holdpkg = list_add(config->holdpkg, strdup(p));
|
||||
vprint(_("config: holdpkg: %s\n"), p);
|
||||
p = q;
|
||||
p++;
|
||||
}
|
||||
config->holdpkg = list_add(config->holdpkg, strdup(p));
|
||||
vprint(_("config: holdpkg: %s\n"), p);
|
||||
} else if(!strcmp(key, "DBPATH")) {
|
||||
/* shave off the leading slash, if there is one */
|
||||
if(*ptr == '/') {
|
||||
ptr++;
|
||||
}
|
||||
FREE(config->dbpath);
|
||||
config->dbpath = strdup(ptr);
|
||||
vprint(_("config: dbpath: %s\n"), ptr);
|
||||
} else if(!strcmp(key, "CACHEDIR")) {
|
||||
/* shave off the leading slash, if there is one */
|
||||
if(*ptr == '/') {
|
||||
ptr++;
|
||||
}
|
||||
FREE(config->cachedir);
|
||||
config->cachedir = strdup(ptr);
|
||||
vprint(_("config: cachedir: %s\n"), ptr);
|
||||
} else if (!strcmp(key, "LOGFILE")) {
|
||||
if(alpm_set_option(PM_OPT_LOGFILE, (long)ptr) == -1) {
|
||||
ERR(NL, _("failed to set option LOGFILE (%s)\n"), alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
vprint(_("config: log file: %s\n"), ptr);
|
||||
} else if (!strcmp(key, "XFERCOMMAND")) {
|
||||
FREE(config->xfercommand);
|
||||
config->xfercommand = strndup(ptr, PATH_MAX);
|
||||
vprint(_("config: xfercommand: %s\n"), config->xfercommand);
|
||||
} else if (!strcmp(key, "PROXYSERVER")) {
|
||||
char *p;
|
||||
if(config->proxyhost) {
|
||||
FREE(config->proxyhost);
|
||||
}
|
||||
p = strstr(ptr, "://");
|
||||
if(p) {
|
||||
p += 3;
|
||||
if(p == NULL || *p == '\0') {
|
||||
ERR(NL, _("config: line %d: bad server location\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
ptr = p;
|
||||
}
|
||||
config->proxyhost = strndup(ptr, PATH_MAX);
|
||||
vprint(_("config: proxyserver: %s\n"), config->proxyhost);
|
||||
} else if (!strcmp(key, "PROXYPORT")) {
|
||||
config->proxyport = (unsigned short)atoi(ptr);
|
||||
vprint(_("config: proxyport: %u\n"), config->proxyport);
|
||||
} else {
|
||||
ERR(NL, _("config: line %d: syntax error\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
} else {
|
||||
if(!strcmp(key, "SERVER")) {
|
||||
/* parse our special url */
|
||||
server_t *server;
|
||||
char *p;
|
||||
|
||||
MALLOC(server, sizeof(server_t));
|
||||
server->server = server->path = NULL;
|
||||
server->protocol = NULL;
|
||||
|
||||
p = strstr(ptr, "://");
|
||||
if(p == NULL) {
|
||||
ERR(NL, _("config: line %d: bad server location\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
*p = '\0';
|
||||
p++; p++; p++;
|
||||
if(p == NULL || *p == '\0') {
|
||||
ERR(NL, _("config: line %d: bad server location\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
server->protocol = strdup(ptr);
|
||||
if(!strcmp(server->protocol, "ftp") || !strcmp(server->protocol, "http")) {
|
||||
char *slash;
|
||||
/* split the url into domain and path */
|
||||
slash = strchr(p, '/');
|
||||
if(slash == NULL) {
|
||||
/* no path included, default to / */
|
||||
server->path = strdup("/");
|
||||
} else {
|
||||
/* add a trailing slash if we need to */
|
||||
if(slash[strlen(slash)-1] == '/') {
|
||||
server->path = strdup(slash);
|
||||
} else {
|
||||
if((server->path = (char *)malloc(strlen(slash)+2)) == NULL) {
|
||||
ERR(NL, _("could not allocate %d bytes\n"), sizeof(strlen(slash+2)));
|
||||
return(1);
|
||||
}
|
||||
sprintf(server->path, "%s/", slash);
|
||||
}
|
||||
*slash = '\0';
|
||||
}
|
||||
server->server = strdup(p);
|
||||
} else if(!strcmp(server->protocol, "file")){
|
||||
/* add a trailing slash if we need to */
|
||||
if(p[strlen(p)-1] == '/') {
|
||||
server->path = strdup(p);
|
||||
} else {
|
||||
server->path = (char *)malloc(strlen(p)+2);
|
||||
if(server->path == NULL) {
|
||||
ERR(NL, _("could not allocate %d bytes\n"), sizeof(strlen(p+2)));
|
||||
return(1);
|
||||
}
|
||||
sprintf(server->path, "%s/", p);
|
||||
}
|
||||
} else {
|
||||
ERR(NL, _("config: line %d: protocol %s is not supported\n"), linenum, ptr);
|
||||
return(1);
|
||||
}
|
||||
/* add to the list */
|
||||
vprint(_("config: %s: server: %s %s %s\n"), section, server->protocol, server->server, server->path);
|
||||
sync->servers = list_add(sync->servers, server);
|
||||
} else {
|
||||
ERR(NL, _("config: line %d: syntax error\n"), linenum);
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
line[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return(0);
|
||||
MALLOC(sync, sizeof(sync_t));
|
||||
sync->treename = strdup(section);
|
||||
sync->db = db;
|
||||
pmc_syncs = list_add(pmc_syncs, sync);
|
||||
}
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -43,31 +43,27 @@ typedef struct __config_t {
|
||||
unsigned short op_q_orphans;
|
||||
unsigned short op_q_owns;
|
||||
unsigned short op_q_search;
|
||||
unsigned short op_q_changelog;
|
||||
unsigned short op_s_clean;
|
||||
unsigned short op_s_dependsonly;
|
||||
unsigned short op_s_downloadonly;
|
||||
list_t *op_s_ignore;
|
||||
unsigned short op_s_info;
|
||||
unsigned short op_s_printuris;
|
||||
unsigned short op_s_sync;
|
||||
unsigned short op_s_search;
|
||||
unsigned short op_s_upgrade;
|
||||
unsigned short group;
|
||||
unsigned int flags;
|
||||
unsigned short debug;
|
||||
/* configuration file option */
|
||||
char *proxyhost;
|
||||
unsigned short proxyport;
|
||||
char *xfercommand;
|
||||
unsigned short chomp;
|
||||
unsigned short nopassiveftp;
|
||||
list_t *holdpkg;
|
||||
unsigned short noask;
|
||||
unsigned int ask;
|
||||
} config_t;
|
||||
|
||||
#define FREECONF(p) do { if(p) { config_free(p); p = NULL; } } while(0)
|
||||
|
||||
config_t *config_new(void);
|
||||
int config_free(config_t *config);
|
||||
int parseconfig(char *file, config_t *config);
|
||||
void cb_db_register(char *section, PM_DB *db);
|
||||
|
||||
#endif /* _PM_CONF_H */
|
||||
|
||||
|
@ -58,11 +58,11 @@ int pacman_deptest(list_t *targets)
|
||||
|
||||
/* we create a transaction to hold a dummy package to be able to use
|
||||
* deps checkings from alpm_trans_prepare() */
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_ADD, 0, NULL, NULL) == -1) {
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_ADD, 0, NULL, NULL, NULL) == -1) {
|
||||
ERR(NL, "%s", alpm_strerror(pm_errno));
|
||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
||||
MSG(NL, _(" if you're sure a package manager is not already running,\n"
|
||||
" you can remove %s\n"), PM_LOCK);
|
||||
" you can remove %s%s\n"), config->root, PM_LOCK);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
@ -108,7 +108,7 @@ int pacman_deptest(list_t *targets)
|
||||
PM_DEPMISS *miss = alpm_list_getdata(lp);
|
||||
if(!config->op_d_resolve) {
|
||||
MSG(NL, _("requires: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME));
|
||||
switch((int)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
||||
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
||||
case PM_DEP_MOD_EQ: MSG(CL, "=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
case PM_DEP_MOD_GE: MSG(CL, ">=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
case PM_DEP_MOD_LE: MSG(CL, "<=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
@ -153,9 +153,11 @@ int pacman_deptest(list_t *targets)
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if(alpm_trans_release() == -1) {
|
||||
ERR(NL, _("could not release transaction (%s)"), alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
if(!config->op_d_resolve) {
|
||||
if(alpm_trans_release() == -1) {
|
||||
ERR(NL, _("could not release transaction (%s)"), alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return(retval);
|
||||
|
@ -40,35 +40,42 @@
|
||||
#include "conf.h"
|
||||
|
||||
/* progress bar */
|
||||
static char sync_fnm[25];
|
||||
static int offset;
|
||||
static struct timeval t0, t;
|
||||
static float rate;
|
||||
static int xfered1;
|
||||
static unsigned char eta_h, eta_m, eta_s;
|
||||
char sync_fnm[25];
|
||||
int offset;
|
||||
struct timeval t0, t;
|
||||
float rate;
|
||||
int xfered1;
|
||||
unsigned char eta_h, eta_m, eta_s;
|
||||
|
||||
/* pacman options */
|
||||
extern config_t *config;
|
||||
|
||||
extern int maxcols;
|
||||
extern unsigned int maxcols;
|
||||
|
||||
static int log_progress(netbuf *ctl, int xfered, void *arg)
|
||||
int log_progress(netbuf *ctl, int xfered, void *arg)
|
||||
{
|
||||
int fsz = *(int*)arg;
|
||||
int pct = ((float)(xfered+offset) / fsz) * 100;
|
||||
int i, cur;
|
||||
static int lastpct=0;
|
||||
unsigned int i, cur;
|
||||
struct timeval t1;
|
||||
float timediff;
|
||||
/* a little hard to conceal easter eggs in open-source software, but
|
||||
* they're still fun. ;)
|
||||
*/
|
||||
int chomp;
|
||||
static unsigned short mouth;
|
||||
static unsigned int lastcur = 0;
|
||||
|
||||
if(config->noprogressbar) {
|
||||
/* we don't need that parameter */
|
||||
ctl=NULL;
|
||||
|
||||
if(config->noprogressbar || (pct == 100 && lastpct == 100)) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
alpm_get_option(PM_OPT_CHOMP, (long *)&chomp);
|
||||
|
||||
gettimeofday(&t1, NULL);
|
||||
if(xfered+offset == fsz) {
|
||||
t = t0;
|
||||
@ -100,7 +107,7 @@ static int log_progress(netbuf *ctl, int xfered, void *arg)
|
||||
printf(" %s [", sync_fnm);
|
||||
cur = (int)((maxcols-64)*pct/100);
|
||||
for(i = 0; i < maxcols-64; i++) {
|
||||
if(config->chomp) {
|
||||
if(chomp) {
|
||||
if(i < cur) {
|
||||
printf("-");
|
||||
} else {
|
||||
@ -132,459 +139,13 @@ static int log_progress(netbuf *ctl, int xfered, void *arg)
|
||||
} else {
|
||||
printf("] %3d%% %6dK %6.1fK/s %02d:%02d:%02d\r", pct, ((xfered+offset) / 1024), rate, eta_h, eta_m, eta_s);
|
||||
}
|
||||
if(lastpct != 100 && pct == 100) {
|
||||
printf("\n");
|
||||
}
|
||||
lastcur = cur;
|
||||
lastpct = pct;
|
||||
fflush(stdout);
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int copyfile(char *src, char *dest)
|
||||
{
|
||||
FILE *in, *out;
|
||||
size_t len;
|
||||
char buf[4097];
|
||||
|
||||
in = fopen(src, "r");
|
||||
if(in == NULL) {
|
||||
return(1);
|
||||
}
|
||||
out = fopen(dest, "w");
|
||||
if(out == NULL) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
while((len = fread(buf, 1, 4096, in))) {
|
||||
fwrite(buf, 1, len, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Download a list of files from a list of servers
|
||||
* - if one server fails, we try the next one in the list
|
||||
*
|
||||
* RETURN: 0 for successful download, 1 on error
|
||||
*/
|
||||
int downloadfiles(list_t *servers, const char *localpath, list_t *files)
|
||||
{
|
||||
return(!!downloadfiles_forreal(servers, localpath, files, NULL, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the real downloadfiles, used directly by sync_synctree() to check
|
||||
* modtimes on remote files.
|
||||
* - if *mtime1 is non-NULL, then only download files
|
||||
* if they are different than *mtime1. String should be in the form
|
||||
* "YYYYMMDDHHMMSS" to match the form of ftplib's FtpModDate() function.
|
||||
* - if *mtime2 is non-NULL, then it will be filled with the mtime
|
||||
* of the remote file (from MDTM FTP cmd or Last-Modified HTTP header).
|
||||
*
|
||||
* RETURN: 0 for successful download
|
||||
* -1 if the mtimes are identical
|
||||
* 1 on error
|
||||
*/
|
||||
int downloadfiles_forreal(list_t *servers, const char *localpath,
|
||||
list_t *files, const char *mtime1, char *mtime2)
|
||||
{
|
||||
int fsz;
|
||||
netbuf *control = NULL;
|
||||
list_t *lp;
|
||||
int done = 0;
|
||||
list_t *complete = NULL;
|
||||
list_t *i;
|
||||
|
||||
if(files == NULL) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
for(i = servers; i && !done; i = i->next) {
|
||||
server_t *server = (server_t*)i->data;
|
||||
|
||||
if(!config->xfercommand && strcmp(server->protocol, "file")) {
|
||||
if(!strcmp(server->protocol, "ftp") && !config->proxyhost) {
|
||||
FtpInit();
|
||||
vprint(_("connecting to %s:21\n"), server->server);
|
||||
if(!FtpConnect(server->server, &control)) {
|
||||
ERR(NL, _("cannot connect to %s\n"), server->server);
|
||||
continue;
|
||||
}
|
||||
if(!FtpLogin("anonymous", "arch@guest", control)) {
|
||||
ERR(NL, _("anonymous login failed\n"));
|
||||
FtpQuit(control);
|
||||
continue;
|
||||
}
|
||||
if(!FtpChdir(server->path, control)) {
|
||||
ERR(NL, _("could not cwd to %s: %s\n"), server->path, FtpLastResponse(control));
|
||||
FtpQuit(control);
|
||||
continue;
|
||||
}
|
||||
if(!config->nopassiveftp) {
|
||||
if(!FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, control)) {
|
||||
WARN(NL, _("failed to set passive mode\n"));
|
||||
}
|
||||
} else {
|
||||
vprint(_("FTP passive mode not set\n"));
|
||||
}
|
||||
} else if(config->proxyhost) {
|
||||
char *host;
|
||||
unsigned port;
|
||||
host = (config->proxyhost) ? config->proxyhost : server->server;
|
||||
port = (config->proxyport) ? config->proxyport : 80;
|
||||
if(strchr(host, ':')) {
|
||||
vprint(_("connecting to %s\n"), host);
|
||||
} else {
|
||||
vprint(_("connecting to %s:%u\n"), host, port);
|
||||
}
|
||||
if(!HttpConnect(host, port, &control)) {
|
||||
ERR(NL, _("cannot connect to %s\n"), host);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* set up our progress bar's callback (and idle timeout) */
|
||||
if(strcmp(server->protocol, "file") && control) {
|
||||
FtpOptions(FTPLIB_CALLBACK, (long)log_progress, control);
|
||||
FtpOptions(FTPLIB_IDLETIME, (long)1000, control);
|
||||
FtpOptions(FTPLIB_CALLBACKARG, (long)&fsz, control);
|
||||
FtpOptions(FTPLIB_CALLBACKBYTES, (10*1024), control);
|
||||
}
|
||||
}
|
||||
|
||||
/* get each file in the list */
|
||||
for(lp = files; lp; lp = lp->next) {
|
||||
char *fn = (char *)lp->data;
|
||||
|
||||
if(list_is_strin(fn, complete)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(config->xfercommand && strcmp(server->protocol, "file")) {
|
||||
int ret;
|
||||
int usepart = 0;
|
||||
char *ptr1, *ptr2;
|
||||
char origCmd[PATH_MAX];
|
||||
char parsedCmd[PATH_MAX] = "";
|
||||
char url[PATH_MAX];
|
||||
char cwd[PATH_MAX];
|
||||
/* build the full download url */
|
||||
snprintf(url, PATH_MAX, "%s://%s%s%s", server->protocol, server->server,
|
||||
server->path, fn);
|
||||
/* replace all occurrences of %o with fn.part */
|
||||
strncpy(origCmd, config->xfercommand, sizeof(origCmd));
|
||||
ptr1 = origCmd;
|
||||
while((ptr2 = strstr(ptr1, "%o"))) {
|
||||
usepart = 1;
|
||||
ptr2[0] = '\0';
|
||||
strcat(parsedCmd, ptr1);
|
||||
strcat(parsedCmd, fn);
|
||||
strcat(parsedCmd, ".part");
|
||||
ptr1 = ptr2 + 2;
|
||||
}
|
||||
strcat(parsedCmd, ptr1);
|
||||
/* replace all occurrences of %u with the download URL */
|
||||
strncpy(origCmd, parsedCmd, sizeof(origCmd));
|
||||
parsedCmd[0] = '\0';
|
||||
ptr1 = origCmd;
|
||||
while((ptr2 = strstr(ptr1, "%u"))) {
|
||||
ptr2[0] = '\0';
|
||||
strcat(parsedCmd, ptr1);
|
||||
strcat(parsedCmd, url);
|
||||
ptr1 = ptr2 + 2;
|
||||
}
|
||||
strcat(parsedCmd, ptr1);
|
||||
/* cwd to the download directory */
|
||||
getcwd(cwd, PATH_MAX);
|
||||
if(chdir(localpath)) {
|
||||
ERR(NL, _("could not chdir to %s\n"), localpath);
|
||||
return(1);
|
||||
}
|
||||
/* execute the parsed command via /bin/sh -c */
|
||||
vprint(_("running command: %s\n"), parsedCmd);
|
||||
ret = system(parsedCmd);
|
||||
if(ret == -1) {
|
||||
ERR(NL, _("running XferCommand: fork failed!\n"));
|
||||
return(1);
|
||||
} else if(ret != 0) {
|
||||
/* download failed */
|
||||
vprint(_("XferCommand command returned non-zero status code (%d)\n"), ret);
|
||||
} else {
|
||||
/* download was successful */
|
||||
complete = list_add(complete, fn);
|
||||
if(usepart) {
|
||||
char fnpart[PATH_MAX];
|
||||
/* rename "output.part" file to "output" file */
|
||||
snprintf(fnpart, PATH_MAX, "%s.part", fn);
|
||||
rename(fnpart, fn);
|
||||
}
|
||||
}
|
||||
chdir(cwd);
|
||||
} else {
|
||||
char output[PATH_MAX];
|
||||
int j, filedone = 0;
|
||||
char *ptr;
|
||||
struct stat st;
|
||||
snprintf(output, PATH_MAX, "%s/%s.part", localpath, fn);
|
||||
strncpy(sync_fnm, fn, 24);
|
||||
/* drop filename extension */
|
||||
ptr = strstr(fn, PM_EXT_DB);
|
||||
if(ptr && (ptr-fn) < 24) {
|
||||
sync_fnm[ptr-fn] = '\0';
|
||||
}
|
||||
ptr = strstr(fn, PM_EXT_PKG);
|
||||
if(ptr && (ptr-fn) < 24) {
|
||||
sync_fnm[ptr-fn] = '\0';
|
||||
}
|
||||
for(j = strlen(sync_fnm); j < 24; j++) {
|
||||
sync_fnm[j] = ' ';
|
||||
}
|
||||
sync_fnm[24] = '\0';
|
||||
offset = 0;
|
||||
|
||||
/* ETA setup */
|
||||
gettimeofday(&t0, NULL);
|
||||
t = t0;
|
||||
rate = 0;
|
||||
xfered1 = 0;
|
||||
eta_h = 0;
|
||||
eta_m = 0;
|
||||
eta_s = 0;
|
||||
|
||||
if(!strcmp(server->protocol, "ftp") && !config->proxyhost) {
|
||||
if(!FtpSize(fn, &fsz, FTPLIB_IMAGE, control)) {
|
||||
WARN(NL, _("failed to get filesize for %s\n"), fn);
|
||||
}
|
||||
/* check mtimes */
|
||||
if(mtime1) {
|
||||
char fmtime[64];
|
||||
if(!FtpModDate(fn, fmtime, sizeof(fmtime)-1, control)) {
|
||||
WARN(NL, _("failed to get mtime for %s\n"), fn);
|
||||
} else {
|
||||
strtrim(fmtime);
|
||||
if(mtime1 && !strcmp(mtime1, fmtime)) {
|
||||
/* mtimes are identical, skip this file */
|
||||
vprint(_("mtimes are identical, skipping %s\n"), fn);
|
||||
filedone = -1;
|
||||
complete = list_add(complete, fn);
|
||||
} else {
|
||||
if(mtime2) {
|
||||
strncpy(mtime2, fmtime, 15); /* YYYYMMDDHHMMSS (=14b) */
|
||||
mtime2[14] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!filedone) {
|
||||
if(!stat(output, &st)) {
|
||||
offset = (int)st.st_size;
|
||||
if(!FtpRestart(offset, control)) {
|
||||
WARN(NL, _("failed to resume download -- restarting\n"));
|
||||
/* can't resume: */
|
||||
/* unlink the file in order to restart download from scratch */
|
||||
unlink(output);
|
||||
}
|
||||
}
|
||||
if(!FtpGet(output, fn, FTPLIB_IMAGE, control)) {
|
||||
ERR(NL, _("\nfailed downloading %s from %s: %s\n"), fn, server->server, FtpLastResponse(control));
|
||||
/* we leave the partially downloaded file in place so it can be resumed later */
|
||||
} else {
|
||||
filedone = 1;
|
||||
}
|
||||
}
|
||||
} else if(!strcmp(server->protocol, "http") || (config->proxyhost && strcmp(server->protocol, "file"))) {
|
||||
char src[PATH_MAX];
|
||||
char *host;
|
||||
unsigned port;
|
||||
struct tm fmtime1;
|
||||
struct tm fmtime2;
|
||||
memset(&fmtime1, 0, sizeof(struct tm));
|
||||
memset(&fmtime2, 0, sizeof(struct tm));
|
||||
if(!strcmp(server->protocol, "http") && !config->proxyhost) {
|
||||
/* HTTP servers hang up after each request (but not proxies), so
|
||||
* we have to re-connect for each file.
|
||||
*/
|
||||
host = (config->proxyhost) ? config->proxyhost : server->server;
|
||||
port = (config->proxyhost) ? config->proxyport : 80;
|
||||
if(strchr(host, ':')) {
|
||||
vprint(_("connecting to %s\n"), host);
|
||||
} else {
|
||||
vprint(_("connecting to %s:%u\n"), host, port);
|
||||
}
|
||||
if(!HttpConnect(host, port, &control)) {
|
||||
ERR(NL, _("cannot connect to %s\n"), host);
|
||||
continue;
|
||||
}
|
||||
/* set up our progress bar's callback (and idle timeout) */
|
||||
if(strcmp(server->protocol, "file") && control) {
|
||||
FtpOptions(FTPLIB_CALLBACK, (long)log_progress, control);
|
||||
FtpOptions(FTPLIB_IDLETIME, (long)1000, control);
|
||||
FtpOptions(FTPLIB_CALLBACKARG, (long)&fsz, control);
|
||||
FtpOptions(FTPLIB_CALLBACKBYTES, (10*1024), control);
|
||||
}
|
||||
}
|
||||
|
||||
if(!stat(output, &st)) {
|
||||
offset = (int)st.st_size;
|
||||
}
|
||||
if(!config->proxyhost) {
|
||||
snprintf(src, PATH_MAX, "%s%s", server->path, fn);
|
||||
} else {
|
||||
snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, server->path, fn);
|
||||
}
|
||||
if(mtime1 && strlen(mtime1)) {
|
||||
struct tm tmref;
|
||||
time_t t, tref;
|
||||
int diff;
|
||||
/* date conversion from YYYYMMDDHHMMSS to "rfc1123-date" */
|
||||
sscanf(mtime1, "%4d%2d%2d%2d%2d%2d",
|
||||
&fmtime1.tm_year, &fmtime1.tm_mon, &fmtime1.tm_mday,
|
||||
&fmtime1.tm_hour, &fmtime1.tm_min, &fmtime1.tm_sec);
|
||||
fmtime1.tm_year -= 1900;
|
||||
fmtime1.tm_mon--;
|
||||
/* compute the week day because some web servers (like lighttpd) need them. */
|
||||
/* we set tmref to "Thu, 01 Jan 1970 00:00:00" */
|
||||
memset(&tmref, 0, sizeof(struct tm));
|
||||
tmref.tm_mday = 1;
|
||||
tref = mktime(&tmref);
|
||||
/* then we compute the difference with mtime1 */
|
||||
t = mktime(&fmtime1);
|
||||
diff = ((t-tref)/3600/24)%7;
|
||||
fmtime1.tm_wday = diff+(diff >= 3 ? -3 : 4);
|
||||
|
||||
}
|
||||
fmtime2.tm_year = 0;
|
||||
if(!HttpGet(server->server, output, src, &fsz, control, offset,
|
||||
(mtime1) ? &fmtime1 : NULL, (mtime2) ? &fmtime2 : NULL)) {
|
||||
if(strstr(FtpLastResponse(control), "304")) {
|
||||
vprint(_("mtimes are identical, skipping %s\n"), fn);
|
||||
filedone = -1;
|
||||
complete = list_add(complete, fn);
|
||||
} else {
|
||||
ERR(NL, _("\nfailed downloading %s from %s: %s\n"), src, server->server, FtpLastResponse(control));
|
||||
/* we leave the partially downloaded file in place so it can be resumed later */
|
||||
}
|
||||
} else {
|
||||
if(mtime2) {
|
||||
if(fmtime2.tm_year) {
|
||||
/* date conversion from "rfc1123-date" to YYYYMMDDHHMMSS */
|
||||
sprintf(mtime2, "%4d%02d%02d%02d%02d%02d",
|
||||
fmtime2.tm_year+1900, fmtime2.tm_mon+1, fmtime2.tm_mday,
|
||||
fmtime2.tm_hour, fmtime2.tm_min, fmtime2.tm_sec);
|
||||
} else {
|
||||
WARN(NL, _("failed to get mtime for %s\n"), fn);
|
||||
}
|
||||
}
|
||||
filedone = 1;
|
||||
}
|
||||
} else if(!strcmp(server->protocol, "file")) {
|
||||
char src[PATH_MAX];
|
||||
snprintf(src, PATH_MAX, "%s%s", server->path, fn);
|
||||
vprint(_("copying %s to %s/%s\n"), src, localpath, fn);
|
||||
/* local repository, just copy the file */
|
||||
if(copyfile(src, output)) {
|
||||
ERR(NL, _("failed copying %s\n"), src);
|
||||
} else {
|
||||
filedone = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(filedone > 0) {
|
||||
char completefile[PATH_MAX];
|
||||
if(!strcmp(server->protocol, "file")) {
|
||||
char out[56];
|
||||
printf(" %s [", sync_fnm);
|
||||
STRNCPY(out, server->path, 33);
|
||||
printf("%s", out);
|
||||
for(j = strlen(out); j < maxcols-64; j++) {
|
||||
printf(" ");
|
||||
}
|
||||
fputs(_("] 100% LOCAL "), stdout);
|
||||
} else {
|
||||
log_progress(control, fsz-offset, &fsz);
|
||||
}
|
||||
complete = list_add(complete, fn);
|
||||
/* rename "output.part" file to "output" file */
|
||||
snprintf(completefile, PATH_MAX, "%s/%s", localpath, fn);
|
||||
rename(output, completefile);
|
||||
} else if(filedone < 0) {
|
||||
return(-1);
|
||||
}
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
if(!config->xfercommand) {
|
||||
if(!strcmp(server->protocol, "ftp") && !config->proxyhost) {
|
||||
FtpQuit(control);
|
||||
} else if(!strcmp(server->protocol, "http") || (config->proxyhost && strcmp(server->protocol, "file"))) {
|
||||
HttpQuit(control);
|
||||
}
|
||||
}
|
||||
|
||||
if(list_count(complete) == list_count(files)) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return(!done);
|
||||
}
|
||||
|
||||
char *fetch_pkgurl(char *target)
|
||||
{
|
||||
char spath[PATH_MAX];
|
||||
char url[PATH_MAX];
|
||||
char *host, *path, *fn;
|
||||
struct stat buf;
|
||||
|
||||
strncpy(url, target, PATH_MAX);
|
||||
host = strstr(url, "://");
|
||||
*host = '\0';
|
||||
host += 3;
|
||||
path = strchr(host, '/');
|
||||
*path = '\0';
|
||||
path++;
|
||||
fn = strrchr(path, '/');
|
||||
if(fn) {
|
||||
*fn = '\0';
|
||||
if(path[0] == '/') {
|
||||
snprintf(spath, PATH_MAX, "%s/", path);
|
||||
} else {
|
||||
snprintf(spath, PATH_MAX, "/%s/", path);
|
||||
}
|
||||
fn++;
|
||||
} else {
|
||||
fn = path;
|
||||
strcpy(spath, "/");
|
||||
}
|
||||
|
||||
/* do not download the file if it exists in the current dir
|
||||
*/
|
||||
if(stat(fn, &buf) == 0) {
|
||||
vprint(_(" %s is already in the current directory\n"), fn);
|
||||
} else {
|
||||
server_t *server;
|
||||
list_t *servers = NULL;
|
||||
list_t *files;
|
||||
|
||||
MALLOC(server, sizeof(server_t));
|
||||
server->protocol = url;
|
||||
server->server = host;
|
||||
server->path = spath;
|
||||
servers = list_add(servers, server);
|
||||
|
||||
files = list_add(NULL, fn);
|
||||
if(downloadfiles(servers, ".", files)) {
|
||||
ERR(NL, _("failed to download %s\n"), target);
|
||||
return(NULL);
|
||||
}
|
||||
FREELISTPTR(files);
|
||||
|
||||
FREELIST(servers);
|
||||
}
|
||||
|
||||
/* return the target with the raw filename, no URL */
|
||||
return(strndup(fn, PATH_MAX));
|
||||
}
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -21,20 +21,16 @@
|
||||
#ifndef _PM_DOWNLOAD_H
|
||||
#define _PM_DOWNLOAD_H
|
||||
|
||||
#include "list.h"
|
||||
extern char sync_fnm[25];
|
||||
extern int offset;
|
||||
extern struct timeval t0, t;
|
||||
extern float rate;
|
||||
extern int xfered1;
|
||||
extern unsigned char eta_h, eta_m, eta_s;
|
||||
|
||||
/* Servers */
|
||||
typedef struct __server_t {
|
||||
char *protocol;
|
||||
char *server;
|
||||
char *path;
|
||||
} server_t;
|
||||
|
||||
int downloadfiles(list_t *servers, const char *localpath, list_t *files);
|
||||
int downloadfiles_forreal(list_t *servers, const char *localpath,
|
||||
list_t *files, const char *mtime1, char *mtime2);
|
||||
|
||||
char *fetch_pkgurl(char *target);
|
||||
#ifdef __FTPLIB_H
|
||||
int log_progress(netbuf *ctl, int xfered, void *arg);
|
||||
#endif
|
||||
|
||||
#endif /* _PM_DOWNLOAD_H */
|
||||
|
||||
|
@ -24,14 +24,15 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <libintl.h>
|
||||
|
||||
#include <alpm.h>
|
||||
/* pacman */
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "list.h"
|
||||
#include "conf.h"
|
||||
#include "util.h"
|
||||
|
||||
#define LOG_STR_LEN 256
|
||||
|
||||
@ -43,7 +44,7 @@ int neednl; /* for cleaner message output */
|
||||
*/
|
||||
void cb_log(unsigned short level, char *msg)
|
||||
{
|
||||
char str[9] = "";
|
||||
char str[LOG_STR_LEN] = "";
|
||||
|
||||
if(!strlen(msg)) {
|
||||
return;
|
||||
@ -69,7 +70,7 @@ void cb_log(unsigned short level, char *msg)
|
||||
sprintf(str, _("function"));
|
||||
break;
|
||||
default:
|
||||
sprintf(str, _("???"));
|
||||
sprintf(str, "???");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -132,7 +133,7 @@ int yesno(char *fmt, ...)
|
||||
va_start(args, fmt);
|
||||
vsnprintf(str, LOG_STR_LEN, fmt, args);
|
||||
va_end(args);
|
||||
MSG(NL, str);
|
||||
pm_fprintf(stderr, NL, str);
|
||||
|
||||
if(fgets(response, 32, stdin)) {
|
||||
/* trim whitespace and newlines */
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
#define MSG(line, fmt, args...) pm_fprintf(stdout, line, fmt, ##args)
|
||||
#define ERR(line, fmt, args...) do { \
|
||||
pm_fprintf(stderr, line, "error: "); \
|
||||
pm_fprintf(stderr, line, _("error: ")); \
|
||||
pm_fprintf(stderr, CL, fmt, ##args); \
|
||||
} while(0)
|
||||
#define WARN(line, fmt, args...) do { \
|
||||
pm_fprintf(stderr, line, "warning: "); \
|
||||
pm_fprintf(stderr, line, _("warning: ")); \
|
||||
pm_fprintf(stderr, CL, fmt, ##args); \
|
||||
} while(0)
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
*/
|
||||
void dump_pkg_full(PM_PKG *pkg, int level)
|
||||
{
|
||||
char *date;
|
||||
char *date, *type;
|
||||
|
||||
if(pkg == NULL) {
|
||||
return;
|
||||
@ -49,20 +49,22 @@ void dump_pkg_full(PM_PKG *pkg, int level)
|
||||
PM_LIST_display(_("Groups :"), alpm_pkg_getinfo(pkg, PM_PKG_GROUPS));
|
||||
|
||||
printf(_("Packager : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_PACKAGER));
|
||||
printf(_("URL : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_URL));
|
||||
printf("URL : %s\n", (char *)alpm_pkg_getinfo(pkg, PM_PKG_URL));
|
||||
PM_LIST_display(_("License :"), alpm_pkg_getinfo(pkg, PM_PKG_LICENSE));
|
||||
printf(_("Architecture : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_ARCH));
|
||||
printf(_("Size : %ld\n"), (long int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE));
|
||||
|
||||
date = alpm_pkg_getinfo(pkg, PM_PKG_BUILDDATE);
|
||||
printf(_("Build Date : %s %s\n"), date, strlen(date) ? "UTC" : "");
|
||||
type = alpm_pkg_getinfo(pkg, PM_PKG_BUILDTYPE);
|
||||
printf(_("Build Type : %s\n"), strlen(type) ? type : _("Unknown"));
|
||||
date = alpm_pkg_getinfo(pkg, PM_PKG_INSTALLDATE);
|
||||
printf(_("Install Date : %s %s\n"), date, strlen(date) ? "UTC" : "");
|
||||
|
||||
printf(_("Install Script : %s\n"), alpm_pkg_getinfo(pkg, PM_PKG_SCRIPLET) ? "Yes" : "No");
|
||||
printf(_("Install Script : %s\n"), alpm_pkg_getinfo(pkg, PM_PKG_SCRIPLET) ? _("Yes") : _("No"));
|
||||
|
||||
printf(_("Reason: : "));
|
||||
switch((int)alpm_pkg_getinfo(pkg, PM_PKG_REASON)) {
|
||||
printf(_("Reason : "));
|
||||
switch((long)alpm_pkg_getinfo(pkg, PM_PKG_REASON)) {
|
||||
case PM_PKG_REASON_EXPLICIT:
|
||||
printf(_("Explicitly installed\n"));
|
||||
break;
|
||||
@ -76,6 +78,7 @@ void dump_pkg_full(PM_PKG *pkg, int level)
|
||||
|
||||
PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES));
|
||||
PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS));
|
||||
PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES));
|
||||
PM_LIST_display(_("Required By :"), alpm_pkg_getinfo(pkg, PM_PKG_REQUIREDBY));
|
||||
PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS));
|
||||
|
||||
@ -102,13 +105,18 @@ void dump_pkg_full(PM_PKG *pkg, int level)
|
||||
snprintf(path, PATH_MAX-1, "%s%s", root, str);
|
||||
if(!stat(path, &buf)) {
|
||||
char *md5sum = alpm_get_md5sum(path);
|
||||
if(md5sum == NULL) {
|
||||
ERR(NL, _("error calculating md5sum for %s\n"), path);
|
||||
char *sha1sum = alpm_get_sha1sum(path);
|
||||
if(md5sum == NULL && sha1sum == NULL) {
|
||||
ERR(NL, _("error calculating md5sum or sha1sum for %s\n"), path);
|
||||
FREE(str);
|
||||
continue;
|
||||
}
|
||||
printf(_("%sMODIFIED\t%s\n"), strcmp(md5sum, ptr) ? "" : "NOT ", path);
|
||||
if (!sha1sum)
|
||||
printf(_("%sMODIFIED\t%s\n"), strcmp(md5sum, ptr) ? "" : _("NOT "), path);
|
||||
if (!md5sum)
|
||||
printf(_("%sMODIFIED\t%s\n"), strcmp(sha1sum, ptr) ? "" : _("NOT "), path);
|
||||
FREE(md5sum);
|
||||
FREE(sha1sum);
|
||||
} else {
|
||||
printf(_("MISSING\t\t%s\n"), path);
|
||||
}
|
||||
@ -119,11 +127,11 @@ void dump_pkg_full(PM_PKG *pkg, int level)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/* Display the content of a sync package
|
||||
*/
|
||||
void dump_pkg_sync(PM_PKG *pkg, char *treename)
|
||||
{
|
||||
char *tmp1, *tmp2;
|
||||
if(pkg == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -135,13 +143,23 @@ void dump_pkg_sync(PM_PKG *pkg, char *treename)
|
||||
PM_LIST_display(_("Groups :"), alpm_pkg_getinfo(pkg, PM_PKG_GROUPS));
|
||||
PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES));
|
||||
PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS));
|
||||
PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES));
|
||||
PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS));
|
||||
PM_LIST_display(_("Replaces :"), alpm_pkg_getinfo(pkg, PM_PKG_REPLACES));
|
||||
|
||||
printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE));
|
||||
printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE));
|
||||
printf(_("Description : "));
|
||||
indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 20);
|
||||
printf(_("\nMD5 Sum : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM));
|
||||
tmp1 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM);
|
||||
if (tmp1 != NULL && tmp1[0] != '\0') {
|
||||
printf(_("\nMD5 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM));
|
||||
}
|
||||
tmp2 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM);
|
||||
if (tmp2 != NULL && tmp2[0] != '\0') {
|
||||
printf(_("\nSHA1 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_pkg_files(PM_PKG *pkg)
|
||||
@ -153,12 +171,37 @@ void dump_pkg_files(PM_PKG *pkg)
|
||||
pkgfiles = alpm_pkg_getinfo(pkg, PM_PKG_FILES);
|
||||
|
||||
for(i = pkgfiles; i; i = alpm_list_next(i)) {
|
||||
fprintf(stdout, _("%s %s\n"), (char *)pkgname, (char *)alpm_list_getdata(i));
|
||||
fprintf(stdout, "%s %s\n", (char *)pkgname, (char *)alpm_list_getdata(i));
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Display the changelog of an installed package
|
||||
*/
|
||||
void dump_pkg_changelog(char *clfile, char *pkgname)
|
||||
{
|
||||
FILE* fp = NULL;
|
||||
char line[PATH_MAX+1];
|
||||
|
||||
if((fp = fopen(clfile, "r")) == NULL)
|
||||
{
|
||||
ERR(NL, _("No changelog available for '%s'.\n"), pkgname);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(!feof(fp))
|
||||
{
|
||||
fgets(line, PATH_MAX, fp);
|
||||
printf("%s", line);
|
||||
line[0] = '\0';
|
||||
}
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int split_pkgname(char *target, char *name, char *version)
|
||||
{
|
||||
char tmp[512];
|
||||
@ -179,6 +222,10 @@ int split_pkgname(char *target, char *name, char *version)
|
||||
if((p = strstr(tmp, PM_EXT_PKG))) {
|
||||
*p = 0;
|
||||
}
|
||||
/* trim architecture */
|
||||
if((p = strrchr(tmp, '-'))) {
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
p = tmp + strlen(tmp);
|
||||
|
||||
|
@ -25,6 +25,7 @@ void dump_pkg_full(PM_PKG *pkg, int level);
|
||||
void dump_pkg_sync(PM_PKG *pkg, char *treename);
|
||||
|
||||
void dump_pkg_files(PM_PKG *pkg);
|
||||
void dump_pkg_changelog(char *clfile, char *pkgname);
|
||||
|
||||
int split_pkgname(char *target, char *name, char *version);
|
||||
|
||||
|
@ -29,11 +29,18 @@
|
||||
#include <unistd.h>
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
#ifndef CYGWIN
|
||||
#include <mcheck.h> /* debug */
|
||||
#else
|
||||
#if defined(__APPLE__)
|
||||
#include <malloc/malloc.h>
|
||||
#elif defined(__OpenBSD__) || defined(__APPLE__)
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/types.h>
|
||||
#elif defined(CYGWIN)
|
||||
#include <libgen.h> /* basename */
|
||||
#else
|
||||
#include <mcheck.h> /* debug */
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <ftplib.h>
|
||||
|
||||
#include <alpm.h>
|
||||
/* pacman */
|
||||
@ -52,6 +59,10 @@
|
||||
|
||||
#define PACCONF "/etc/pacman.conf"
|
||||
|
||||
#if defined(__OpenBSD__) || defined(__APPLE__)
|
||||
#define BSD
|
||||
#endif
|
||||
|
||||
/* Operations */
|
||||
enum {
|
||||
PM_OP_MAIN = 1,
|
||||
@ -71,23 +82,10 @@ list_t *pmc_syncs = NULL;
|
||||
/* list of targets specified on command line */
|
||||
list_t *pm_targets = NULL;
|
||||
|
||||
int maxcols = 80;
|
||||
unsigned int maxcols = 80;
|
||||
|
||||
extern int neednl;
|
||||
|
||||
/* Version
|
||||
*/
|
||||
static void version()
|
||||
{
|
||||
printf(_("\n"));
|
||||
printf(_(" .--. Pacman v%s - libalpm v%s\n"), PACKAGE_VERSION, PM_VERSION);
|
||||
printf(_("/ _.-' .-. .-. .-. Copyright (C) 2002-2006 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"));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Display usage/syntax for the specified operation.
|
||||
* op: the operation code requested
|
||||
* myname: basename(argv[0])
|
||||
@ -130,12 +128,13 @@ static void usage(int op, char *myname)
|
||||
} else if(op == PM_OP_QUERY) {
|
||||
printf(_("usage: %s {-Q --query} [options] [package]\n"), myname);
|
||||
printf(_("options:\n"));
|
||||
printf(_(" -e, --orphans list all packages that were explicitly installed\n"));
|
||||
printf(_(" -c, --changelog view the changelog of a package\n"));
|
||||
printf(_(" -e, --orphans list all packages that were installed as a dependency\n"));
|
||||
printf(_(" and are not required by any other packages\n"));
|
||||
printf(_(" -g, --groups view all members of a package group\n"));
|
||||
printf(_(" -i, --info view package information\n"));
|
||||
printf(_(" -l, --list list the contents of the queried package\n"));
|
||||
printf(_(" -m, --foreign list all packages that were not found in the sync repos\n"));
|
||||
printf(_(" -m, --foreign list all packages that were not found in the sync db(s)\n"));
|
||||
printf(_(" -o, --owns <file> query the package that owns <file>\n"));
|
||||
printf(_(" -p, --file pacman will query the package file [package] instead of\n"));
|
||||
printf(_(" looking in the database\n"));
|
||||
@ -145,6 +144,7 @@ static void usage(int op, char *myname)
|
||||
printf(_("options:\n"));
|
||||
printf(_(" -c, --clean remove old packages from cache directory (use -cc for all)\n"));
|
||||
printf(_(" -d, --nodeps skip dependency checks\n"));
|
||||
printf(_(" -e, --dependsonly install dependencies only\n"));
|
||||
printf(_(" -f, --force force install, overwrite conflicting files\n"));
|
||||
printf(_(" -g, --groups view all members of a package group\n"));
|
||||
printf(_(" -p, --print-uris print out URIs for given packages and their dependencies\n"));
|
||||
@ -156,6 +156,7 @@ static void usage(int op, char *myname)
|
||||
}
|
||||
printf(_(" --config <path> set an alternate configuration file\n"));
|
||||
printf(_(" --noconfirm do not ask for anything confirmation\n"));
|
||||
printf(_(" --ask <number> pre-specify answers for questions (see manpage)\n"));
|
||||
printf(_(" --noprogressbar do not show a progress bar when downloading files\n"));
|
||||
printf(_(" --noscriptlet do not execute the install scriptlet if there is any\n"));
|
||||
printf(_(" -v, --verbose be verbose\n"));
|
||||
@ -164,6 +165,67 @@ static void usage(int op, char *myname)
|
||||
}
|
||||
}
|
||||
|
||||
/* Version
|
||||
*/
|
||||
static void version()
|
||||
{
|
||||
printf("\n");
|
||||
printf(" .--. Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, PM_VERSION);
|
||||
printf("/ _.-' .-. .-. .-. Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>\n");
|
||||
printf("\\ '-. '-' '-' '-' & Frugalware developers <frugalware-devel@frugalware.org>\n");
|
||||
printf(" '--' \n");
|
||||
printf(_(" This program may be freely redistributed under\n"));
|
||||
printf(_(" the terms of the GNU General Public License\n"));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void cleanup(int signum)
|
||||
{
|
||||
list_t *lp;
|
||||
|
||||
if(signum==SIGSEGV)
|
||||
{
|
||||
fprintf(stderr, "Internal pacman error: Segmentation fault\n"
|
||||
"Please submit a full bug report, with the given package if appropriate.\n"
|
||||
"See <URL:http://wiki.frugalware.org/Bugs> for instructions.\n");
|
||||
exit(signum);
|
||||
} else if((signum == SIGINT) && (alpm_trans_release() == -1) && (pm_errno ==
|
||||
PM_ERR_TRANS_COMMITING)) {
|
||||
return;
|
||||
}
|
||||
if(signum != 0 && config->op_d_vertest == 0) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
/* free alpm library resources */
|
||||
if(alpm_release() == -1) {
|
||||
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
for(lp = pmc_syncs; lp; lp = lp->next) {
|
||||
sync_t *sync = lp->data;
|
||||
FREE(sync->treename);
|
||||
}
|
||||
FREELIST(pmc_syncs);
|
||||
FREELIST(pm_targets);
|
||||
FREECONF(config);
|
||||
|
||||
#ifndef CYGWIN
|
||||
#ifndef BSD
|
||||
/* debug */
|
||||
muntrace();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(neednl) {
|
||||
putchar('\n');
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
/* Parse command-line arguments for each operation
|
||||
* argc: argc
|
||||
* argv: argv
|
||||
@ -188,8 +250,10 @@ static int parseargs(int argc, char *argv[])
|
||||
{"vertest", no_argument, 0, 'Y'}, /* does the same as the 'vercmp' binary */
|
||||
{"dbpath", required_argument, 0, 'b'},
|
||||
{"cascade", no_argument, 0, 'c'},
|
||||
{"changelog", no_argument, 0, 'c'},
|
||||
{"clean", no_argument, 0, 'c'},
|
||||
{"nodeps", no_argument, 0, 'd'},
|
||||
{"dependsonly",no_argument, 0, 'e'},
|
||||
{"orphans", no_argument, 0, 'e'},
|
||||
{"force", no_argument, 0, 'f'},
|
||||
{"groups", no_argument, 0, 'g'},
|
||||
@ -215,6 +279,7 @@ static int parseargs(int argc, char *argv[])
|
||||
{"debug", required_argument, 0, 1003},
|
||||
{"noprogressbar", no_argument, 0, 1004},
|
||||
{"noscriptlet", no_argument, 0, 1005},
|
||||
{"ask", required_argument, 0, 1006},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
char root[PATH_MAX];
|
||||
@ -230,12 +295,17 @@ static int parseargs(int argc, char *argv[])
|
||||
if(config->configfile) {
|
||||
free(config->configfile);
|
||||
}
|
||||
#if defined(__OpenBSD__) || defined(__APPLE__)
|
||||
config->configfile = strdup(optarg);
|
||||
#else
|
||||
config->configfile = strndup(optarg, PATH_MAX);
|
||||
#endif
|
||||
break;
|
||||
case 1002: config->op_s_ignore = list_add(config->op_s_ignore, strdup(optarg)); break;
|
||||
case 1003: config->debug = atoi(optarg); break;
|
||||
case 1004: config->noprogressbar = 1; break;
|
||||
case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
|
||||
case 1006: config->noask = 1; config->ask = atoi(optarg); break;
|
||||
case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break;
|
||||
case 'D':
|
||||
config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST);
|
||||
@ -265,9 +335,10 @@ static int parseargs(int argc, char *argv[])
|
||||
case 'c':
|
||||
config->op_s_clean++;
|
||||
config->flags |= PM_TRANS_FLAG_CASCADE;
|
||||
config->op_q_changelog = 1;
|
||||
break;
|
||||
case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break;
|
||||
case 'e': config->op_q_orphans = 1; break;
|
||||
case 'e': config->op_q_orphans = 1; config->flags |= PM_TRANS_FLAG_DEPENDSONLY; break;
|
||||
case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
|
||||
case 'g': config->group++; break;
|
||||
case 'h': config->help = 1; break;
|
||||
@ -282,7 +353,7 @@ static int parseargs(int argc, char *argv[])
|
||||
case 'o': config->op_q_owns = 1; break;
|
||||
case 'p':
|
||||
config->op_q_isfile = 1;
|
||||
config->op_s_printuris = 1;
|
||||
config->flags |= PM_TRANS_FLAG_PRINTURIS;
|
||||
break;
|
||||
case 'r':
|
||||
if(realpath(optarg, root) == NULL) {
|
||||
@ -303,6 +374,7 @@ static int parseargs(int argc, char *argv[])
|
||||
case 'v': config->verbose++; break;
|
||||
case 'w':
|
||||
config->op_s_downloadonly = 1;
|
||||
config->flags |= PM_TRANS_FLAG_DOWNLOADONLY;
|
||||
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
|
||||
break;
|
||||
case 'y': config->op_s_sync++; break;
|
||||
@ -334,52 +406,6 @@ static int parseargs(int argc, char *argv[])
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void cleanup(int signum)
|
||||
{
|
||||
list_t *lp;
|
||||
|
||||
if((signum == SIGINT) && (alpm_trans_release() == -1)) {
|
||||
return;
|
||||
}
|
||||
if(signum != 0 && config->op_d_vertest == 0) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
/* free alpm library resources */
|
||||
if(alpm_release() == -1) {
|
||||
ERR(NL, _("%s\n"), alpm_strerror(pm_errno));
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
for(lp = pmc_syncs; lp; lp = lp->next) {
|
||||
sync_t *sync = lp->data;
|
||||
list_t *i;
|
||||
for(i = sync->servers; i; i = i->next) {
|
||||
server_t *server = i->data;
|
||||
FREE(server->protocol);
|
||||
FREE(server->server);
|
||||
FREE(server->path);
|
||||
}
|
||||
FREELIST(sync->servers);
|
||||
FREE(sync->treename);
|
||||
}
|
||||
FREELIST(pmc_syncs);
|
||||
FREELIST(pm_targets);
|
||||
FREECONF(config);
|
||||
|
||||
#ifndef CYGWIN
|
||||
/* debug */
|
||||
muntrace();
|
||||
#endif
|
||||
|
||||
if(neednl) {
|
||||
putchar('\n');
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
@ -390,8 +416,10 @@ int main(int argc, char *argv[])
|
||||
list_t *lp;
|
||||
|
||||
#ifndef CYGWIN
|
||||
#ifndef BSD
|
||||
/* debug */
|
||||
mtrace();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
cenv = getenv("COLUMNS");
|
||||
@ -402,6 +430,7 @@ int main(int argc, char *argv[])
|
||||
/* set signal handlers */
|
||||
signal(SIGINT, cleanup);
|
||||
signal(SIGTERM, cleanup);
|
||||
signal(SIGSEGV, cleanup);
|
||||
|
||||
/* i18n init */
|
||||
lang=getenv("LC_ALL");
|
||||
@ -411,6 +440,9 @@ int main(int argc, char *argv[])
|
||||
lang=getenv("LANG");
|
||||
|
||||
setlocale(LC_ALL, lang);
|
||||
// workaround for tr_TR
|
||||
if(lang && !strcmp(lang, "tr_TR"))
|
||||
setlocale(LC_CTYPE, "C");
|
||||
bindtextdomain("pacman", "/usr/share/locale");
|
||||
textdomain("pacman");
|
||||
|
||||
@ -444,9 +476,12 @@ int main(int argc, char *argv[])
|
||||
if(myuid > 0) {
|
||||
if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) {
|
||||
if((config->op == PM_OP_SYNC && !config->op_s_sync &&
|
||||
(config->op_s_search || config->op_s_printuris || config->group || config->op_q_list ||
|
||||
config->op_q_info)) || (config->op == PM_OP_DEPTEST && !config->op_d_resolve)) {
|
||||
/* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */
|
||||
(config->op_s_search || config->group || config->op_q_list || config->op_q_info))
|
||||
|| (config->op == PM_OP_DEPTEST && !config->op_d_resolve)
|
||||
|| (config->root != NULL)) {
|
||||
/* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */
|
||||
/* special case: ignore root user check if -r is specified, fall back on
|
||||
* normal FS checking */
|
||||
} else {
|
||||
ERR(NL, _("you cannot perform this operation unless you are root.\n"));
|
||||
config_free(config);
|
||||
@ -476,14 +511,7 @@ int main(int argc, char *argv[])
|
||||
cleanup(1);
|
||||
}
|
||||
|
||||
if(config->configfile == NULL) {
|
||||
config->configfile = strdup(PACCONF);
|
||||
}
|
||||
if(parseconfig(config->configfile, config) == -1) {
|
||||
cleanup(1);
|
||||
}
|
||||
|
||||
/* set library parameters */
|
||||
/* Setup logging as soon as possible, to print out maximum debugging info */
|
||||
if(alpm_set_option(PM_OPT_LOGMASK, (long)config->debug) == -1) {
|
||||
ERR(NL, _("failed to set option LOGMASK (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
@ -492,20 +520,61 @@ int main(int argc, char *argv[])
|
||||
ERR(NL, _("failed to set option LOGCB (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(config->dbpath == NULL) {
|
||||
config->dbpath = strdup(PM_DBPATH);
|
||||
} else {
|
||||
/* dbpath has been set by parseargs or parseconfig */
|
||||
if(alpm_set_option(PM_OPT_DBPATH, (long)config->dbpath) == -1) {
|
||||
ERR(NL, _("failed to set option DBPATH (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
|
||||
if(config->configfile == NULL) {
|
||||
config->configfile = strdup(PACCONF);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_CACHEDIR, (long)config->cachedir) == -1) {
|
||||
ERR(NL, _("failed to set option CACHEDIR (%s)\n"), alpm_strerror(pm_errno));
|
||||
if(alpm_parse_config(config->configfile, cb_db_register, "") != 0) {
|
||||
ERR(NL, _("failed to parse config (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
|
||||
/* set library parameters */
|
||||
if(alpm_set_option(PM_OPT_DLCB, (long)log_progress) == -1) {
|
||||
ERR(NL, _("failed to set option DLCB (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLFNM, (long)sync_fnm) == -1) {
|
||||
ERR(NL, _("failed to set option DLFNM (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLOFFSET, (long)&offset) == -1) {
|
||||
ERR(NL, _("failed to set option DLOFFSET (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLT0, (long)&t0) == -1) {
|
||||
ERR(NL, _("failed to set option DLT0 (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLT, (long)&t) == -1) {
|
||||
ERR(NL, _("failed to set option DLT (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLRATE, (long)&rate) == -1) {
|
||||
ERR(NL, _("failed to set option DLRATE (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLXFERED1, (long)&xfered1) == -1) {
|
||||
ERR(NL, _("failed to set option DLXFERED1 (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLETA_H, (long)&eta_h) == -1) {
|
||||
ERR(NL, _("failed to set option DLETA_H (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLETA_M, (long)&eta_m) == -1) {
|
||||
ERR(NL, _("failed to set option DLETA_M (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
if(alpm_set_option(PM_OPT_DLETA_S, (long)&eta_s) == -1) {
|
||||
ERR(NL, _("failed to set option DLETA_S (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
}
|
||||
FREE(config->dbpath);
|
||||
alpm_get_option(PM_OPT_DBPATH, (long *)&config->dbpath);
|
||||
FREE(config->cachedir);
|
||||
alpm_get_option(PM_OPT_CACHEDIR, (long *)&config->cachedir);
|
||||
|
||||
for(lp = config->op_s_ignore; lp; lp = lp->next) {
|
||||
if(alpm_set_option(PM_OPT_IGNOREPKG, (long)lp->data) == -1) {
|
||||
ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno));
|
||||
@ -514,13 +583,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if(config->verbose > 0) {
|
||||
printf(_("Root : %s\n"), config->root);
|
||||
printf(_("DBPath: %s\n"), config->dbpath);
|
||||
printf("Root : %s\n", config->root);
|
||||
printf("DBPath: %s\n", config->dbpath);
|
||||
list_display(_("Targets:"), pm_targets);
|
||||
}
|
||||
|
||||
/* Opening local database */
|
||||
db_local = alpm_db_register("local");
|
||||
db_local = alpm_db_register("local", NULL);
|
||||
if(db_local == NULL) {
|
||||
ERR(NL, _("could not register 'local' database (%s)\n"), alpm_strerror(pm_errno));
|
||||
cleanup(1);
|
||||
|
@ -3,4 +3,6 @@
|
||||
# This file is in the public domain.
|
||||
#
|
||||
# Set of available languages.
|
||||
|
||||
de
|
||||
fr
|
||||
hu
|
||||
|
@ -23,13 +23,13 @@ VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
localedir = $(datadir)/locale
|
||||
gettextsrcdir = $(datadir)/gettext/po
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
MKINSTALLDIRS = @MKINSTALLDIRS@
|
||||
mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
|
||||
mkinstalldirs = @INSTALL@ -d
|
||||
|
||||
GMSGFMT = @GMSGFMT@
|
||||
MSGFMT = @MSGFMT@
|
||||
|
@ -4,6 +4,7 @@ deptest.c
|
||||
download.c
|
||||
list.c
|
||||
log.c
|
||||
log.h
|
||||
package.c
|
||||
pacman.c
|
||||
query.c
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,6 @@
|
||||
/* pacman */
|
||||
#include "list.h"
|
||||
#include "package.h"
|
||||
#include "db.h"
|
||||
#include "query.h"
|
||||
#include "log.h"
|
||||
#include "conf.h"
|
||||
@ -95,14 +94,28 @@ int pacman_query(list_t *targets)
|
||||
PM_PKG *info = NULL;
|
||||
list_t *targ;
|
||||
list_t *i;
|
||||
PM_LIST *j;
|
||||
PM_LIST *j, *ret;
|
||||
char *package = NULL;
|
||||
int done = 0;
|
||||
|
||||
if(config->op_q_search) {
|
||||
if(db_search(db_local, "local", targets)) {
|
||||
for(i = targets; i; i = i->next) {
|
||||
alpm_set_option(PM_OPT_NEEDLES, (long)i->data);
|
||||
}
|
||||
ret = alpm_db_search(db_local);
|
||||
if(ret == NULL) {
|
||||
return(1);
|
||||
}
|
||||
for(j = ret; j; j = alpm_list_next(j)) {
|
||||
PM_PKG *pkg = alpm_list_getdata(j);
|
||||
|
||||
printf("local/%s/%s %s\n ",
|
||||
(char*)alpm_list_getdata(alpm_pkg_getinfo(pkg, PM_PKG_GROUPS)),
|
||||
(char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
|
||||
indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
|
||||
printf("\n");
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
@ -111,16 +124,6 @@ int pacman_query(list_t *targets)
|
||||
ERR(NL, _("no usable package repositories configured.\n"));
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* open the database(s) */
|
||||
for(i = pmc_syncs; i; i = i->next) {
|
||||
sync_t *sync = i->data;
|
||||
sync->db = alpm_db_register(sync->treename);
|
||||
if(sync->db == NULL) {
|
||||
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(targ = targets; !done; targ = (targ ? targ->next : NULL)) {
|
||||
@ -221,10 +224,8 @@ int pacman_query(list_t *targets)
|
||||
char *haystack;
|
||||
char *needle;
|
||||
haystack = strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME));
|
||||
strtoupper(haystack);
|
||||
needle = strdup(alpm_pkg_getinfo(info, PM_PKG_NAME));
|
||||
strtoupper(needle);
|
||||
if(strstr(haystack, needle)) {
|
||||
if(!strcmp(haystack, needle)) {
|
||||
match = 1;
|
||||
}
|
||||
FREE(haystack);
|
||||
@ -240,7 +241,7 @@ int pacman_query(list_t *targets)
|
||||
}
|
||||
if(config->op_q_orphans) {
|
||||
if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL
|
||||
&& (int)alpm_pkg_getinfo(info, PM_PKG_REASON) == PM_PKG_REASON_EXPLICIT) {
|
||||
&& (long)alpm_pkg_getinfo(info, PM_PKG_REASON) == PM_PKG_REASON_DEPEND) {
|
||||
MSG(NL, "%s %s\n", pkgname, pkgver);
|
||||
}
|
||||
}
|
||||
@ -249,7 +250,7 @@ int pacman_query(list_t *targets)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char *pkgname, *pkgver;
|
||||
char *pkgname, *pkgver, changelog[PATH_MAX];
|
||||
|
||||
info = alpm_db_readpkg(db_local, package);
|
||||
if(info == NULL) {
|
||||
@ -258,7 +259,17 @@ int pacman_query(list_t *targets)
|
||||
}
|
||||
|
||||
/* find a target */
|
||||
if(config->op_q_info || config->op_q_list) {
|
||||
if(config->op_q_changelog || config->op_q_info || config->op_q_list) {
|
||||
if(config->op_q_changelog) {
|
||||
char *dbpath;
|
||||
alpm_get_option(PM_OPT_DBPATH, (long *)&dbpath);
|
||||
snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog",
|
||||
config->root, dbpath,
|
||||
(char*)alpm_db_getinfo(db_local, PM_DB_TREENAME),
|
||||
(char*)alpm_pkg_getinfo(info, PM_PKG_NAME),
|
||||
(char*)alpm_pkg_getinfo(info, PM_PKG_VERSION));
|
||||
dump_pkg_changelog(changelog, (char*)alpm_pkg_getinfo(info, PM_PKG_NAME));
|
||||
}
|
||||
if(config->op_q_info) {
|
||||
dump_pkg_full(info, config->op_q_info);
|
||||
}
|
||||
|
@ -77,24 +77,17 @@ int pacman_remove(list_t *targets)
|
||||
|
||||
/* Step 1: create a new transaction
|
||||
*/
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
|
||||
ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
||||
MSG(NL, _(" if you're sure a package manager is not already running,\n"
|
||||
" you can remove %s\n"), PM_LOCK);
|
||||
" you can remove %s%s\n"), config->root, PM_LOCK);
|
||||
}
|
||||
FREELIST(finaltargs);
|
||||
return(1);
|
||||
}
|
||||
/* and add targets to it */
|
||||
for(i = finaltargs; i; i = i->next) {
|
||||
/* check if the package is in the HoldPkg list. If so, ask
|
||||
* confirmation first */
|
||||
if(list_is_strin(i->data, config->holdpkg)) {
|
||||
if(!yesno(_(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "), i->data)) {
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
if(alpm_trans_addtarget(i->data) == -1) {
|
||||
ERR(NL, _("failed to add target '%s' (%s)\n"), (char *)i->data, alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
@ -155,7 +148,6 @@ int pacman_remove(list_t *targets)
|
||||
*/
|
||||
cleanup:
|
||||
FREELIST(finaltargs);
|
||||
|
||||
if(alpm_trans_release() == -1) {
|
||||
ERR(NL, _("failed to release transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
|
@ -19,6 +19,11 @@
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#if defined(__APPLE__) || defined(__OpenBSD__)
|
||||
#include <sys/syslimits.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -38,7 +43,6 @@
|
||||
#include "download.h"
|
||||
#include "list.h"
|
||||
#include "package.h"
|
||||
#include "db.h"
|
||||
#include "trans.h"
|
||||
#include "sync.h"
|
||||
#include "conf.h"
|
||||
@ -65,6 +69,8 @@ static int sync_cleancache(int level)
|
||||
list_t *clean = NULL;
|
||||
list_t *i, *j;
|
||||
|
||||
if(!yesno(_("Do you want to remove old packages from cache? [Y/n] ")))
|
||||
return(0);
|
||||
MSG(NL, _("removing old packages from cache... "));
|
||||
dir = opendir(dirpath);
|
||||
if(dir == NULL) {
|
||||
@ -128,6 +134,8 @@ static int sync_cleancache(int level)
|
||||
FREELIST(clean);
|
||||
} else {
|
||||
/* full cleanup */
|
||||
if(!yesno(_("Do you want to remove all packages from cache? [Y/n] ")))
|
||||
return(0);
|
||||
MSG(NL, _("removing all packages from cache... "));
|
||||
|
||||
if(rmrf(dirpath)) {
|
||||
@ -147,52 +155,22 @@ static int sync_cleancache(int level)
|
||||
|
||||
static int sync_synctree(int level, list_t *syncs)
|
||||
{
|
||||
char *root, *dbpath;
|
||||
char path[PATH_MAX];
|
||||
list_t *i;
|
||||
int success = 0, ret;
|
||||
|
||||
alpm_get_option(PM_OPT_ROOT, (long *)&root);
|
||||
alpm_get_option(PM_OPT_DBPATH, (long *)&dbpath);
|
||||
|
||||
for(i = syncs; i; i = i->next) {
|
||||
list_t *files = NULL;
|
||||
char newmtime[16] = "";
|
||||
char lastupdate[16] = "";
|
||||
sync_t *sync = (sync_t *)i->data;
|
||||
|
||||
if(level < 2) {
|
||||
/* get the lastupdate time */
|
||||
db_getlastupdate(sync->db, lastupdate);
|
||||
if(strlen(lastupdate) == 0) {
|
||||
vprint(_("failed to get lastupdate time for %s (no big deal)\n"), sync->treename);
|
||||
}
|
||||
}
|
||||
|
||||
/* build a one-element list */
|
||||
snprintf(path, PATH_MAX, "%s" PM_EXT_DB, sync->treename);
|
||||
files = list_add(files, strdup(path));
|
||||
|
||||
snprintf(path, PATH_MAX, "%s%s", root, dbpath);
|
||||
|
||||
ret = downloadfiles_forreal(sync->servers, path, files, lastupdate, newmtime);
|
||||
FREELIST(files);
|
||||
ret = alpm_db_update(level, sync->db);
|
||||
if(ret > 0) {
|
||||
ERR(NL, _("failed to synchronize %s\n"), sync->treename);
|
||||
if(pm_errno == PM_ERR_DB_SYNC) {
|
||||
ERR(NL, _("failed to synchronize %s\n"), sync->treename);
|
||||
} else {
|
||||
ERR(NL, _("failed to update %s (%s)\n"), sync->treename, alpm_strerror(pm_errno));
|
||||
}
|
||||
success--;
|
||||
} else if(ret < 0) {
|
||||
MSG(NL, _(" %s is up to date\n"), sync->treename);
|
||||
} else {
|
||||
if(strlen(newmtime)) {
|
||||
vprint(_("sync: new mtime for %s: %s\n"), sync->treename, newmtime);
|
||||
db_setlastupdate(sync->db, newmtime);
|
||||
}
|
||||
snprintf(path, PATH_MAX, "%s%s/%s" PM_EXT_DB, root, dbpath, sync->treename);
|
||||
if(alpm_db_update(sync->db, path) == -1) {
|
||||
ERR(NL, _("failed to update %s (%s)\n"), sync->treename, alpm_strerror(pm_errno));
|
||||
}
|
||||
/* remove the .tar.gz */
|
||||
unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,12 +180,29 @@ static int sync_synctree(int level, list_t *syncs)
|
||||
static int sync_search(list_t *syncs, list_t *targets)
|
||||
{
|
||||
list_t *i;
|
||||
PM_LIST *ret;
|
||||
|
||||
for(i = targets; i; i = i->next) {
|
||||
alpm_set_option(PM_OPT_NEEDLES, (long)i->data);
|
||||
}
|
||||
for(i = syncs; i; i = i->next) {
|
||||
sync_t *sync = i->data;
|
||||
if(targets) {
|
||||
if(db_search(sync->db, sync->treename, targets)) {
|
||||
return(1);
|
||||
PM_LIST *lp;
|
||||
ret = alpm_db_search(sync->db);
|
||||
if(ret == NULL) {
|
||||
continue;
|
||||
}
|
||||
for(lp = ret; lp; lp = alpm_list_next(lp)) {
|
||||
PM_PKG *pkg = alpm_list_getdata(lp);
|
||||
|
||||
char *group = (char *)alpm_list_getdata(alpm_pkg_getinfo(pkg,PM_PKG_GROUPS));
|
||||
printf("%s/%s%s%s %s\n ", (char *)alpm_db_getinfo(sync->db, PM_DB_TREENAME),
|
||||
(char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
|
||||
(group ? " (" : ""), (group ? group : ""), (group ? ") " : ""),
|
||||
indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
|
||||
printf("\n");
|
||||
}
|
||||
} else {
|
||||
PM_LIST *lp;
|
||||
@ -215,7 +210,7 @@ static int sync_search(list_t *syncs, list_t *targets)
|
||||
for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) {
|
||||
PM_PKG *pkg = alpm_list_getdata(lp);
|
||||
|
||||
MSG(NL, _("%s/%s %s\n "), sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
|
||||
MSG(NL, "%s/%s %s\n ", sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
|
||||
indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4);
|
||||
MSG(NL, "\n");
|
||||
}
|
||||
@ -228,7 +223,7 @@ static int sync_search(list_t *syncs, list_t *targets)
|
||||
static int sync_group(int level, list_t *syncs, list_t *targets)
|
||||
{
|
||||
list_t *i, *j;
|
||||
|
||||
|
||||
if(targets) {
|
||||
for(i = targets; i; i = i->next) {
|
||||
for(j = syncs; j; j = j->next) {
|
||||
@ -236,7 +231,7 @@ static int sync_group(int level, list_t *syncs, list_t *targets)
|
||||
PM_GRP *grp = alpm_db_readgrp(sync->db, i->data);
|
||||
|
||||
if(grp) {
|
||||
MSG(NL, "%s/%s\n", sync->treename, (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
|
||||
MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
|
||||
PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES));
|
||||
}
|
||||
}
|
||||
@ -249,8 +244,8 @@ static int sync_group(int level, list_t *syncs, list_t *targets)
|
||||
for(lp = alpm_db_getgrpcache(sync->db); lp; lp = alpm_list_next(lp)) {
|
||||
PM_GRP *grp = alpm_list_getdata(lp);
|
||||
|
||||
MSG(NL, "%s/%s\n", sync->treename, (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
|
||||
if(level > 1) {
|
||||
MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME));
|
||||
if(grp && level > 1) {
|
||||
PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES));
|
||||
}
|
||||
}
|
||||
@ -356,10 +351,6 @@ int pacman_sync(list_t *targets)
|
||||
int retval = 0;
|
||||
list_t *i;
|
||||
PM_LIST *packages, *data, *lp;
|
||||
char *root, *cachedir;
|
||||
char ldir[PATH_MAX];
|
||||
int varcache = 1;
|
||||
list_t *files = NULL;
|
||||
|
||||
if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
|
||||
ERR(NL, _("no usable package repositories configured.\n"));
|
||||
@ -370,16 +361,6 @@ int pacman_sync(list_t *targets)
|
||||
return(sync_cleancache(config->op_s_clean));
|
||||
}
|
||||
|
||||
/* open the database(s) */
|
||||
for(i = pmc_syncs; i; i = i->next) {
|
||||
sync_t *sync = i->data;
|
||||
sync->db = alpm_db_register(sync->treename);
|
||||
if(sync->db == NULL) {
|
||||
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(config->op_s_sync) {
|
||||
/* grab a fresh package list */
|
||||
MSG(NL, _(":: Synchronizing package databases...\n"));
|
||||
@ -407,11 +388,11 @@ int pacman_sync(list_t *targets)
|
||||
|
||||
/* Step 1: create a new transaction...
|
||||
*/
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
|
||||
ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
||||
MSG(NL, _(" if you're sure a package manager is not already running,\n"
|
||||
" you can remove %s\n"), PM_LOCK);
|
||||
" you can remove %s%s\n"), config->root, PM_LOCK);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
@ -439,18 +420,18 @@ int pacman_sync(list_t *targets)
|
||||
MSG(NL, _("\n:: pacman has detected a newer version of the \"pacman\" package.\n"));
|
||||
MSG(NL, _(":: It is recommended that you allow pacman to upgrade itself\n"));
|
||||
MSG(NL, _(":: first, then you can re-run the operation with the newer version.\n"));
|
||||
MSG(NL, _("::\n"));
|
||||
MSG(NL, "::\n");
|
||||
if(yesno(_(":: Upgrade pacman first? [Y/n] "))) {
|
||||
if(alpm_trans_release() == -1) {
|
||||
ERR(NL, _("failed to release transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
|
||||
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
|
||||
ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
||||
MSG(NL, _(" if you're sure a package manager is not already running,\n"
|
||||
" you can remove %s\n"), PM_LOCK);
|
||||
" you can remove %s%s\n"), config->root, PM_LOCK);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
@ -470,6 +451,7 @@ int pacman_sync(list_t *targets)
|
||||
if(alpm_trans_addtarget(targ) == -1) {
|
||||
PM_GRP *grp = NULL;
|
||||
list_t *j;
|
||||
int found=0;
|
||||
if(pm_errno == PM_ERR_TRANS_DUP_TARGET) {
|
||||
/* just ignore duplicate targets */
|
||||
continue;
|
||||
@ -480,12 +462,13 @@ int pacman_sync(list_t *targets)
|
||||
goto cleanup;
|
||||
}
|
||||
/* target not found: check if it's a group */
|
||||
for(j = pmc_syncs; j && !grp; j = j->next) {
|
||||
for(j = pmc_syncs; j; j = j->next) {
|
||||
sync_t *sync = j->data;
|
||||
grp = alpm_db_readgrp(sync->db, targ);
|
||||
if(grp) {
|
||||
PM_LIST *pmpkgs;
|
||||
list_t *k, *pkgs;
|
||||
found++;
|
||||
MSG(NL, _(":: group %s:\n"), targ);
|
||||
pmpkgs = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES);
|
||||
/* remove dupe entries in case a package exists in multiple repos */
|
||||
@ -507,10 +490,25 @@ int pacman_sync(list_t *targets)
|
||||
FREELIST(pkgs);
|
||||
}
|
||||
}
|
||||
if(grp == NULL) {
|
||||
ERR(NL, "could not add target '%s': not found in sync db\n", targ);
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
if(!found) {
|
||||
/* targ not found in sync db, searching for providers... */
|
||||
PM_LIST *k = NULL;
|
||||
PM_PKG *pkg;
|
||||
char *pname;
|
||||
for(j = pmc_syncs; j && !k; j = j->next) {
|
||||
sync_t *sync = j->data;
|
||||
k = alpm_db_whatprovides(sync->db, targ);
|
||||
pkg = (PM_PKG*)alpm_list_getdata(alpm_list_first(k));
|
||||
pname = (char*)alpm_pkg_getinfo(pkg, PM_PKG_NAME);
|
||||
}
|
||||
if(pname != NULL) {
|
||||
/* targ is provided by pname */
|
||||
targets = list_add(targets, strdup(pname));
|
||||
} else {
|
||||
ERR(NL, _("could not add target '%s': not found in sync db\n"), targ);
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -519,15 +517,16 @@ int pacman_sync(list_t *targets)
|
||||
/* Step 2: "compute" the transaction based on targets and flags
|
||||
*/
|
||||
if(alpm_trans_prepare(&data) == -1) {
|
||||
long long *pkgsize, *freespace;
|
||||
ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno));
|
||||
switch(pm_errno) {
|
||||
case PM_ERR_UNSATISFIED_DEPS:
|
||||
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
||||
PM_DEPMISS *miss = alpm_list_getdata(lp);
|
||||
MSG(NL, _(":: %s: %s %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET),
|
||||
(int)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? _("requires") : _("is required by"),
|
||||
MSG(NL, ":: %s: %s %s", alpm_dep_getinfo(miss, PM_DEP_TARGET),
|
||||
(long)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? _("requires") : _("is required by"),
|
||||
alpm_dep_getinfo(miss, PM_DEP_NAME));
|
||||
switch((int)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
||||
switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
|
||||
case PM_DEP_MOD_EQ: MSG(CL, "=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
case PM_DEP_MOD_GE: MSG(CL, ">=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
case PM_DEP_MOD_LE: MSG(CL, "<=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
|
||||
@ -539,11 +538,21 @@ int pacman_sync(list_t *targets)
|
||||
case PM_ERR_CONFLICTING_DEPS:
|
||||
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
||||
PM_DEPMISS *miss = alpm_list_getdata(lp);
|
||||
MSG(NL, ":: %s: conflicts with %s", alpm_dep_getinfo(miss, PM_DEP_TARGET),
|
||||
alpm_dep_getinfo(miss, PM_DEP_NAME));
|
||||
|
||||
MSG(NL, _(":: %s: conflicts with %s"),
|
||||
alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME));
|
||||
}
|
||||
alpm_list_free(data);
|
||||
break;
|
||||
case PM_ERR_DISK_FULL:
|
||||
lp = alpm_list_first(data);
|
||||
pkgsize = alpm_list_getdata(lp);
|
||||
lp = alpm_list_next(lp);
|
||||
freespace = alpm_list_getdata(lp);
|
||||
MSG(NL, _(":: %.1f MB required, have %.1f MB"),
|
||||
(double)(*pkgsize / 1048576.0), (double)(*freespace / 1048576.0));
|
||||
alpm_list_free(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -558,19 +567,20 @@ int pacman_sync(list_t *targets)
|
||||
}
|
||||
|
||||
/* list targets and get confirmation */
|
||||
if(!config->op_s_printuris) {
|
||||
if(!((unsigned long)alpm_trans_getinfo(PM_TRANS_FLAGS) & PM_TRANS_FLAG_PRINTURIS)) {
|
||||
list_t *list_install = NULL;
|
||||
list_t *list_remove = NULL;
|
||||
char *str;
|
||||
unsigned long totalsize = 0;
|
||||
double mb;
|
||||
unsigned long totalusize = 0;
|
||||
double mb, umb;
|
||||
|
||||
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
||||
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
||||
PM_PKG *pkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
||||
char *pkgname, *pkgver;
|
||||
|
||||
if((int)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) {
|
||||
if((long)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) {
|
||||
PM_LIST *j, *data;
|
||||
data = alpm_sync_getinfo(sync, PM_SYNC_DATA);
|
||||
for(j = alpm_list_first(data); j; j = alpm_list_next(j)) {
|
||||
@ -584,7 +594,8 @@ 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);
|
||||
totalsize += (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE);
|
||||
totalusize += (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE);
|
||||
|
||||
asprintf(&str, "%s-%s", pkgname, pkgver);
|
||||
list_install = list_add(list_install, str);
|
||||
@ -598,14 +609,19 @@ int pacman_sync(list_t *targets)
|
||||
FREE(str);
|
||||
}
|
||||
mb = (double)(totalsize / 1048576.0);
|
||||
umb = (double)(totalusize / 1048576.0);
|
||||
/* round up to 0.1 */
|
||||
if(mb < 0.1) {
|
||||
mb = 0.1;
|
||||
}
|
||||
if(umb < 0.1) {
|
||||
umb = 0.1;
|
||||
}
|
||||
MSG(NL, _("\nTargets: "));
|
||||
str = buildstring(list_install);
|
||||
indentprint(str, 9);
|
||||
MSG(NL, _("\nTotal Package Size: %.1f MB\n"), mb);
|
||||
MSG(NL, _("\nTotal Uncompressed Package Size: %.1f MB\n"), umb);
|
||||
FREELIST(list_install);
|
||||
FREE(str);
|
||||
|
||||
@ -636,109 +652,6 @@ int pacman_sync(list_t *targets)
|
||||
}
|
||||
}
|
||||
|
||||
/* group sync records by repository and download */
|
||||
alpm_get_option(PM_OPT_ROOT, (long *)&root);
|
||||
alpm_get_option(PM_OPT_CACHEDIR, (long *)&cachedir);
|
||||
snprintf(ldir, PATH_MAX, "%s%s", root, cachedir);
|
||||
|
||||
for(i = pmc_syncs; i; i = i->next) {
|
||||
sync_t *current = i->data;
|
||||
|
||||
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
||||
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
||||
PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
||||
PM_DB *dbs = alpm_pkg_getinfo(spkg, PM_PKG_DATA);
|
||||
|
||||
if(current->db == dbs) {
|
||||
char path[PATH_MAX];
|
||||
char *pkgname, *pkgver;
|
||||
|
||||
pkgname = alpm_pkg_getinfo(spkg, PM_PKG_NAME);
|
||||
pkgver = alpm_pkg_getinfo(spkg, PM_PKG_VERSION);
|
||||
|
||||
if(config->op_s_printuris) {
|
||||
server_t *server = (server_t*)current->servers->data;
|
||||
snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, pkgname, pkgver);
|
||||
if(!strcmp(server->protocol, "file")) {
|
||||
MSG(NL, "%s://%s%s\n", server->protocol, server->path, path);
|
||||
} else {
|
||||
MSG(NL, "%s://%s%s%s\n", server->protocol,
|
||||
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 */
|
||||
snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, pkgname, pkgver);
|
||||
files = list_add(files, strdup(path));
|
||||
} else {
|
||||
vprint(_(" %s-%s" PM_EXT_PKG " is already in the cache\n"), pkgname, pkgver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(files) {
|
||||
struct stat buf;
|
||||
MSG(NL, _("\n:: Retrieving packages from %s...\n"), current->treename);
|
||||
fflush(stdout);
|
||||
if(stat(ldir, &buf)) {
|
||||
/* no cache directory.... try creating it */
|
||||
WARN(NL, _("no %s cache exists. creating...\n"), ldir);
|
||||
alpm_logaction(_("warning: no %s cache exists. creating..."), ldir);
|
||||
if(makepath(ldir)) {
|
||||
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
|
||||
* the package afterwards.
|
||||
*/
|
||||
WARN(NL, _("couldn't create package cache, using /tmp instead"));
|
||||
alpm_logaction(_("warning: couldn't create package cache, using /tmp instead"));
|
||||
snprintf(ldir, PATH_MAX, "/tmp");
|
||||
if(alpm_set_option(PM_OPT_CACHEDIR, (long)ldir) == -1) {
|
||||
ERR(NL, _("failed to set option CACHEDIR (%s)\n"), alpm_strerror(pm_errno));
|
||||
goto cleanup;
|
||||
}
|
||||
varcache = 0;
|
||||
}
|
||||
}
|
||||
if(downloadfiles(current->servers, ldir, files)) {
|
||||
ERR(NL, _("failed to retrieve some files from %s\n"), current->treename);
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
FREELIST(files);
|
||||
}
|
||||
}
|
||||
if(config->op_s_printuris) {
|
||||
goto cleanup;
|
||||
}
|
||||
MSG(NL, "\n");
|
||||
|
||||
/* Check integrity of files */
|
||||
MSG(NL, _("checking package integrity... "));
|
||||
|
||||
for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) {
|
||||
PM_SYNCPKG *sync = alpm_list_getdata(lp);
|
||||
PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG);
|
||||
if(alpm_pkg_checkmd5sum(spkg) == -1) {
|
||||
if(pm_errno == PM_ERR_PKG_INVALID) {
|
||||
ERR(NL, _("archive %s is corrupted\n"), alpm_pkg_getinfo(spkg, PM_PKG_NAME));
|
||||
} else {
|
||||
ERR(NL, _("could not get checksum for package %s (%s)\n"),
|
||||
alpm_pkg_getinfo(spkg, PM_PKG_NAME), alpm_strerror(pm_errno));
|
||||
}
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
if(retval) {
|
||||
goto cleanup;
|
||||
}
|
||||
MSG(CL, _("done.\n"));
|
||||
|
||||
if(config->op_s_downloadonly) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Step 3: actually perform the installation
|
||||
*/
|
||||
if(alpm_trans_commit(&data) == -1) {
|
||||
@ -747,16 +660,18 @@ int pacman_sync(list_t *targets)
|
||||
case PM_ERR_FILE_CONFLICTS:
|
||||
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
||||
PM_CONFLICT *conflict = alpm_list_getdata(lp);
|
||||
switch((int)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
|
||||
switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) {
|
||||
case PM_CONFLICT_TYPE_TARGET:
|
||||
MSG(NL, _("%s exists in \"%s\" (target) and \"%s\" (target)"),
|
||||
MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"),
|
||||
config->root,
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_FILE),
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_TARGET),
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_CTARGET));
|
||||
break;
|
||||
case PM_CONFLICT_TYPE_FILE:
|
||||
MSG(NL, _("%s: %s exists in filesystem"),
|
||||
MSG(NL, _("%s: %s%s exists in filesystem"),
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_TARGET),
|
||||
config->root,
|
||||
(char *)alpm_conflict_getinfo(conflict, PM_CONFLICT_FILE));
|
||||
break;
|
||||
}
|
||||
@ -764,6 +679,13 @@ int pacman_sync(list_t *targets)
|
||||
alpm_list_free(data);
|
||||
MSG(NL, _("\nerrors occurred, no packages were upgraded.\n"));
|
||||
break;
|
||||
case PM_ERR_PKG_CORRUPTED:
|
||||
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
|
||||
MSG(NL, "%s", (char*)alpm_list_getdata(lp));
|
||||
}
|
||||
alpm_list_free(data);
|
||||
MSG(NL, _("\nerrors occurred, no packages were upgraded.\n"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -771,13 +693,6 @@ int pacman_sync(list_t *targets)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(!varcache && !config->op_s_downloadonly) {
|
||||
/* delete packages */
|
||||
for(i = files; i; i = i->next) {
|
||||
unlink(i->data);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 4: release transaction resources
|
||||
*/
|
||||
cleanup:
|
||||
|
@ -25,7 +25,6 @@
|
||||
typedef struct __sync_t {
|
||||
char *treename;
|
||||
PM_DB *db;
|
||||
list_t *servers; /* List of server_t */
|
||||
} sync_t;
|
||||
|
||||
int pacman_sync(list_t *targets);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <math.h>
|
||||
#include <libintl.h>
|
||||
|
||||
#include <alpm.h>
|
||||
@ -39,63 +40,123 @@
|
||||
#define LOG_STR_LEN 256
|
||||
|
||||
extern config_t *config;
|
||||
extern unsigned int maxcols;
|
||||
|
||||
int prevpercent=0; /* for less progressbar output */
|
||||
|
||||
/* Callback to handle transaction events
|
||||
*/
|
||||
void cb_trans_evt(unsigned char event, void *data1, void *data2)
|
||||
{
|
||||
char str[LOG_STR_LEN] = "";
|
||||
char out[PATH_MAX];
|
||||
int i;
|
||||
|
||||
switch(event) {
|
||||
case PM_TRANS_EVT_CHECKDEPS_START:
|
||||
MSG(NL, _("checking dependencies... "));
|
||||
pm_fprintf(stderr, NL, _("checking dependencies... "));
|
||||
break;
|
||||
case PM_TRANS_EVT_FILECONFLICTS_START:
|
||||
MSG(NL, _("checking for file conflicts... "));
|
||||
pm_fprintf(stderr, NL, _("checking for file conflicts... "));
|
||||
break;
|
||||
case PM_TRANS_EVT_RESOLVEDEPS_START:
|
||||
MSG(NL, _("resolving dependencies... "));
|
||||
pm_fprintf(stderr, NL, _("resolving dependencies... "));
|
||||
break;
|
||||
case PM_TRANS_EVT_INTERCONFLICTS_START:
|
||||
MSG(NL, _("looking for inter-conflicts... "));
|
||||
pm_fprintf(stderr, NL, _("looking for inter-conflicts... "));
|
||||
break;
|
||||
case PM_TRANS_EVT_CHECKDEPS_DONE:
|
||||
case PM_TRANS_EVT_FILECONFLICTS_DONE:
|
||||
case PM_TRANS_EVT_RESOLVEDEPS_DONE:
|
||||
case PM_TRANS_EVT_INTERCONFLICTS_DONE:
|
||||
MSG(CL, _("done.\n"));
|
||||
pm_fprintf(stderr, CL, _("done.\n"));
|
||||
break;
|
||||
case PM_TRANS_EVT_EXTRACT_DONE:
|
||||
if(!config->noprogressbar) {
|
||||
MSG(NL, "");
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_EVT_ADD_START:
|
||||
MSG(NL, _("installing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
|
||||
if(config->noprogressbar) {
|
||||
MSG(NL, _("installing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_EVT_ADD_DONE:
|
||||
MSG(CL, _("done.\n"));
|
||||
if(config->noprogressbar) {
|
||||
MSG(CL, _("done.\n"));
|
||||
}
|
||||
snprintf(str, LOG_STR_LEN, _("installed %s (%s)"),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
|
||||
alpm_logaction(str);
|
||||
break;
|
||||
case PM_TRANS_EVT_REMOVE_START:
|
||||
if(config->noprogressbar) {
|
||||
MSG(NL, _("removing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_EVT_REMOVE_DONE:
|
||||
MSG(CL, _("done.\n"));
|
||||
if(config->noprogressbar) {
|
||||
MSG(CL, _("done.\n"));
|
||||
} else {
|
||||
MSG(NL, "");
|
||||
}
|
||||
snprintf(str, LOG_STR_LEN, _("removed %s (%s)"),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
|
||||
alpm_logaction(str);
|
||||
break;
|
||||
case PM_TRANS_EVT_UPGRADE_START:
|
||||
MSG(NL, _("upgrading %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
|
||||
if(config->noprogressbar) {
|
||||
MSG(NL, _("upgrading %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_EVT_UPGRADE_DONE:
|
||||
MSG(CL, _("done.\n"));
|
||||
if(config->noprogressbar) {
|
||||
MSG(CL, _("done.\n"));
|
||||
}
|
||||
snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data2, PM_PKG_VERSION),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
|
||||
alpm_logaction(str);
|
||||
break;
|
||||
case PM_TRANS_EVT_INTEGRITY_START:
|
||||
MSG(NL, _("checking package integrity... "));
|
||||
break;
|
||||
case PM_TRANS_EVT_INTEGRITY_DONE:
|
||||
MSG(CL, _("done.\n"));
|
||||
break;
|
||||
case PM_TRANS_EVT_SCRIPTLET_INFO:
|
||||
MSG(NL, "%s\n", (char*)data1);
|
||||
break;
|
||||
case PM_TRANS_EVT_SCRIPTLET_START:
|
||||
MSG(NL, (char*)data1);
|
||||
MSG(CL, "...");
|
||||
break;
|
||||
case PM_TRANS_EVT_SCRIPTLET_DONE:
|
||||
if(!(long)data1) {
|
||||
MSG(CL, _(" done.\n"));
|
||||
} else {
|
||||
MSG(CL, _(" failed.\n"));
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_EVT_PRINTURI:
|
||||
MSG(NL, "%s%s\n", (char*)data1, (char*)data2);
|
||||
break;
|
||||
case PM_TRANS_EVT_RETRIEVE_START:
|
||||
MSG(NL, _("\n:: Retrieving packages from %s...\n"), (char*)data1);
|
||||
fflush(stdout);
|
||||
break;
|
||||
case PM_TRANS_EVT_RETRIEVE_LOCAL:
|
||||
MSG(NL, " %s [", (char*)data1);
|
||||
STRNCPY(out, (char*)data2, maxcols-42);
|
||||
MSG(CL, "%s", out);
|
||||
for(i = strlen(out); i < maxcols-43; i++) {
|
||||
MSG(CL, " ");
|
||||
}
|
||||
fputs(_("] 100% LOCAL "), stdout);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,46 +166,176 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i
|
||||
|
||||
switch(event) {
|
||||
case PM_TRANS_CONV_INSTALL_IGNOREPKG:
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s requires %s, but it is in IgnorePkg. Install anyway? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data2, PM_PKG_NAME));
|
||||
*response = yesno(str);
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_INSTALL_IGNOREPKG) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s requires %s, but it is in IgnorePkg. Install anyway? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data2, PM_PKG_NAME));
|
||||
*response = yesno(str);
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_CONV_REMOVE_HOLDPKG:
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_REMOVE_HOLDPKG) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
|
||||
*response = yesno(str);
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_CONV_REPLACE_PKG:
|
||||
snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)data3,
|
||||
(char *)alpm_pkg_getinfo(data2, PM_PKG_NAME));
|
||||
*response = yesno(str);
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_REPLACE_PKG) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)data3,
|
||||
(char *)alpm_pkg_getinfo(data2, PM_PKG_NAME));
|
||||
*response = yesno(str);
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_CONV_CONFLICT_PKG:
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s conflicts with %s. Remove %s? [Y/n] "),
|
||||
(char *)data1,
|
||||
(char *)data2,
|
||||
(char *)data2);
|
||||
*response = yesno(str);
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_CONFLICT_PKG) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s conflicts with %s. Remove %s? [Y/n] "),
|
||||
(char *)data1,
|
||||
(char *)data2,
|
||||
(char *)data2);
|
||||
*response = yesno(str);
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_CONV_LOCAL_NEWER:
|
||||
if(!config->op_s_downloadonly) {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "),
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_LOCAL_NEWER) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
if(!config->op_s_downloadonly) {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
|
||||
*response = yesno(str);
|
||||
} else {
|
||||
*response = 1;
|
||||
*response = yesno(str);
|
||||
} else {
|
||||
*response = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_CONV_LOCAL_UPTODATE:
|
||||
if(!config->op_s_downloadonly) {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "),
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_LOCAL_UPTODATE) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
if(!config->op_s_downloadonly) {
|
||||
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
|
||||
(char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
|
||||
*response = yesno(str);
|
||||
*response = yesno(str);
|
||||
} else {
|
||||
*response = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PM_TRANS_CONV_CORRUPTED_PKG:
|
||||
if(config->noask) {
|
||||
if(config->ask & PM_TRANS_CONV_CORRUPTED_PKG) {
|
||||
*response = 1;
|
||||
} else {
|
||||
*response = 0;
|
||||
}
|
||||
} else {
|
||||
*response = 1;
|
||||
if(!config->noconfirm) {
|
||||
snprintf(str, LOG_STR_LEN, _(":: Archive %s is corrupted. Do you want to delete it? [Y/n] "),
|
||||
(char *)data1);
|
||||
*response = yesno(str);
|
||||
} else {
|
||||
*response = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howmany, int remain)
|
||||
{
|
||||
int i, hash;
|
||||
unsigned int maxpkglen, progresslen = maxcols - 57;
|
||||
char *addstr, *upgstr, *removestr, *ptr;
|
||||
addstr = strdup(_("installing"));
|
||||
upgstr = strdup(_("upgrading"));
|
||||
removestr = strdup(_("removing"));
|
||||
|
||||
if(config->noprogressbar) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pkgname)
|
||||
return;
|
||||
if (percent > 100)
|
||||
return;
|
||||
if(percent == prevpercent)
|
||||
return;
|
||||
|
||||
prevpercent=percent;
|
||||
switch (event) {
|
||||
case PM_TRANS_PROGRESS_ADD_START:
|
||||
ptr = addstr;
|
||||
break;
|
||||
|
||||
case PM_TRANS_PROGRESS_UPGRADE_START:
|
||||
ptr = upgstr;
|
||||
break;
|
||||
case PM_TRANS_PROGRESS_REMOVE_START:
|
||||
ptr = removestr;
|
||||
break;
|
||||
}
|
||||
hash=percent*progresslen/100;
|
||||
|
||||
// if the package name is too long, then slice the ending
|
||||
maxpkglen=46-strlen(ptr)-(3+2*(int)log10(howmany));
|
||||
if(strlen(pkgname)>maxpkglen)
|
||||
pkgname[maxpkglen]='\0';
|
||||
|
||||
putchar('(');
|
||||
for(i=0;i<(int)log10(howmany)-(int)log10(remain);i++)
|
||||
putchar(' ');
|
||||
printf("%d/%d) %s %s ", remain, howmany, ptr, pkgname);
|
||||
if (strlen(pkgname)<maxpkglen)
|
||||
for (i=maxpkglen-strlen(pkgname)-1; i>0; i--)
|
||||
putchar(' ');
|
||||
printf("[");
|
||||
for (i = progresslen; i > 0; i--) {
|
||||
if (i >= progresslen - hash)
|
||||
printf("#");
|
||||
else
|
||||
printf("-");
|
||||
}
|
||||
MSG(CL, "] %3d%%\r", percent);
|
||||
FREE(addstr);
|
||||
FREE(upgstr);
|
||||
FREE(removestr);
|
||||
}
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -27,6 +27,8 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2);
|
||||
/* callback to handle questions from pacman transactions (yes/no) */
|
||||
void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, int *response);
|
||||
|
||||
void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howmany, int remain);
|
||||
|
||||
#endif /* _PM_TRANS_H */
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -19,6 +19,11 @@
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#if defined(__APPLE__) || defined(__OpenBSD__)
|
||||
#include <sys/syslimits.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -29,7 +34,6 @@
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <regex.h>
|
||||
#include <libintl.h>
|
||||
#ifdef CYGWIN
|
||||
#include <limits.h> /* PATH_MAX */
|
||||
@ -43,6 +47,7 @@
|
||||
|
||||
extern int maxcols;
|
||||
extern config_t *config;
|
||||
extern int neednl;
|
||||
|
||||
/* does the same thing as 'mkdir -p' */
|
||||
int makepath(char *path)
|
||||
@ -216,19 +221,4 @@ char *strtrim(char *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
/* match a string against a regular expression */
|
||||
int reg_match(char *string, char *pattern)
|
||||
{
|
||||
int result;
|
||||
regex_t reg;
|
||||
|
||||
if(regcomp(®, pattern, REG_EXTENDED | REG_NOSUB | REG_ICASE) != 0) {
|
||||
ERR(NL, _("%s is not a valid regular expression.\n"), pattern);
|
||||
return(-1);
|
||||
}
|
||||
result = regexec(®, string, 0, 0, 0);
|
||||
regfree(®);
|
||||
return(!(result));
|
||||
}
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -27,7 +27,7 @@
|
||||
if((b) > 0) { \
|
||||
p = malloc(b); \
|
||||
if (!(p)) { \
|
||||
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", b); \
|
||||
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", (int)b); \
|
||||
exit(1); \
|
||||
} \
|
||||
} else { \
|
||||
|
Loading…
Reference in New Issue
Block a user