Rip alpm_parse_config out of libalpm
Switch over to the new frontend parseconfig. * Fix a few issues in parseconfig * Remove unused callback upon database registration * Remove conf file related errors from error.c/alpm.h Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
6949ab9761
commit
358cc5804a
12 changed files with 48 additions and 303 deletions
|
@ -138,7 +138,7 @@ pmdb_t SYMEXPORT *alpm_db_register(char *treename)
|
||||||
/* Do not register a database if a transaction is on-going */
|
/* Do not register a database if a transaction is on-going */
|
||||||
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
|
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
|
||||||
|
|
||||||
return(_alpm_db_register(treename, NULL));
|
return(_alpm_db_register(treename));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unregister a package database
|
/** Unregister a package database
|
||||||
|
@ -869,211 +869,6 @@ char SYMEXPORT *alpm_fetch_pkgurl(char *url)
|
||||||
return(_alpm_fetch_pkgurl(url));
|
return(_alpm_fetch_pkgurl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parses a configuration file.
|
|
||||||
* @param file path to the config file.
|
|
||||||
* @param callback a function to be called upon new database creation
|
|
||||||
* @param this_section the config current section being parsed
|
|
||||||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
||||||
*/
|
|
||||||
int SYMEXPORT alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this_section)
|
|
||||||
{
|
|
||||||
FILE *fp = NULL;
|
|
||||||
char line[PATH_MAX+1];
|
|
||||||
char *ptr = NULL;
|
|
||||||
char *key = NULL;
|
|
||||||
int linenum = 0;
|
|
||||||
char origkey[256];
|
|
||||||
char section[256] = "";
|
|
||||||
pmdb_t *db = NULL;
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
fp = fopen(file, "r");
|
|
||||||
if(fp == NULL) {
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this_section != NULL && strlen(this_section) > 0) {
|
|
||||||
strncpy(section, this_section, min(255, strlen(this_section)));
|
|
||||||
if(!strcmp(section, "local")) {
|
|
||||||
RET_ERR(PM_ERR_CONF_LOCAL, -1);
|
|
||||||
}
|
|
||||||
if(strcmp(section, "options")) {
|
|
||||||
db = _alpm_db_register(section, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while(fgets(line, PATH_MAX, fp)) {
|
|
||||||
linenum++;
|
|
||||||
_alpm_strtrim(line);
|
|
||||||
if(strlen(line) == 0 || line[0] == '#') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if((ptr = strchr(line, '#'))) {
|
|
||||||
*ptr = '\0';
|
|
||||||
}
|
|
||||||
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';
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: new section '%s'"), section);
|
|
||||||
if(!strlen(section)) {
|
|
||||||
RET_ERR(PM_ERR_CONF_BAD_SECTION, -1);
|
|
||||||
}
|
|
||||||
if(!strcmp(section, "local")) {
|
|
||||||
RET_ERR(PM_ERR_CONF_LOCAL, -1);
|
|
||||||
}
|
|
||||||
if(strcmp(section, "options")) {
|
|
||||||
db = _alpm_db_register(section, callback);
|
|
||||||
if(db == NULL) {
|
|
||||||
/* pm_errno is set by alpm_db_register */
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* directive */
|
|
||||||
ptr = line;
|
|
||||||
key = strsep(&ptr, "=");
|
|
||||||
if(key == NULL) {
|
|
||||||
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
|
|
||||||
}
|
|
||||||
_alpm_strtrim(key);
|
|
||||||
strncpy(origkey, key, min(255, strlen(key)));
|
|
||||||
key = _alpm_strtoupper(key);
|
|
||||||
if(!strlen(section) && strcmp(key, "INCLUDE")) {
|
|
||||||
RET_ERR(PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION, -1);
|
|
||||||
}
|
|
||||||
if(ptr == NULL) {
|
|
||||||
if(strcmp(origkey, "NoPassiveFTP") == 0 || strcmp(key, "NOPASSIVEFTP") == 0) {
|
|
||||||
alpm_option_set_nopassiveftp(1);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: nopassiveftp"));
|
|
||||||
} else if(strcmp(origkey, "UseSyslog") == 0 || strcmp(key, "USESYSLOG") == 0) {
|
|
||||||
alpm_option_set_usesyslog(1);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: usesyslog"));
|
|
||||||
} else if(strcmp(origkey, "ILoveCandy") == 0 || strcmp(key, "ILOVECANDY") == 0) {
|
|
||||||
alpm_option_set_chomp(1);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: chomp"));
|
|
||||||
} else if(strcmp(origkey, "UseColor") == 0 || strcmp(key, "USECOLOR") == 0) {
|
|
||||||
alpm_option_set_usecolor(1);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: usecolor"));
|
|
||||||
} else if(strcmp(origkey, "ShowSize") == 0 || strcmp(key, "SHOWSIZE") == 0) {
|
|
||||||
alpm_option_set_showsize(1);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: showsize"));
|
|
||||||
} else {
|
|
||||||
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_alpm_strtrim(ptr);
|
|
||||||
if(strcmp(origkey, "Include") == 0 || strcmp(key, "INCLUDE") == 0) {
|
|
||||||
char conf[PATH_MAX];
|
|
||||||
strncpy(conf, ptr, PATH_MAX);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: including %s"), conf);
|
|
||||||
alpm_parse_config(conf, callback, section);
|
|
||||||
} else if(strcmp(section, "options") == 0) {
|
|
||||||
if(strcmp(origkey, "NoUpgrade") == 0 || strcmp(key, "NOUPGRADE") == 0) {
|
|
||||||
char *p = ptr;
|
|
||||||
char *q;
|
|
||||||
|
|
||||||
while((q = strchr(p, ' '))) {
|
|
||||||
*q = '\0';
|
|
||||||
alpm_option_add_noupgrade(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
|
|
||||||
p = q;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
alpm_option_add_noupgrade(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
|
|
||||||
} else if(strcmp(origkey, "NoExtract") == 0 || strcmp(key, "NOEXTRACT") == 0) {
|
|
||||||
char *p = ptr;
|
|
||||||
char *q;
|
|
||||||
|
|
||||||
while((q = strchr(p, ' '))) {
|
|
||||||
*q = '\0';
|
|
||||||
alpm_option_add_noextract(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
|
|
||||||
p = q;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
alpm_option_add_noextract(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
|
|
||||||
} else if(strcmp(origkey, "IgnorePkg") == 0 || strcmp(key, "IGNOREPKG") == 0) {
|
|
||||||
char *p = ptr;
|
|
||||||
char *q;
|
|
||||||
|
|
||||||
while((q = strchr(p, ' '))) {
|
|
||||||
*q = '\0';
|
|
||||||
alpm_option_add_ignorepkg(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
|
|
||||||
p = q;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
alpm_option_add_ignorepkg(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
|
|
||||||
} else if(strcmp(origkey, "HoldPkg") == 0 || strcmp(key, "HOLDPKG") == 0) {
|
|
||||||
char *p = ptr;
|
|
||||||
char *q;
|
|
||||||
|
|
||||||
while((q = strchr(p, ' '))) {
|
|
||||||
*q = '\0';
|
|
||||||
alpm_option_add_holdpkg(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
|
|
||||||
p = q;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
alpm_option_add_holdpkg(p);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
|
|
||||||
} else if(strcmp(origkey, "DBPath") == 0 || strcmp(key, "DBPATH") == 0) {
|
|
||||||
alpm_option_set_dbpath(ptr);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: dbpath: %s"), ptr);
|
|
||||||
} else if(strcmp(origkey, "CacheDir") == 0 || strcmp(key, "CACHEDIR") == 0) {
|
|
||||||
alpm_option_set_cachedir(ptr);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: cachedir: %s"), ptr);
|
|
||||||
} else if(strcmp(origkey, "RootDir") == 0 || strcmp(key, "ROOTDIR") == 0) {
|
|
||||||
alpm_option_set_root(ptr);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: rootdir: %s"), ptr);
|
|
||||||
} else if (strcmp(origkey, "LogFile") == 0 || strcmp(key, "LOGFILE") == 0) {
|
|
||||||
alpm_option_set_logfile(ptr);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: logfile: %s"), ptr);
|
|
||||||
} else if (strcmp(origkey, "LockFile") == 0 || strcmp(key, "LOCKFILE") == 0) {
|
|
||||||
alpm_option_set_lockfile(ptr);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: lockfile: %s"), ptr);
|
|
||||||
} else if (strcmp(origkey, "XferCommand") == 0 || strcmp(key, "XFERCOMMAND") == 0) {
|
|
||||||
alpm_option_set_xfercommand(ptr);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: xfercommand: %s"), ptr);
|
|
||||||
} else if (strcmp(origkey, "UpgradeDelay") == 0 || strcmp(key, "UPGRADEDELAY") == 0) {
|
|
||||||
/* The config value is in days, we use seconds */
|
|
||||||
time_t ud = atol(ptr) * 60 * 60 *24;
|
|
||||||
alpm_option_set_upgradedelay(ud);
|
|
||||||
_alpm_log(PM_LOG_DEBUG, _("config: upgradedelay: %d"), ud);
|
|
||||||
} else {
|
|
||||||
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(strcmp(origkey, "Server") == 0 || strcmp(key, "SERVER") == 0) {
|
|
||||||
/* let's attempt a replacement for the current repo */
|
|
||||||
char *server = _alpm_strreplace(ptr, "$repo", section);
|
|
||||||
|
|
||||||
if(alpm_db_setserver(db, server) != 0) {
|
|
||||||
/* pm_errno is set by alpm_db_setserver */
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(server);
|
|
||||||
} else {
|
|
||||||
RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
line[0] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/* This function is mostly the same as sync.c find_replacements and sysupgrade
|
/* This function is mostly the same as sync.c find_replacements and sysupgrade
|
||||||
|
|
|
@ -137,19 +137,10 @@ void alpm_option_set_xfercommand(const char *cmd);
|
||||||
unsigned short alpm_option_get_nopassiveftp();
|
unsigned short alpm_option_get_nopassiveftp();
|
||||||
void alpm_option_set_nopassiveftp(unsigned short nopasv);
|
void alpm_option_set_nopassiveftp(unsigned short nopasv);
|
||||||
|
|
||||||
unsigned short alpm_option_get_chomp();
|
|
||||||
void alpm_option_set_chomp(unsigned short chomp);
|
|
||||||
|
|
||||||
alpm_list_t *alpm_option_get_needles();
|
alpm_list_t *alpm_option_get_needles();
|
||||||
void alpm_option_add_needle(char *needle);
|
void alpm_option_add_needle(char *needle);
|
||||||
void alpm_option_set_needles(alpm_list_t *needles);
|
void alpm_option_set_needles(alpm_list_t *needles);
|
||||||
|
|
||||||
unsigned short alpm_option_get_usecolor();
|
|
||||||
void alpm_option_set_usecolor(unsigned short usecolor);
|
|
||||||
|
|
||||||
unsigned short alpm_option_get_showsize();
|
|
||||||
void alpm_option_set_showsize(unsigned short showsize);
|
|
||||||
|
|
||||||
pmdb_t *alpm_option_get_localdb();
|
pmdb_t *alpm_option_get_localdb();
|
||||||
alpm_list_t *alpm_option_get_syncdbs();
|
alpm_list_t *alpm_option_get_syncdbs();
|
||||||
|
|
||||||
|
@ -157,9 +148,6 @@ alpm_list_t *alpm_option_get_syncdbs();
|
||||||
* Databases
|
* Databases
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Database registration callback */
|
|
||||||
typedef void (*alpm_cb_db_register)(const char *, pmdb_t *);
|
|
||||||
|
|
||||||
pmdb_t *alpm_db_register(char *treename);
|
pmdb_t *alpm_db_register(char *treename);
|
||||||
int alpm_db_unregister(pmdb_t *db);
|
int alpm_db_unregister(pmdb_t *db);
|
||||||
|
|
||||||
|
@ -203,8 +191,6 @@ int alpm_pkg_free(pmpkg_t *pkg);
|
||||||
int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
|
int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
|
||||||
int alpm_pkg_checksha1sum(pmpkg_t *pkg);
|
int alpm_pkg_checksha1sum(pmpkg_t *pkg);
|
||||||
char *alpm_fetch_pkgurl(char *url);
|
char *alpm_fetch_pkgurl(char *url);
|
||||||
int alpm_parse_config(char *file, alpm_cb_db_register callback,
|
|
||||||
const char *this_section);
|
|
||||||
int alpm_pkg_vercmp(const char *ver1, const char *ver2);
|
int alpm_pkg_vercmp(const char *ver1, const char *ver2);
|
||||||
char *alpm_pkg_name_hasarch(char *pkgname);
|
char *alpm_pkg_name_hasarch(char *pkgname);
|
||||||
|
|
||||||
|
@ -463,11 +449,6 @@ enum _pmerrno_t {
|
||||||
PM_ERR_DB_SYNC,
|
PM_ERR_DB_SYNC,
|
||||||
PM_ERR_RETRIEVE,
|
PM_ERR_RETRIEVE,
|
||||||
PM_ERR_PKG_HOLD,
|
PM_ERR_PKG_HOLD,
|
||||||
/* Configuration file */
|
|
||||||
PM_ERR_CONF_BAD_SECTION,
|
|
||||||
PM_ERR_CONF_LOCAL,
|
|
||||||
PM_ERR_CONF_BAD_SYNTAX,
|
|
||||||
PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION,
|
|
||||||
PM_ERR_INVALID_REGEX,
|
PM_ERR_INVALID_REGEX,
|
||||||
/* Downloading */
|
/* Downloading */
|
||||||
PM_ERR_CONNECT_FAILED,
|
PM_ERR_CONNECT_FAILED,
|
||||||
|
|
|
@ -157,7 +157,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
|
pmdb_t *_alpm_db_register(const char *treename)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
pmdb_t *db;
|
pmdb_t *db;
|
||||||
|
@ -206,9 +206,6 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
|
||||||
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only call callback on NEW registration. */
|
|
||||||
if(callback) callback(treename, db);
|
|
||||||
|
|
||||||
if(strcmp(treename, "local") == 0) {
|
if(strcmp(treename, "local") == 0) {
|
||||||
handle->db_local = db;
|
handle->db_local = db;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -52,7 +52,7 @@ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename);
|
||||||
void _alpm_db_free(pmdb_t *db);
|
void _alpm_db_free(pmdb_t *db);
|
||||||
int _alpm_db_cmp(const void *db1, const void *db2);
|
int _alpm_db_cmp(const void *db1, const void *db2);
|
||||||
alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles);
|
alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles);
|
||||||
pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback);
|
pmdb_t *_alpm_db_register(const char *treename);
|
||||||
|
|
||||||
/* be.c, backend specific calls */
|
/* be.c, backend specific calls */
|
||||||
int _alpm_db_install(pmdb_t *db, const char *dbfile);
|
int _alpm_db_install(pmdb_t *db, const char *dbfile);
|
||||||
|
|
|
@ -138,15 +138,6 @@ char SYMEXPORT *alpm_strerror(int err)
|
||||||
case PM_ERR_PKG_HOLD:
|
case PM_ERR_PKG_HOLD:
|
||||||
/* TODO wow this is not descriptive at all... what does this mean? */
|
/* TODO wow this is not descriptive at all... what does this mean? */
|
||||||
return _("not confirmed");
|
return _("not confirmed");
|
||||||
/* Configuration file */
|
|
||||||
case PM_ERR_CONF_BAD_SECTION:
|
|
||||||
return _("bad configuration section name");
|
|
||||||
case PM_ERR_CONF_LOCAL:
|
|
||||||
return _("'local' is reserved and cannot be used as a repository name");
|
|
||||||
case PM_ERR_CONF_BAD_SYNTAX:
|
|
||||||
return _("syntax error in config file");
|
|
||||||
case PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION:
|
|
||||||
return _("all directives must belong to a section");
|
|
||||||
case PM_ERR_INVALID_REGEX:
|
case PM_ERR_INVALID_REGEX:
|
||||||
return _("invalid regular expression");
|
return _("invalid regular expression");
|
||||||
/* Downloading */
|
/* Downloading */
|
||||||
|
|
|
@ -138,9 +138,6 @@ alpm_list_t SYMEXPORT *alpm_option_get_holdpkgs() { return handle->holdpkg; }
|
||||||
time_t SYMEXPORT alpm_option_get_upgradedelay() { return handle->upgradedelay; }
|
time_t SYMEXPORT alpm_option_get_upgradedelay() { return handle->upgradedelay; }
|
||||||
const char SYMEXPORT *alpm_option_get_xfercommand() { return handle->xfercommand; }
|
const char SYMEXPORT *alpm_option_get_xfercommand() { return handle->xfercommand; }
|
||||||
unsigned short SYMEXPORT alpm_option_get_nopassiveftp() { return handle->nopassiveftp; }
|
unsigned short SYMEXPORT alpm_option_get_nopassiveftp() { return handle->nopassiveftp; }
|
||||||
unsigned short SYMEXPORT alpm_option_get_chomp() { return handle->chomp; }
|
|
||||||
unsigned short SYMEXPORT alpm_option_get_usecolor() { return handle->use_color; }
|
|
||||||
unsigned short SYMEXPORT alpm_option_get_showsize() { return handle->showsize; }
|
|
||||||
|
|
||||||
pmdb_t SYMEXPORT *alpm_option_get_localdb() { return handle->db_local; }
|
pmdb_t SYMEXPORT *alpm_option_get_localdb() { return handle->db_local; }
|
||||||
alpm_list_t SYMEXPORT *alpm_option_get_syncdbs()
|
alpm_list_t SYMEXPORT *alpm_option_get_syncdbs()
|
||||||
|
@ -302,19 +299,4 @@ void SYMEXPORT alpm_option_set_nopassiveftp(unsigned short nopasv)
|
||||||
handle->nopassiveftp = nopasv;
|
handle->nopassiveftp = nopasv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SYMEXPORT alpm_option_set_chomp(unsigned short chomp)
|
|
||||||
{
|
|
||||||
handle->chomp = chomp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SYMEXPORT alpm_option_set_usecolor(unsigned short usecolor)
|
|
||||||
{
|
|
||||||
handle->use_color = usecolor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SYMEXPORT alpm_option_set_showsize(unsigned short showsize)
|
|
||||||
{
|
|
||||||
handle->showsize = showsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vim: set ts=2 sw=2 noet: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
|
|
@ -47,26 +47,23 @@ typedef struct _pmhandle_t {
|
||||||
/* options */
|
/* options */
|
||||||
alpm_cb_log logcb; /* Log callback function */
|
alpm_cb_log logcb; /* Log callback function */
|
||||||
alpm_cb_download dlcb; /* Download callback function */
|
alpm_cb_download dlcb; /* Download callback function */
|
||||||
unsigned short logmask; /* Output mask for logging functions */
|
unsigned short logmask; /* Output mask for logging functions */ /* TODO move to frontend */
|
||||||
char *root; /* Root path, default '/' */
|
char *root; /* Root path, default '/' */
|
||||||
char *dbpath; /* Base path to pacman's DBs */
|
char *dbpath; /* Base path to pacman's DBs */
|
||||||
char *cachedir; /* Base path to pacman's cache */
|
char *cachedir; /* Base path to pacman's cache */
|
||||||
char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
|
char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
|
||||||
char *lockfile; /* Name of the lock file */
|
char *lockfile; /* Name of the lock file */
|
||||||
unsigned short usesyslog; /* Use syslog instead of logfile? */
|
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
|
||||||
|
|
||||||
alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */
|
alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */
|
||||||
alpm_list_t *noextract; /* List of packages NOT to extrace */ /*TODO is this used?*/
|
alpm_list_t *noextract; /* List of packages NOT to extract */ /*TODO is this used?*/
|
||||||
alpm_list_t *ignorepkg; /* List of packages to ignore */
|
alpm_list_t *ignorepkg; /* List of packages to ignore */
|
||||||
alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */
|
alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */
|
||||||
|
|
||||||
time_t upgradedelay; /* Amount of time to wait before upgrading a package*/
|
time_t upgradedelay; /* Amount of time to wait before upgrading a package */
|
||||||
/* servers */
|
/* servers */
|
||||||
char *xfercommand; /* External download command */
|
char *xfercommand; /* External download command */
|
||||||
unsigned short nopassiveftp; /* Don't use PASV ftp connections */
|
unsigned short nopassiveftp; /* Don't use PASV ftp connections */
|
||||||
unsigned short chomp; /* I Love Candy! */
|
|
||||||
unsigned short use_color; /* enable colorful output */
|
|
||||||
unsigned short showsize; /* Show individual package sizes */
|
|
||||||
} pmhandle_t;
|
} pmhandle_t;
|
||||||
|
|
||||||
extern pmhandle_t *handle;
|
extern pmhandle_t *handle;
|
||||||
|
|
|
@ -91,7 +91,6 @@ static float get_update_timediff(int first_call)
|
||||||
/* refactored from cb_trans_progress */
|
/* refactored from cb_trans_progress */
|
||||||
static void fill_progress(const int percent, const int proglen)
|
static void fill_progress(const int percent, const int proglen)
|
||||||
{
|
{
|
||||||
const unsigned short chomp = alpm_option_get_chomp();
|
|
||||||
const unsigned int hashlen = proglen - 8;
|
const unsigned int hashlen = proglen - 8;
|
||||||
const unsigned int hash = percent * hashlen / 100;
|
const unsigned int hash = percent * hashlen / 100;
|
||||||
static unsigned int lasthash = 0, mouth = 0;
|
static unsigned int lasthash = 0, mouth = 0;
|
||||||
|
@ -109,7 +108,7 @@ static void fill_progress(const int percent, const int proglen)
|
||||||
printf(" [");
|
printf(" [");
|
||||||
for(i = hashlen; i > 1; --i) {
|
for(i = hashlen; i > 1; --i) {
|
||||||
/* if special progress bar enabled */
|
/* if special progress bar enabled */
|
||||||
if(chomp) {
|
if(config->chomp) {
|
||||||
if(i > hashlen - hash) {
|
if(i > hashlen - hash) {
|
||||||
printf("-");
|
printf("-");
|
||||||
} else if(i == hashlen - hash) {
|
} else if(i == hashlen - hash) {
|
||||||
|
|
|
@ -495,20 +495,24 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
}
|
}
|
||||||
section = strdup(ptr);
|
section = strdup(ptr);
|
||||||
section[strlen(section)-1] = '\0';
|
section[strlen(section)-1] = '\0';
|
||||||
printf(_("config: new section '%s'"), section);
|
printf(_("config: new section '%s'\n"), section);
|
||||||
if(!strlen(section)) {
|
if(!strlen(section)) {
|
||||||
printf("PM_ERR_CONF_BAD_SECTION");
|
printf("PM_ERR_CONF_BAD_SECTION\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
/* a section/database named local is not allowed */
|
||||||
if(!strcmp(section, "local")) {
|
if(!strcmp(section, "local")) {
|
||||||
printf("PM_ERR_CONF_LOCAL");
|
printf("PM_ERR_CONF_LOCAL\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
/* if we are not looking at the options section, register a db */
|
||||||
|
if(strcmp(section, "options") != 0) {
|
||||||
|
alpm_db_register(section);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* directive */
|
/* directive */
|
||||||
char *key;
|
char *key;
|
||||||
const char *upperkey;
|
const char *upperkey;
|
||||||
|
|
||||||
/* strsep modifies the 'line' string: 'key \0 ptr' */
|
/* strsep modifies the 'line' string: 'key \0 ptr' */
|
||||||
key = line;
|
key = line;
|
||||||
ptr = line;
|
ptr = line;
|
||||||
|
@ -517,12 +521,12 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
strtrim(ptr);
|
strtrim(ptr);
|
||||||
|
|
||||||
if(key == NULL) {
|
if(key == NULL) {
|
||||||
printf("PM_ERR_CONF_BAD_SYNTAX");
|
printf("PM_ERR_CONF_BAD_SYNTAX\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
upperkey = strtoupper(strdup(key));
|
upperkey = strtoupper(strdup(key));
|
||||||
if(!strlen(section) && strcmp(key, "INCLUDE")) {
|
if(section == NULL && (strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0)) {
|
||||||
printf("PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION");
|
printf("PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
if(ptr == NULL) {
|
if(ptr == NULL) {
|
||||||
|
@ -530,27 +534,27 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
/* TODO shouldn't we check if these are in the [options] section? */
|
/* TODO shouldn't we check if these are in the [options] section? */
|
||||||
if(strcmp(key, "NoPassiveFTP") == 0 || strcmp(upperkey, "NOPASSIVEFTP") == 0) {
|
if(strcmp(key, "NoPassiveFTP") == 0 || strcmp(upperkey, "NOPASSIVEFTP") == 0) {
|
||||||
alpm_option_set_nopassiveftp(1);
|
alpm_option_set_nopassiveftp(1);
|
||||||
printf(_("config: nopassiveftp"));
|
printf(_("config: nopassiveftp\n"));
|
||||||
} else if(strcmp(key, "UseSyslog") == 0 || strcmp(upperkey, "USESYSLOG") == 0) {
|
} else if(strcmp(key, "UseSyslog") == 0 || strcmp(upperkey, "USESYSLOG") == 0) {
|
||||||
alpm_option_set_usesyslog(1);
|
alpm_option_set_usesyslog(1);
|
||||||
printf(_("config: usesyslog"));
|
printf(_("config: usesyslog\n"));
|
||||||
} else if(strcmp(key, "ILoveCandy") == 0 || strcmp(upperkey, "ILOVECANDY") == 0) {
|
} else if(strcmp(key, "ILoveCandy") == 0 || strcmp(upperkey, "ILOVECANDY") == 0) {
|
||||||
config->chomp = 1;
|
config->chomp = 1;
|
||||||
printf(_("config: chomp"));
|
printf(_("config: chomp\n"));
|
||||||
} else if(strcmp(key, "UseColor") == 0 || strcmp(upperkey, "USECOLOR") == 0) {
|
} else if(strcmp(key, "UseColor") == 0 || strcmp(upperkey, "USECOLOR") == 0) {
|
||||||
config->usecolor = 1;
|
config->usecolor = 1;
|
||||||
printf(_("config: usecolor"));
|
printf(_("config: usecolor\n"));
|
||||||
} else if(strcmp(key, "ShowSize") == 0 || strcmp(upperkey, "SHOWSIZE") == 0) {
|
} else if(strcmp(key, "ShowSize") == 0 || strcmp(upperkey, "SHOWSIZE") == 0) {
|
||||||
config->showsize= 1;
|
config->showsize= 1;
|
||||||
printf(_("config: showsize"));
|
printf(_("config: showsize\n"));
|
||||||
} else {
|
} else {
|
||||||
printf("PM_ERR_CONF_BAD_SYNTAX");
|
printf("PM_ERR_CONF_BAD_SYNTAX\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* directives with settings */
|
/* directives with settings */
|
||||||
if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) {
|
if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) {
|
||||||
printf(_("config: including %s"), ptr);
|
printf(_("config: including %s\n"), ptr);
|
||||||
_parseconfig(ptr, section);
|
_parseconfig(ptr, section);
|
||||||
} else if(strcmp(section, "options") == 0) {
|
} else if(strcmp(section, "options") == 0) {
|
||||||
if(strcmp(key, "NoUpgrade") == 0 || strcmp(upperkey, "NOUPGRADE") == 0) {
|
if(strcmp(key, "NoUpgrade") == 0 || strcmp(upperkey, "NOUPGRADE") == 0) {
|
||||||
|
@ -561,12 +565,12 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
while((q = strchr(p, ' '))) {
|
while((q = strchr(p, ' '))) {
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
alpm_option_add_noupgrade(p);
|
alpm_option_add_noupgrade(p);
|
||||||
printf(_("config: noupgrade: %s"), p);
|
printf(_("config: noupgrade: %s\n"), p);
|
||||||
p = q;
|
p = q;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
alpm_option_add_noupgrade(p);
|
alpm_option_add_noupgrade(p);
|
||||||
printf(_("config: noupgrade: %s"), p);
|
printf(_("config: noupgrade: %s\n"), p);
|
||||||
} else if(strcmp(key, "NoExtract") == 0 || strcmp(upperkey, "NOEXTRACT") == 0) {
|
} else if(strcmp(key, "NoExtract") == 0 || strcmp(upperkey, "NOEXTRACT") == 0) {
|
||||||
char *p = ptr;
|
char *p = ptr;
|
||||||
char *q;
|
char *q;
|
||||||
|
@ -574,12 +578,12 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
while((q = strchr(p, ' '))) {
|
while((q = strchr(p, ' '))) {
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
alpm_option_add_noextract(p);
|
alpm_option_add_noextract(p);
|
||||||
printf(_("config: noextract: %s"), p);
|
printf(_("config: noextract: %s\n"), p);
|
||||||
p = q;
|
p = q;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
alpm_option_add_noextract(p);
|
alpm_option_add_noextract(p);
|
||||||
printf(_("config: noextract: %s"), p);
|
printf(_("config: noextract: %s\n"), p);
|
||||||
} else if(strcmp(key, "IgnorePkg") == 0 || strcmp(upperkey, "IGNOREPKG") == 0) {
|
} else if(strcmp(key, "IgnorePkg") == 0 || strcmp(upperkey, "IGNOREPKG") == 0) {
|
||||||
char *p = ptr;
|
char *p = ptr;
|
||||||
char *q;
|
char *q;
|
||||||
|
@ -592,7 +596,7 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
alpm_option_add_ignorepkg(p);
|
alpm_option_add_ignorepkg(p);
|
||||||
printf(_("config: ignorepkg: %s"), p);
|
printf(_("config: ignorepkg: %s\n"), p);
|
||||||
} else if(strcmp(key, "HoldPkg") == 0 || strcmp(upperkey, "HOLDPKG") == 0) {
|
} else if(strcmp(key, "HoldPkg") == 0 || strcmp(upperkey, "HOLDPKG") == 0) {
|
||||||
char *p = ptr;
|
char *p = ptr;
|
||||||
char *q;
|
char *q;
|
||||||
|
@ -600,37 +604,37 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
while((q = strchr(p, ' '))) {
|
while((q = strchr(p, ' '))) {
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
alpm_option_add_holdpkg(p);
|
alpm_option_add_holdpkg(p);
|
||||||
printf(_("config: holdpkg: %s"), p);
|
printf(_("config: holdpkg: %s\n"), p);
|
||||||
p = q;
|
p = q;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
alpm_option_add_holdpkg(p);
|
alpm_option_add_holdpkg(p);
|
||||||
printf(_("config: holdpkg: %s"), p);
|
printf(_("config: holdpkg: %s\n"), p);
|
||||||
} else if(strcmp(key, "DBPath") == 0 || strcmp(upperkey, "DBPATH") == 0) {
|
} else if(strcmp(key, "DBPath") == 0 || strcmp(upperkey, "DBPATH") == 0) {
|
||||||
alpm_option_set_dbpath(ptr);
|
alpm_option_set_dbpath(ptr);
|
||||||
printf(_("config: dbpath: %s"), ptr);
|
printf(_("config: dbpath: %s\n"), ptr);
|
||||||
} else if(strcmp(key, "CacheDir") == 0 || strcmp(upperkey, "CACHEDIR") == 0) {
|
} else if(strcmp(key, "CacheDir") == 0 || strcmp(upperkey, "CACHEDIR") == 0) {
|
||||||
alpm_option_set_cachedir(ptr);
|
alpm_option_set_cachedir(ptr);
|
||||||
printf(_("config: cachedir: %s"), ptr);
|
printf(_("config: cachedir: %s\n"), ptr);
|
||||||
} else if(strcmp(key, "RootDir") == 0 || strcmp(upperkey, "ROOTDIR") == 0) {
|
} else if(strcmp(key, "RootDir") == 0 || strcmp(upperkey, "ROOTDIR") == 0) {
|
||||||
alpm_option_set_root(ptr);
|
alpm_option_set_root(ptr);
|
||||||
printf(_("config: rootdir: %s"), ptr);
|
printf(_("config: rootdir: %s\n"), ptr);
|
||||||
} else if (strcmp(key, "LogFile") == 0 || strcmp(upperkey, "LOGFILE") == 0) {
|
} else if (strcmp(key, "LogFile") == 0 || strcmp(upperkey, "LOGFILE") == 0) {
|
||||||
alpm_option_set_logfile(ptr);
|
alpm_option_set_logfile(ptr);
|
||||||
printf(_("config: logfile: %s"), ptr);
|
printf(_("config: logfile: %s\n"), ptr);
|
||||||
} else if (strcmp(key, "LockFile") == 0 || strcmp(upperkey, "LOCKFILE") == 0) {
|
} else if (strcmp(key, "LockFile") == 0 || strcmp(upperkey, "LOCKFILE") == 0) {
|
||||||
alpm_option_set_lockfile(ptr);
|
alpm_option_set_lockfile(ptr);
|
||||||
printf(_("config: lockfile: %s"), ptr);
|
printf(_("config: lockfile: %s\n"), ptr);
|
||||||
} else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) {
|
} else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) {
|
||||||
alpm_option_set_xfercommand(ptr);
|
alpm_option_set_xfercommand(ptr);
|
||||||
printf(_("config: xfercommand: %s"), ptr);
|
printf(_("config: xfercommand: %s\n"), ptr);
|
||||||
} else if (strcmp(key, "UpgradeDelay") == 0 || strcmp(upperkey, "UPGRADEDELAY") == 0) {
|
} else if (strcmp(key, "UpgradeDelay") == 0 || strcmp(upperkey, "UPGRADEDELAY") == 0) {
|
||||||
/* The config value is in days, we use seconds */
|
/* The config value is in days, we use seconds */
|
||||||
time_t ud = atol(ptr) * 60 * 60 *24;
|
time_t ud = atol(ptr) * 60 * 60 *24;
|
||||||
alpm_option_set_upgradedelay(ud);
|
alpm_option_set_upgradedelay(ud);
|
||||||
printf(_("config: upgradedelay: %d"), (int)ud);
|
printf(_("config: upgradedelay: %d\n"), (int)ud);
|
||||||
} else {
|
} else {
|
||||||
printf("PM_ERR_CONF_BAD_SYNTAX");
|
printf("PM_ERR_CONF_BAD_SYNTAX\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -640,16 +644,15 @@ static int _parseconfig(const char *file, const char *givensection)
|
||||||
|
|
||||||
if(alpm_db_setserver(db, server) != 0) {
|
if(alpm_db_setserver(db, server) != 0) {
|
||||||
/* pm_errno is set by alpm_db_setserver */
|
/* pm_errno is set by alpm_db_setserver */
|
||||||
return(-1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(server);
|
free(server);
|
||||||
} else {
|
} else {
|
||||||
printf("PM_ERR_CONF_BAD_SYNTAX");
|
printf("PM_ERR_CONF_BAD_SYNTAX\n");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line[0] = '\0';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -751,7 +754,7 @@ int main(int argc, char *argv[])
|
||||||
config->configfile = strdup(CONFFILE);
|
config->configfile = strdup(CONFFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(alpm_parse_config(config->configfile, NULL, "") != 0) {
|
if(parseconfig(config->configfile) != 0) {
|
||||||
fprintf(stderr, _("error: failed to parse config (%s)\n"),
|
fprintf(stderr, _("error: failed to parse config (%s)\n"),
|
||||||
alpm_strerror(pm_errno));
|
alpm_strerror(pm_errno));
|
||||||
cleanup(1);
|
cleanup(1);
|
||||||
|
|
|
@ -150,7 +150,7 @@ static int query_search(alpm_list_t *targets)
|
||||||
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||||
|
|
||||||
/* print the package size with the output if ShowSize option set */
|
/* print the package size with the output if ShowSize option set */
|
||||||
if(alpm_option_get_showsize()) {
|
if(config->showsize) {
|
||||||
/* Convert byte size to MB */
|
/* Convert byte size to MB */
|
||||||
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
|
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
|
||||||
alpm_pkg_get_version(pkg));
|
alpm_pkg_get_version(pkg));
|
||||||
|
|
||||||
/* print the package size with the output if ShowSize option set */
|
/* print the package size with the output if ShowSize option set */
|
||||||
if(alpm_option_get_showsize()) {
|
if(config->showsize) {
|
||||||
/* Convert byte size to MB */
|
/* Convert byte size to MB */
|
||||||
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
|
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ char *strtrim(char *str)
|
||||||
{
|
{
|
||||||
char *pch = str;
|
char *pch = str;
|
||||||
|
|
||||||
if(*str == '\0') {
|
if(str == NULL || *str == '\0') {
|
||||||
/* string is empty, so we're done. */
|
/* string is empty, so we're done. */
|
||||||
return(str);
|
return(str);
|
||||||
}
|
}
|
||||||
|
@ -350,7 +350,7 @@ void display_targets(alpm_list_t *syncpkgs)
|
||||||
isize += alpm_pkg_get_isize(pkg);
|
isize += alpm_pkg_get_isize(pkg);
|
||||||
|
|
||||||
/* print the package size with the output if ShowSize option set */
|
/* print the package size with the output if ShowSize option set */
|
||||||
if(alpm_option_get_showsize()) {
|
if(config->showsize) {
|
||||||
/* Convert byte size to MB */
|
/* Convert byte size to MB */
|
||||||
mbdispsize = dispsize / (1024.0 * 1024.0);
|
mbdispsize = dispsize / (1024.0 * 1024.0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue