From f13c4422e4b1b42bda0d18f55f190f1b220683f8 Mon Sep 17 00:00:00 2001 From: mischief Date: Sun, 20 Mar 2022 13:27:13 -0700 Subject: [PATCH] redbean: allow symlinks for -D path 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. --- tool/net/redbean.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 94349998e..ec6a1eecb 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -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); }