Fix issue #20 - can now find files with a dot prefix; directories are still ignored

This commit is contained in:
Jason Perkins 2014-04-24 10:49:06 -04:00
parent aef8313299
commit a672ec416a
3 changed files with 21 additions and 15 deletions

View File

@ -1,7 +1,7 @@
--
-- os.lua
-- Additions to the OS namespace.
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
--
@ -270,7 +270,9 @@
while os.matchnext(m) do
if not os.matchisfile(m) then
local dirname = os.matchname(m)
matchwalker(path.join(basedir, dirname))
if (not dirname:startswith(".")) then
matchwalker(path.join(basedir, dirname))
end
end
end
os.matchdone(m)

View File

@ -1,7 +1,7 @@
/**
* \file os_match.c
* \brief Match files and directories.
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
* \author Copyright (c) 2002-2014 Jason Perkins and the Premake project
*/
#include <stdlib.h>
@ -57,9 +57,10 @@ int os_matchisfile(lua_State* L)
int os_matchnext(lua_State* L)
{
MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1);
if (m->handle == INVALID_HANDLE_VALUE)
if (m->handle == INVALID_HANDLE_VALUE) {
return 0;
}
while (m) /* loop forever */
{
if (!m->is_first)
@ -69,11 +70,8 @@ int os_matchnext(lua_State* L)
}
m->is_first = 0;
if (m->entry.cFileName[0] != '.')
{
lua_pushboolean(L, 1);
return 1;
}
lua_pushboolean(L, 1);
return 1;
}
return 0;
@ -155,21 +153,22 @@ int os_matchisfile(lua_State* L)
lua_pushboolean(L, S_ISREG(info.st_mode));
return 1;
}
return 0;
}
int os_matchnext(lua_State* L)
{
MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1);
if (m->handle == NULL)
if (m->handle == NULL) {
return 0;
}
m->entry = readdir(m->handle);
while (m->entry != NULL)
{
const char* name = m->entry->d_name;
if (name[0] != '.' && fnmatch(m->mask, name, 0) == 0)
if (fnmatch(m->mask, name, 0) == 0)
{
lua_pushboolean(L, 1);
return 1;

View File

@ -1,7 +1,7 @@
--
-- tests/base/test_os.lua
-- Automated test suite for the new OS functions.
-- Copyright (c) 2008-2013 Jason Perkins and the Premake project
-- Copyright (c) 2008-2014 Jason Perkins and the Premake project
--
local suite = test.declare("base_os")
@ -82,6 +82,11 @@
test.istrue(table.contains(result, "folder/ok.lua"))
end
function suite.matchfiles_OnDottedFile()
local result = os.matchfiles("../.*")
test.istrue(table.contains(result, "../.hgignore"))
end
--