Fixed os.isdir to work with Windows symbolic links.

This commit is contained in:
triton 2015-11-24 04:08:09 +00:00
parent 1f8c426fdb
commit 5a6bb85027

View File

@ -8,20 +8,35 @@
#include <sys/stat.h>
#include "premake.h"
#ifdef _WIN32
#include <Windows.h>
#endif
int os_isdir(lua_State* L)
{
struct stat buf;
const char* path = luaL_checkstring(L, 1);
#ifdef _WIN32
int attr;
#endif
/* empty path is equivalent to ".", must be true */
if (strlen(path) == 0)
{
lua_pushboolean(L, 1);
}
#ifdef _WIN32
// Use Windows-specific GetFileAttributes since it deals with symbolic links.
else if ((attr = GetFileAttributes(path)) != INVALID_FILE_ATTRIBUTES)
{
int isdir = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
lua_pushboolean(L, isdir);
}
#endif
else if (stat(path, &buf) == 0)
{
lua_pushboolean(L, buf.st_mode & S_IFDIR);
int isdir = (buf.st_mode & S_IFDIR) != 0;
lua_pushboolean(L, isdir);
}
else
{