From d06f923066b94f9fb71aeaa681bb8e0d068213b7 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 20 Nov 2023 16:10:02 +0300 Subject: [PATCH] Fix filesearch trying to open file symlinks as directory --- src/filesrch.c | 8 +++++++- src/w_wad.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/filesrch.c b/src/filesrch.c index 2e54929bb..e493f8786 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -401,8 +401,14 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want if (lstat(searchpath,&fsstat) == 0 && S_ISDIR(fsstat.st_mode)) dent->d_type = DT_DIR; else if (lstat(searchpath,&fsstat) == 0 && S_ISLNK(fsstat.st_mode)) - dent->d_type = DT_LNK; + dent->d_type = DT_LNK; + // Symlinks aren't always directory symlinks. Dunno if this would resolve recursive + // symlinks, but i think stat already does that + if (dent->d_type == DT_LNK && stat(searchpath,&fsstat) == 0 && !S_ISDIR(fsstat.st_mode)) + { + dent->d_type = DT_UNKNOWN; + } // Linux and FreeBSD has a special field for file type on dirent, so use that to speed up lookups. // FIXME: should we also follow symlinks? diff --git a/src/w_wad.c b/src/w_wad.c index 0914ec963..950b80d9a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -202,7 +202,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors) // If findfile finds the file, the full path will be returned // in filenamebuf == *filename. - if (findfile(filenamebuf, NULL, true)) + if (findfile(filenamebuf, NULL, true) == FS_FOUND) { if ((handle = fopen_utf8(*filename, "rb")) == NULL) {