summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-12-02 12:56:57 -0600
committerDan McGee <dan@archlinux.org>2007-12-02 12:56:57 -0600
commit8a474e8735da5a65d338305b771742b38eab6b50 (patch)
tree8eb7e9bfa71a9b8d8d88cba6bad3a71ea06e98c3 /src
parent4845207fd4b540efd7dfcb157eaa64a1a3f10ed9 (diff)
Fixes for the ineptitude of libalpm DB registration
When a DB is "registered" in libalpm, it goes and tries to create paths and other BS which is stupid, but a pain in the butt to fix. For now, work around this terrible behavior by ensuring our paths are always set before we call any alpm_db_register function. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/pacman.c106
1 files changed, 61 insertions, 45 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 8171d84e..9cdde0c3 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -230,6 +230,61 @@ static void cleanup(int signum)
exit(signum);
}
+/** Sets all libalpm required paths 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 void setlibpaths(void)
+{
+ static int init = 0;
+ if (!init) {
+ int ret = 0;
+
+ pm_printf(PM_LOG_DEBUG, "setlibpaths() called\n");
+ 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)\n"),
+ config->rootdir, alpm_strerrorlast());
+ cleanup(ret);
+ }
+ if(!config->dbpath) {
+ snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), DBPATH);
+ config->dbpath = strdup(path);
+ }
+ if(!config->logfile) {
+ snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), LOGFILE);
+ ret = alpm_option_set_dbpath(path);
+ config->logfile = strdup(path);
+ }
+ }
+ if(config->dbpath) {
+ ret = alpm_option_set_dbpath(config->dbpath);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
+ config->dbpath, alpm_strerrorlast());
+ cleanup(ret);
+ }
+ }
+ if(config->logfile) {
+ ret = alpm_option_set_logfile(config->logfile);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
+ config->logfile, alpm_strerrorlast());
+ cleanup(ret);
+ }
+ }
+
+ /* add a default cachedir if one wasn't specified */
+ if(alpm_option_get_cachedirs() == NULL) {
+ alpm_option_add_cachedir(CACHEDIR);
+ }
+ }
+}
+
/** Parse command-line arguments for each operation.
* @param argc argc
* @param argv argv
@@ -502,8 +557,11 @@ static int _parseconfig(const char *file, const char *givensection,
file, linenum);
return(1);
}
- /* if we are not looking at the options section, register a db */
+ /* if we are not looking at the options section, register a db and also
+ * ensure we have set all of our library paths as the library is too stupid
+ * at the moment to do lazy opening of the databases */
if(strcmp(section, "options") != 0) {
+ setlibpaths();
db = alpm_db_register_sync(section);
}
} else {
@@ -696,6 +754,8 @@ static int _parseconfig(const char *file, const char *givensection,
free(section);
}
+ /* call setlibpaths here to ensure we have called it at least once */
+ setlibpaths();
pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file);
return(0);
}
@@ -785,50 +845,6 @@ int main(int argc, char *argv[])
cleanup(ret);
}
- /* Oh paths, what a mess. Now that we have parsed the command line and config
- * file, 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. */
- 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)\n"),
- config->rootdir, alpm_strerrorlast());
- cleanup(ret);
- }
- if(!config->dbpath) {
- snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), DBPATH);
- config->dbpath = strdup(path);
- }
- if(!config->logfile) {
- snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), LOGFILE);
- ret = alpm_option_set_dbpath(path);
- config->logfile = strdup(path);
- }
- }
- if(config->dbpath) {
- ret = alpm_option_set_dbpath(config->dbpath);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
- config->dbpath, alpm_strerrorlast());
- cleanup(ret);
- }
- }
- if(config->logfile) {
- ret = alpm_option_set_logfile(config->logfile);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
- config->logfile, alpm_strerrorlast());
- cleanup(ret);
- }
- }
-
- /* add a default cachedir if one wasn't specified */
- if(alpm_option_get_cachedirs() == NULL) {
- alpm_option_add_cachedir(CACHEDIR);
- }
-
#if defined(HAVE_GETEUID)
/* check if we have sufficient permission for the requested operation */
if(myuid > 0 && needs_transaction()) {