Avoid double slash when explicitly passing --root or --rootdir
Passing a path with a trailing slash to --root or --rootdir can lead to a double slash at the start of paths. e.g. $ pacman --root / -v 2>1 | grep " //" Log File : //var/log/pacman.log In MSYS2, paths starting with // will hit the network and fail. Avoid this be explicitly stripping the trailing / from paths passed to these flags. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
76b140c72a
commit
34611a6643
1 changed files with 9 additions and 2 deletions
|
@ -1136,15 +1136,22 @@ int setdefaults(config_t *c)
|
||||||
#define SETDEFAULT(opt, val) if(!opt) { opt = val; if(!opt) { return -1; } }
|
#define SETDEFAULT(opt, val) if(!opt) { opt = val; if(!opt) { return -1; } }
|
||||||
|
|
||||||
if(c->rootdir) {
|
if(c->rootdir) {
|
||||||
|
char* rootdir = strdup(c->rootdir);
|
||||||
|
int rootdir_len = strlen(rootdir);
|
||||||
|
/* This removes trailing slashes from the root directory */
|
||||||
|
if(rootdir[rootdir_len-1] == '/'){
|
||||||
|
rootdir[rootdir_len-1] = '\0';
|
||||||
|
}
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
if(!c->dbpath) {
|
if(!c->dbpath) {
|
||||||
snprintf(path, PATH_MAX, "%s/%s", c->rootdir, &DBPATH[1]);
|
snprintf(path, PATH_MAX, "%s/%s", rootdir, &DBPATH[1]);
|
||||||
SETDEFAULT(c->dbpath, strdup(path));
|
SETDEFAULT(c->dbpath, strdup(path));
|
||||||
}
|
}
|
||||||
if(!c->logfile) {
|
if(!c->logfile) {
|
||||||
snprintf(path, PATH_MAX, "%s/%s", c->rootdir, &LOGFILE[1]);
|
snprintf(path, PATH_MAX, "%s/%s", rootdir, &LOGFILE[1]);
|
||||||
SETDEFAULT(c->logfile, strdup(path));
|
SETDEFAULT(c->logfile, strdup(path));
|
||||||
}
|
}
|
||||||
|
free(rootdir);
|
||||||
} else {
|
} else {
|
||||||
SETDEFAULT(c->rootdir, strdup(ROOTDIR));
|
SETDEFAULT(c->rootdir, strdup(ROOTDIR));
|
||||||
SETDEFAULT(c->dbpath, strdup(DBPATH));
|
SETDEFAULT(c->dbpath, strdup(DBPATH));
|
||||||
|
|
Loading…
Add table
Reference in a new issue