From ce186b12929aeff6d4d29e2f1cb44994d940511e Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Sat, 11 Jul 2020 02:02:42 +1000 Subject: [PATCH] Fixed issue with os.matchfiles and symlinks --- src/host/os_match.c | 5 +++-- tests/base/test_os.lua | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/host/os_match.c b/src/host/os_match.c index c07a10627a..06583c411f 100644 --- a/src/host/os_match.c +++ b/src/host/os_match.c @@ -161,9 +161,10 @@ int os_matchisfile(lua_State* L) { MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); #if defined(_DIRENT_HAVE_D_TYPE) - if (m->entry->d_type != DT_UNKNOWN) + // Dirent marks symlinks as DT_LNK, not (DT_LNK|DT_DIR). The fallback handles symlinks using stat. + if (m->entry->d_type == DT_DIR) { - lua_pushboolean(L, (m->entry->d_type == DT_DIR) == 0); + lua_pushboolean(L, 0); } else #endif diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index 95502e8600..e11807a8a5 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -124,6 +124,20 @@ test.istrue(table.contains(result, "folder/subfolder/hello.txt")) end + function suite.matchfiles_onSymbolicLink() + if os.istarget("macosx") + or os.istarget("linux") + or os.istarget("solaris") + or os.istarget("bsd") + then + os.execute("cd folder && ln -s subfolder symlinkfolder && cd ..") + local result = os.matchfiles("folder/**/*.txt") + os.execute("rm folder/symlinkfolder") + premake.modules.self_test.print(table.tostring(result)) + test.istrue(table.contains(result, "folder/symlinkfolder/hello.txt")) + end + end + -- -- os.pathsearch() tests