redbean: allow symlinks for -D path (#372)

Previously ProgramDirectory called isdirectory which returns false for
symlinks. instead just check directory with stat, and allow user to pass
`-D /tmp/foo/`, where /tmp/foo might be a symlink.
This commit is contained in:
Nick Owens 2022-03-21 05:43:49 -07:00 committed by GitHub
parent 5e8ae2d5bc
commit f78f2fcac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -938,12 +938,16 @@ static bool HasString(struct Strings *l, const char *s, size_t n) {
static void ProgramDirectory(const char *path) {
char *s;
size_t n;
struct stat st;
if(stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
DIEF("(cfg) error: not a directory: %`'s", path);
}
s = strdup(path);
n = strlen(s);
while (n && (s[n - 1] == '/' || s[n - 1] == '\\')) s[--n] = 0;
if (!n || !isdirectory(s)) {
DIEF("(cfg) error: not a directory: %`'s", s);
}
INFOF("(cfg) program directory: %s", s);
AddString(&stagedirs, s, n);
}