-/** Sets all libalpm required paths in one go. Called after the command line
+/** Sets up libalpm global stuff in one go. Called after the command line
* and inital config file parsing. Once this is complete, we can see if any
* paths were defined. If a rootdir was defined and nothing else, we want all
* of our paths to live under the rootdir that was specified. Safe to call
* multiple times (will only do anything the first time).
*/
-static int setlibpaths(void)
+static int setup_libalpm(void)
{
int ret = 0;
+ enum _pmerrno_t err;
+
+ pm_printf(PM_LOG_DEBUG, "setup_libalpm called
");
- pm_printf(PM_LOG_DEBUG, "setlibpaths() called
");
/* Configure root path first. If it is set and dbpath/logfile were not
* set, then set those as well to reside under the root. */
if(config->rootdir) {
char path[PATH_MAX];
- ret = alpm_option_set_root(config->rootdir);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting rootdir '%s' (%s)
"),
- config->rootdir, alpm_strerrorlast());
- return ret;
- }
if(!config->dbpath) {
- /* omit leading slash from our static DBPATH, root handles it */
- snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), DBPATH + 1);
+ snprintf(path, PATH_MAX, "%s/%s", config->rootdir, DBPATH + 1);
config->dbpath = strdup(path);
}
if(!config->logfile) {
- /* omit leading slash from our static LOGFILE path, root handles it */
- snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), LOGFILE + 1);
+ snprintf(path, PATH_MAX, "%s/%s", config->rootdir, LOGFILE + 1);
config->logfile = strdup(path);
}
- }
- /* Set other paths if they were configured. Note that unless rootdir
- * was left undefined, these two paths (dbpath and logfile) will have
- * been set locally above, so the if cases below will now trigger. */
- if(config->dbpath) {
- ret = alpm_option_set_dbpath(config->dbpath);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)
"),
- config->dbpath, alpm_strerrorlast());
- return ret;
+ } else {
+ config->rootdir = strdup(ROOTDIR);
+ if(!config->dbpath) {
+ config->dbpath = strdup(DBPATH);
}
}
- if(config->logfile) {
- ret = alpm_option_set_logfile(config->logfile);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)
"),
- config->logfile, alpm_strerrorlast());
- return ret;
- }
+
+ /* initialize library */
+ config->handle = alpm_initialize(config->rootdir, config->dbpath, &err);
+ if(!config->handle) {
+ pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)
"),
+ alpm_strerror(err));
+ return -1;
+ }
+
+ alpm_option_set_logcb(cb_log);
+ alpm_option_set_dlcb(cb_dl_progress);
+
+ config->logfile = config->logfile ? config->logfile : strdup(LOGFILE);
+ ret = alpm_option_set_logfile(config->logfile);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)
"),
+ config->logfile, alpm_strerrorlast());
+ return ret;
}
/* Set GnuPG's home directory. This is not relative to rootdir, even if
* rootdir is defined. Reasoning: gpgdir contains configuration data. */
- if(config->gpgdir) {
- ret = alpm_option_set_signaturedir(config->gpgdir);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)
"),
- config->gpgdir, alpm_strerrorlast());
- return ret;
- }
+ config->gpgdir = config->gpgdir ? config->gpgdir : strdup(GPGDIR);
+ ret = alpm_option_set_signaturedir(config->gpgdir);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)
"),
+ config->gpgdir, alpm_strerrorlast());
+ return ret;
}
@@ -682,8 +706,7 @@ int parseconfig(const char *file)
return ret;
}
free(section);
- /* call setlibpaths here to ensure we have called it at least once */
- if((ret = setlibpaths())) {
+ if((ret = setup_libalpm())) {
return ret;
}
/* second pass, repo section parsing */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 76c76cf..4c44bfd 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -32,6 +32,10 @@ typedef struct __config_t {
unsigned short noprogressbar;
unsigned short logmask;
unsigned short print;
+ unsigned short checkspace;
+ unsigned short usesyslog;
+ unsigned short usedelta;
+ char *arch;
char *print_format;
/* unfortunately, we have to keep track of paths both here and in the library
* because they can come from both the command line or config file, and we
@@ -41,7 +45,7 @@ typedef struct __config_t {
char *dbpath;
char *logfile;
char *gpgdir;
- /* TODO how to handle cachedirs? */
+ alpm_list_t *cachedirs;
unsigned short op_q_isfile;
unsigned short op_q_info;
@@ -64,9 +68,10 @@ typedef struct __config_t {
unsigned short op_s_upgrade;
unsigned short group;
- pmtransflag_t flags;
unsigned short noask;
unsigned int ask;
+ pmtransflag_t flags;
+ pgp_verify_t sigverify;