diff options
author | Dan McGee <dan@archlinux.org> | 2007-12-02 19:20:55 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-12-02 19:20:55 +0100 |
commit | 4845207fd4b540efd7dfcb157eaa64a1a3f10ed9 (patch) | |
tree | ae73be869dfae4353586a4004cd95e03bd8d02e0 /src | |
parent | 250331a636699561e1239e341f30f2adfebbcb43 (diff) | |
download | pacman-4845207fd4b540efd7dfcb157eaa64a1a3f10ed9.tar.gz pacman-4845207fd4b540efd7dfcb157eaa64a1a3f10ed9.tar.xz |
Make pacman path handling (hopefully) a bit more intuitive
I made pacman path handling a bit odd with my rootdir changes a while back
in order to increase flexability. However, it had a bit of a drawback in
that dbpath/logfile/etc. would not default to being under the rootdir if
that was the only parameter you specified in the config file or on the
command line. (Note: logfile handling was always broken due to the explicit
logfile line required in config files)
Pacman now works as follows:
if a rootdir is specified but not dbpath or logfile:
attempt to place the logfile and dbpath in their default locations under
root
if an explicit dbpath/logfile is specified:
interpret these as absolute paths, regardless of the rootdir setting
if nothing is specified:
fall back to configured defaults
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/conf.c | 6 | ||||
-rw-r--r-- | src/pacman/conf.h | 13 | ||||
-rw-r--r-- | src/pacman/pacman.c | 84 |
3 files changed, 62 insertions, 41 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 9940a133..743f8330 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -44,6 +44,9 @@ config_t *config_new(void) newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING; /* CONFFILE is defined at compile-time */ newconfig->configfile = strdup(CONFFILE); + newconfig->rootdir = NULL; + newconfig->dbpath = NULL; + newconfig->logfile = NULL; return(newconfig); } @@ -55,6 +58,9 @@ int config_free(config_t *oldconfig) } free(oldconfig->configfile); + free(oldconfig->rootdir); + free(oldconfig->dbpath); + free(oldconfig->logfile); free(oldconfig); oldconfig = NULL; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 01d69498..989fa2c8 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -24,7 +24,6 @@ #include <alpm.h> typedef struct __config_t { - char *configfile; unsigned short op; unsigned short quiet; unsigned short verbose; @@ -34,10 +33,14 @@ typedef struct __config_t { unsigned short noconfirm; unsigned short noprogressbar; unsigned short logmask; - /* keep track if we had paths specified on command line */ - unsigned short have_root; - unsigned short have_dbpath; - unsigned short have_logfile; + /* 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 + * need to ensure we get the order of preference right. */ + char *configfile; + char *rootdir; + char *dbpath; + char *logfile; + /* TODO how to handle cachedirs? */ unsigned short op_q_isfile; unsigned short op_q_info; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 19d8b2a4..8171d84e 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -349,12 +349,7 @@ static int parseargs(int argc, char *argv[]) config->flags |= PM_TRANS_FLAG_ALLDEPS; break; case 1009: - if(alpm_option_set_logfile(optarg) != 0) { - pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), - optarg, alpm_strerrorlast()); - return(1); - } - config->have_logfile = 1; + config->logfile = strdup(optarg); break; case 1010: list = strsplit(optarg, ','); @@ -372,12 +367,7 @@ static int parseargs(int argc, char *argv[]) case 'U': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break; case 'V': config->version = 1; break; case 'b': - if(alpm_option_set_dbpath(optarg) != 0) { - pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"), - optarg, alpm_strerrorlast()); - return(1); - } - config->have_dbpath = 1; + config->dbpath = strdup(optarg); break; case 'c': (config->op_s_clean)++; @@ -409,12 +399,7 @@ static int parseargs(int argc, char *argv[]) config->quiet = 1; break; case 'r': - if(alpm_option_set_root(optarg) != 0) { - pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"), - optarg, alpm_strerrorlast()); - return(1); - } - config->have_root = 1; + config->rootdir = strdup(optarg); break; case 's': config->op_s_search = 1; @@ -652,12 +637,8 @@ static int _parseconfig(const char *file, const char *givensection, pm_printf(PM_LOG_DEBUG, "config: holdpkg: %s\n", p); } else if(strcmp(key, "DBPath") == 0 || strcmp(upperkey, "DBPATH") == 0) { /* don't overwrite a path specified on the command line */ - if(!config->have_dbpath) { - if(alpm_option_set_dbpath(ptr) != 0) { - pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"), - ptr, alpm_strerrorlast()); - return(1); - } + if(!config->dbpath) { + config->dbpath = strdup(ptr); pm_printf(PM_LOG_DEBUG, "config: dbpath: %s\n", ptr); } } else if(strcmp(key, "CacheDir") == 0 || strcmp(upperkey, "CACHEDIR") == 0) { @@ -669,21 +650,13 @@ static int _parseconfig(const char *file, const char *givensection, pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", ptr); } else if(strcmp(key, "RootDir") == 0 || strcmp(upperkey, "ROOTDIR") == 0) { /* don't overwrite a path specified on the command line */ - if(!config->have_root) { - if(alpm_option_set_root(ptr) != 0) { - pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"), - ptr, alpm_strerrorlast()); - return(1); - } + if(!config->rootdir) { + config->rootdir = strdup(ptr); pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", ptr); } } else if (strcmp(key, "LogFile") == 0 || strcmp(upperkey, "LOGFILE") == 0) { - if(!config->have_logfile) { - if(alpm_option_set_logfile(ptr) != 0) { - pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), - ptr, alpm_strerrorlast()); - return(1); - } + if(!config->logfile) { + config->logfile = strdup(ptr); pm_printf(PM_LOG_DEBUG, "config: logfile: %s\n", ptr); } } else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) { @@ -812,6 +785,45 @@ 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); |