[latex3-commits] [git/LaTeX3-latex3-l3build] direxists: Simplify and fix direxists (8fa061f)
Marcel Fabian Krüger
tex at 2krueger.de
Sun Aug 15 14:59:55 CEST 2021
Repository : https://github.com/latex3/l3build
On branch : direxists
Link : https://github.com/latex3/l3build/commit/8fa061f9807d808e07c622929630eaa7662015aa
>---------------------------------------------------------------
commit 8fa061f9807d808e07c622929630eaa7662015aa
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sun Aug 15 14:59:55 2021 +0200
Simplify and fix direxists
>---------------------------------------------------------------
8fa061f9807d808e07c622929630eaa7662015aa
l3build-file-functions.lua | 46 ++++++++++++++++------------------------------
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/l3build-file-functions.lua b/l3build-file-functions.lua
index 6ca1cc6..53364bd 100644
--- a/l3build-file-functions.lua
+++ b/l3build-file-functions.lua
@@ -211,6 +211,20 @@ function cleandir(dir)
return rm(dir, "**")
end
+function direxists(dir)
+ return attributes(dir, "mode") == "directory"
+end
+
+function fileexists(file)
+ local f = open(file, "r")
+ if f ~= nil then
+ f:close()
+ return true
+ else
+ return false -- also file exits and is not readable
+ end
+end
+
-- Copy files 'quietly'
function cp(glob, source, dest)
local errorlevel
@@ -218,7 +232,7 @@ function cp(glob, source, dest)
-- p_src is a path relative to `source` whereas
-- p_cwd is the counterpart relative to the current working directory
if os_type == "windows" then
- if attributes(p.cwd, "mode") == "directory" then
+ if direxists(p.cwd) then
errorlevel = execute(
'xcopy /y /e /i "' .. unix_to_win(p.cwd) .. '" "'
.. unix_to_win(dest .. '/' .. p.src) .. '" > nul'
@@ -241,31 +255,6 @@ function cp(glob, source, dest)
return 0
end
--- OS-dependent test for a directory
-function direxists(dir)
- local errorlevel
- if os_type == "windows" then
- errorlevel =
- execute("if not exist \"" .. unix_to_win(dir) .. "\" exit 1")
- else
- errorlevel = execute("[ -d '" .. dir .. "' ]")
- end
- if errorlevel ~= 0 then
- return false
- end
- return true
-end
-
-function fileexists(file)
- local f = open(file, "r")
- if f ~= nil then
- f:close()
- return true
- else
- return false -- also file exits and is not readable
- end
-end
-
-- Generate a table containing all file names of the given glob or all files
-- if absent
function filelist(path, glob)
@@ -309,16 +298,13 @@ function tree(src_path, glob)
local function always_true()
return true
end
- local function is_dir(file)
- return attributes(file, "mode") == "directory"
- end
--- at type table<integer,tree_entry_t>
local result = { {
src = ".",
cwd = src_path,
} }
for glob_part, sep in glob:gmatch("([^/]+)(/?)/*") do
- local accept = sep == "/" and is_dir or always_true
+ local accept = sep == "/" and direxists or always_true
---Feeds the given table according to `glob_part`
--- at param p tree_entry_t path counterpart relative to the current working directory
--- at param table table
More information about the latex3-commits
mailing list.