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>
This commit is contained in:
parent
250331a636
commit
4845207fd4
3 changed files with 62 additions and 41 deletions
|
@ -44,6 +44,9 @@ config_t *config_new(void)
|
||||||
newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
|
newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
|
||||||
/* CONFFILE is defined at compile-time */
|
/* CONFFILE is defined at compile-time */
|
||||||
newconfig->configfile = strdup(CONFFILE);
|
newconfig->configfile = strdup(CONFFILE);
|
||||||
|
newconfig->rootdir = NULL;
|
||||||
|
newconfig->dbpath = NULL;
|
||||||
|
newconfig->logfile = NULL;
|
||||||
|
|
||||||
return(newconfig);
|
return(newconfig);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +58,9 @@ int config_free(config_t *oldconfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
free(oldconfig->configfile);
|
free(oldconfig->configfile);
|
||||||
|
free(oldconfig->rootdir);
|
||||||
|
free(oldconfig->dbpath);
|
||||||
|
free(oldconfig->logfile);
|
||||||
free(oldconfig);
|
free(oldconfig);
|
||||||
oldconfig = NULL;
|
oldconfig = NULL;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include <alpm.h>
|
#include <alpm.h>
|
||||||
|
|
||||||
typedef struct __config_t {
|
typedef struct __config_t {
|
||||||
char *configfile;
|
|
||||||
unsigned short op;
|
unsigned short op;
|
||||||
unsigned short quiet;
|
unsigned short quiet;
|
||||||
unsigned short verbose;
|
unsigned short verbose;
|
||||||
|
@ -34,10 +33,14 @@ typedef struct __config_t {
|
||||||
unsigned short noconfirm;
|
unsigned short noconfirm;
|
||||||
unsigned short noprogressbar;
|
unsigned short noprogressbar;
|
||||||
unsigned short logmask;
|
unsigned short logmask;
|
||||||
/* keep track if we had paths specified on command line */
|
/* unfortunately, we have to keep track of paths both here and in the library
|
||||||
unsigned short have_root;
|
* because they can come from both the command line or config file, and we
|
||||||
unsigned short have_dbpath;
|
* need to ensure we get the order of preference right. */
|
||||||
unsigned short have_logfile;
|
char *configfile;
|
||||||
|
char *rootdir;
|
||||||
|
char *dbpath;
|
||||||
|
char *logfile;
|
||||||
|
/* TODO how to handle cachedirs? */
|
||||||
|
|
||||||
unsigned short op_q_isfile;
|
unsigned short op_q_isfile;
|
||||||
unsigned short op_q_info;
|
unsigned short op_q_info;
|
||||||
|
|
|
@ -349,12 +349,7 @@ static int parseargs(int argc, char *argv[])
|
||||||
config->flags |= PM_TRANS_FLAG_ALLDEPS;
|
config->flags |= PM_TRANS_FLAG_ALLDEPS;
|
||||||
break;
|
break;
|
||||||
case 1009:
|
case 1009:
|
||||||
if(alpm_option_set_logfile(optarg) != 0) {
|
config->logfile = strdup(optarg);
|
||||||
pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
|
|
||||||
optarg, alpm_strerrorlast());
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
config->have_logfile = 1;
|
|
||||||
break;
|
break;
|
||||||
case 1010:
|
case 1010:
|
||||||
list = strsplit(optarg, ',');
|
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 'U': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break;
|
||||||
case 'V': config->version = 1; break;
|
case 'V': config->version = 1; break;
|
||||||
case 'b':
|
case 'b':
|
||||||
if(alpm_option_set_dbpath(optarg) != 0) {
|
config->dbpath = strdup(optarg);
|
||||||
pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
|
|
||||||
optarg, alpm_strerrorlast());
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
config->have_dbpath = 1;
|
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
(config->op_s_clean)++;
|
(config->op_s_clean)++;
|
||||||
|
@ -409,12 +399,7 @@ static int parseargs(int argc, char *argv[])
|
||||||
config->quiet = 1;
|
config->quiet = 1;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
if(alpm_option_set_root(optarg) != 0) {
|
config->rootdir = strdup(optarg);
|
||||||
pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"),
|
|
||||||
optarg, alpm_strerrorlast());
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
config->have_root = 1;
|
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
config->op_s_search = 1;
|
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);
|
pm_printf(PM_LOG_DEBUG, "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) {
|
||||||
/* don't overwrite a path specified on the command line */
|
/* don't overwrite a path specified on the command line */
|
||||||
if(!config->have_dbpath) {
|
if(!config->dbpath) {
|
||||||
if(alpm_option_set_dbpath(ptr) != 0) {
|
config->dbpath = strdup(ptr);
|
||||||
pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
|
|
||||||
ptr, alpm_strerrorlast());
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
pm_printf(PM_LOG_DEBUG, "config: dbpath: %s\n", ptr);
|
pm_printf(PM_LOG_DEBUG, "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) {
|
||||||
|
@ -669,21 +650,13 @@ static int _parseconfig(const char *file, const char *givensection,
|
||||||
pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", ptr);
|
pm_printf(PM_LOG_DEBUG, "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) {
|
||||||
/* don't overwrite a path specified on the command line */
|
/* don't overwrite a path specified on the command line */
|
||||||
if(!config->have_root) {
|
if(!config->rootdir) {
|
||||||
if(alpm_option_set_root(ptr) != 0) {
|
config->rootdir = strdup(ptr);
|
||||||
pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"),
|
|
||||||
ptr, alpm_strerrorlast());
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", ptr);
|
pm_printf(PM_LOG_DEBUG, "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) {
|
||||||
if(!config->have_logfile) {
|
if(!config->logfile) {
|
||||||
if(alpm_option_set_logfile(ptr) != 0) {
|
config->logfile = strdup(ptr);
|
||||||
pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
|
|
||||||
ptr, alpm_strerrorlast());
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
pm_printf(PM_LOG_DEBUG, "config: logfile: %s\n", ptr);
|
pm_printf(PM_LOG_DEBUG, "config: logfile: %s\n", ptr);
|
||||||
}
|
}
|
||||||
} else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) {
|
} else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) {
|
||||||
|
@ -812,6 +785,45 @@ int main(int argc, char *argv[])
|
||||||
cleanup(ret);
|
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 */
|
/* add a default cachedir if one wasn't specified */
|
||||||
if(alpm_option_get_cachedirs() == NULL) {
|
if(alpm_option_get_cachedirs() == NULL) {
|
||||||
alpm_option_add_cachedir(CACHEDIR);
|
alpm_option_add_cachedir(CACHEDIR);
|
||||||
|
|
Loading…
Add table
Reference in a new issue