diff options
Diffstat (limited to 'tex/context/base/mkiv/l-file.lua')
-rw-r--r-- | tex/context/base/mkiv/l-file.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/l-file.lua b/tex/context/base/mkiv/l-file.lua index f2a27ad18..5fec0040f 100644 --- a/tex/context/base/mkiv/l-file.lua +++ b/tex/context/base/mkiv/l-file.lua @@ -96,6 +96,10 @@ function lfs.isfile(name) return attributes(name,"mode") == "file" end +function lfs.isfound(name) + return attributes(name,"mode") == "file" and name or nil +end + local colon = P(":") local period = P(".") local periods = P("..") @@ -699,3 +703,25 @@ function lfs.mkdirs(path) lfs.mkdir(full) end end + +-- here is oen i ran into when messign around with xavante code (keppler project) +-- where it's called in_base .. no gain in using lpeg here + +function file.withinbase(path) -- don't go beyond root + local l = 0 + if not find(path,"^/") then + path = "/" .. path + end + for dir in gmatch(path,"/([^/]+)") do + if dir == ".." then + l = l - 1 + elseif dir ~= "." then + l = l + 1 + end + if l < 0 then + return false + end + end + return true +end + |