diff --git a/src/base/os.lua b/src/base/os.lua index 0b175bb1..0fb493d4 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -250,24 +250,11 @@ -- directory name, "**" to recurse into subdirectories. -- @param matchFiles -- True to match against files, false to match directories. --- @param excludeDirs --- Lua Pattern. --- If any encountered dir matches this pattern, it will be discarded (both from results and from recursive decent). --- If it is nil, it will be set to "%..*", to keep backward compatibility. --- To make it match all dirs, you need to pass un-matchable pattern; we use "a^" for this internally. --- @param excludeFiles --- Lua Pattern. --- If any encountered file matches this pattern, it will be discarded from results. --- If it is nil, it will be set to "a^" to match no files. -- @return -- A table containing the matched file or directory names. --- - function os.match(mask, matchFiles, excludeDirs, excludeFiles) - -- patch up exclude masks to default values - excludeDirs = excludeDirs and excludeDirs or "%..*" - excludeFiles = excludeFiles and excludeFiles or "a^" - + function os.match(mask, matchFiles) -- Strip any extraneous weirdness from the mask to ensure a good -- match against the paths returned by the OS. I don't know if I've -- caught all the possibilities here yet; will add more as I go. @@ -304,7 +291,7 @@ local isfile = os.matchisfile(m) if (matchFiles and isfile) or (not matchFiles and not isfile) then local fname = os.matchname(m) - if (isfile and not fname:match(excludeFiles)) or (not isfile and not fname:match(excludeDirs)) then + if isfile or not fname:startswith(".") then fname = path.join(basedir, fname) if fname:match(mask) == fname then table.insert(result, fname) @@ -320,8 +307,7 @@ while os.matchnext(m) do if not os.matchisfile(m) then local dirname = os.matchname(m) - -- always exclude phony dirs: . and .. - if not (dirname == "." or dirname == ".." or dirname:match(excludeDirs)) then + if (not dirname:startswith(".")) then matchwalker(path.join(basedir, dirname)) end end @@ -346,7 +332,7 @@ --- function os.matchdirs(mask) - return os.match(mask, false, "%..*", nil) + return os.match(mask, false) end @@ -361,7 +347,7 @@ --- function os.matchfiles(mask) - return os.match(mask, true, "%..*", nil) + return os.match(mask, true) end @@ -454,12 +440,10 @@ local builtin_rmdir = os.rmdir function os.rmdir(p) - -- recursively remove subdirectories: exclude no dirs apart builtin . and .. - local dirs = os.match(p .. "/*", false, "a^", nil) + -- recursively remove subdirectories + local dirs = os.matchdirs(p .. "/*") for _, dname in ipairs(dirs) do - if not (dname:endswith("/.") or dname:endswith("/..")) then - os.rmdir(dname) - end + os.rmdir(dname) end -- remove any files diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index 818679c1..ed0c319a 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -78,9 +78,8 @@ end function suite.matchfiles_SkipsDotDirs_OnRecursive() - local result = os.matchfiles("../**.lua*") - test.istrue(table.contains(result, "../src/_manifest.lua")) - test.isfalse(table.contains(result, "../.hg/store/data/scripts/test.lua.i")) + local result = os.matchfiles("**.lua") + test.isfalse(table.contains(result, ".svn/text-base/testfx.lua.svn-base")) end function suite.matchfiles_OnSubfolderMatch() @@ -112,31 +111,6 @@ --- --- os.match() tests for exclude patterns --- - - function suite.match_DirsCustomExcludeDirs() - local result = os.match("*", false, "a.*") - test.istrue(table.contains(result, "..")) - test.isfalse(table.contains(result, "actions")) - test.isfalse(table.contains(result, "api")) - end - - function suite.match_FilesCustomExcludeDirs() - local result = os.match("../**.lua*", true, "src") - test.isfalse(table.contains(result, "../src/_manifest.lua")) - test.istrue(table.contains(result, "../.hg/store/data/scripts/test.lua.i")) - end - - function suite.match_FilesCustomExcludeFiles() - local result = os.match("**.lua", true, nil, "ok.*") - test.istrue(table.contains(result, "folder/premake5.lua")) - test.isfalse(table.contains(result, "folder/ok.lua")) - end - - - -- -- os.pathsearch() tests -- @@ -198,18 +172,3 @@ } test.isequal("test a b", os.translateCommands("{COPY} a b", "test")) end - - - --- --- os.mkdir() and os.rmdir() tests --- - - function suite.mkdirrmdir_WorksWithDottesDirs() - os.mkdir("__TEST/.TEST") - test.istrue(table.contains(os.matchdirs("*"), "__TEST")) - test.istrue(table.contains(os.match("**", false, "a^"), "__TEST/.TEST")) - os.rmdir("__TEST") - test.isfalse(table.contains(os.matchdirs("*"), "__TEST")) - test.isfalse(table.contains(os.match("**", false, "a^"), "__TEST/.TEST")) - end