Don't auto-create directories that will be empty

Sun, 06 Sep 2020 22:12:52 +0300

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 06 Sep 2020 22:12:52 +0300
changeset 35
2f927eae429b
parent 34
4c7122a505d4
child 36
6e3c3dd86b2f

Don't auto-create directories that will be empty

handlers/copy.lua file | annotate | diff | comparison | revisions
lgen.lua file | annotate | diff | comparison | revisions
luaext.lua file | annotate | diff | comparison | revisions
mypath.lua file | annotate | diff | comparison | revisions
tuple.lua file | annotate | diff | comparison | revisions
--- a/handlers/copy.lua	Sun Sep 06 21:24:39 2020 +0300
+++ b/handlers/copy.lua	Sun Sep 06 22:12:52 2020 +0300
@@ -2,6 +2,7 @@
 --@module handlers.copy
 
 local path=require("mypath")
+local lfs=require("lfs")
 
 local handlers_copy={}
 
--- a/lgen.lua	Sun Sep 06 21:24:39 2020 +0300
+++ b/lgen.lua	Sun Sep 06 22:12:52 2020 +0300
@@ -56,7 +56,7 @@
 scan.map(hierarchy, function(f) handlers.phase2(f, env) end,
                     function(d) 
                         --log.log("Make path "..path.join(dst, d).."\n")
-                        lfs.mkdir(path.join(dst, d))
+                        --lfs.mkdir(path.join(dst, d))
                     end)
 --print('Phase 3...')
 --scan.map(hierarchy, function(f) handlers.phase3(f, env) end)
--- a/luaext.lua	Sun Sep 06 21:24:39 2020 +0300
+++ b/luaext.lua	Sun Sep 06 22:12:52 2020 +0300
@@ -6,6 +6,8 @@
 -- See the included file LICENSE for details.
 --
 
+local lfs=require("lfs")
+local path=require("mypath")
 
 --DOC
 -- Make \var{str} shell-safe.
@@ -87,8 +89,15 @@
     end
 end
 
-function io.openX(file, ...)
-    local f, err = io.open(file, ...)
+function io.openX(file, mode)
+    if mode=='w' then
+        local dn = path.dirname(file)
+        if not lfs.attributes(dn) then
+            print("Ensure directory", dn)
+            lfs.mkdir(dn)
+        end
+    end
+    local f, err = io.open(file, mode)
     if not f then
         error(file..": "..err)
     end
--- a/mypath.lua	Sun Sep 06 21:24:39 2020 +0300
+++ b/mypath.lua	Sun Sep 06 22:12:52 2020 +0300
@@ -28,7 +28,7 @@
 end
 
 function path.dirname(p)
-    return tuple.fst(dirbasename(p))
+    return tuple.fst(path.dirbasename(p))
 end
 
 function path.dirname_slash(p)
--- a/tuple.lua	Sun Sep 06 21:24:39 2020 +0300
+++ b/tuple.lua	Sun Sep 06 22:12:52 2020 +0300
@@ -2,7 +2,7 @@
 --@module tuple
 local tuple={}
 
-function tuplefst(a, b)
+function tuple.fst(a, b)
     return a
 end
 

mercurial