- D_AddFile(): Check the existence of the file before enumerating entire directory to find it as input might be coming in correctly.

This commit is contained in:
Mitchell Richters 2020-10-15 06:50:41 +11:00
parent ec5762f024
commit 38c0af4d34

View file

@ -42,6 +42,7 @@
#include <unistd.h> #include <unistd.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <sys/stat.h>
#include "cmdlib.h" #include "cmdlib.h"
@ -204,15 +205,20 @@ bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int posi
return false; return false;
} }
#ifdef __unix__ #ifdef __unix__
// Test case sensitively, pure lowercase and pure uppercase. // Confirm file exists in filesystem.
struct stat info;
bool found = stat(file, &info) == 0;
if (!found)
{
// File not found, so split file into path and filename so we can enumerate the path for the file.
FString fullpath = file; FString fullpath = file;
auto lastindex = fullpath.LastIndexOf("/"); auto lastindex = fullpath.LastIndexOf("/");
FString basepath = fullpath.Left(lastindex); FString basepath = fullpath.Left(lastindex);
FString filename = fullpath.Right(fullpath.Len() - lastindex - 1); FString filename = fullpath.Right(fullpath.Len() - lastindex - 1);
// Proceed only if locating a file (i.e. `file` isn't a path to just a directory.)
if (filename.IsNotEmpty()) if (filename.IsNotEmpty())
{ {
bool found = false;
DIR *d; DIR *d;
struct dirent *dir; struct dirent *dir;
d = opendir(basepath.GetChars()); d = opendir(basepath.GetChars());
@ -232,7 +238,7 @@ bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int posi
closedir(d); closedir(d);
if (!found) if (!found)
{ {
Printf("Can't find file '%s'\n", filename.GetChars()); Printf("Can't find file '%s' in '%s'\n", filename.GetChars(), basepath.GetChars());
return false; return false;
} }
} }
@ -242,6 +248,7 @@ bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int posi
return false; return false;
} }
} }
}
#endif #endif
if (check && !DirEntryExists(file)) if (check && !DirEntryExists(file))