]> git.e2factory.org Git - e2factory.git/commitdiff
Add error checking to directory() loops
authorTobias Ulmer <tu@emlix.com>
Wed, 15 May 2013 18:03:13 +0000 (20:03 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 13:58:55 +0000 (14:58 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/plugin.lua
local/e2-cf.lua
local/e2build.lua
local/e2tool.lua

index e8fb1ba3f339b71b0370ffe0295fc6fdb6b3deec..4a5b22cbc43abc25e542fe002d5f4bb1df185d65 100644 (file)
@@ -142,7 +142,11 @@ function plugin.load_plugins(dir, ctx)
     e2lib.logf(4, "loading plugins from: %s", dir)
 
     local pfn = {}
-    for fn in e2lib.directory(dir) do
+    for fn, re in e2lib.directory(dir) do
+        if not fn then
+            return false, e:cat(re)
+        end
+
         table.insert(pfn, fn)
     end
 
index 669afeb5b7d0b58a49114f7f3d853a4dace73afd..371e20a55f46640f278e893e67fec042a9ae8a8c 100644 (file)
@@ -104,7 +104,12 @@ local function shadow_config_down(src_res, pathname)
         return false, err.new("config in %s would be shadowed", cfdir)
     end
 
-    for f in e2lib.directory(cfdir, false, true) do
+    local re
+    for f, re in e2lib.directory(cfdir, false, true) do
+        if not f then
+            return false, re
+        end
+
         if e2lib.isdir(e2lib.join(cfdir, f)) then
             return shadow_config_down(src_res, e2lib.join(pathname, f))
         end
index 23b87a697fe9356b278c2b5baa35b72584ad0599..58172548a83e4c2a84c1d86d5b1de64bf037d98c 100644 (file)
@@ -538,7 +538,11 @@ function e2build.unpack_result(info, r, dep, destdir)
     if not rc then
         return false, e:cat(re)
     end
-    for f in e2lib.directory(".") do
+    for f, re in e2lib.directory(".") do
+        if not f then
+            return false, e:cat(re)
+        end
+
         rc, re = e2lib.mv(f, destdir)
         if not rc then
             return false, e:cat(re)
@@ -572,7 +576,11 @@ local function write_build_driver(info, r, destdir)
     bd=bd..string.format("source %s/env/builtin\n", res.build_config.Tc)
     bd=bd..string.format("source %s/env/env\n", res.build_config.Tc)
     local brc_noinit = bd
-    for x in e2lib.directory(info.root .. "/proj/init") do
+    for x, re in e2lib.directory(info.root .. "/proj/init") do
+        if not x then
+            return false, e:cat(re)
+        end
+
         if not e2lib.is_backup_file(x) then
             bd=bd..string.format("source %s/init/%s\n", res.build_config.Tc, x)
         end
@@ -701,7 +709,11 @@ local function sources(info, r, return_flags)
         local res = info.results[r]
         local rc, re
         local e = err.new("installing init files")
-        for x in e2lib.directory(info.root .. "/proj/init") do
+        for x, re in e2lib.directory(info.root .. "/proj/init") do
+            if not x then
+                return false, e:cat(re)
+            end
+
             if not e2lib.is_backup_file(x) then
                 local location = string.format("proj/init/%s", x)
                 local abslocation = string.format("%s/%s", info.root, location)
@@ -820,7 +832,12 @@ local function deploy(info, r, return_flags)
         return true
     end
     local files = {}
-    for f in e2lib.directory("result/files") do
+    local re
+    for f, re in e2lib.directory("result/files") do
+        if not f then
+            return false, re
+        end
+
         table.insert(files, string.format("files/%s", f))
     end
     table.insert(files, "checksums")
index 35f016ee08b42e0305cafbb898f1f01037a3277a..f8c5a94c8aa2a418384d2dc7de4364786e02edf1 100644 (file)
@@ -903,7 +903,11 @@ end
 --- gather source paths.
 local function gather_source_paths(info, basedir, sources)
     sources = sources or {}
-    for dir in e2lib.directory(info.root .. "/" .. e2tool.sourcedir(basedir)) do
+    for dir, re in e2lib.directory(e2lib.join(info.root, e2tool.sourcedir(basedir))) do
+        if not dir then
+            return false, re
+        end
+
         local tmp
         if basedir then
             tmp = basedir .. "/" .. dir
@@ -977,7 +981,12 @@ local function load_source_config(info)
     local e = err.new("error loading source configuration")
     info.sources = {}
 
-    for _,src in ipairs(gather_source_paths(info)) do
+    local sources, re = gather_source_paths(info)
+    if not sources then
+        return false, e:cat(re)
+    end
+
+    for _,src in ipairs(sources) do
         local list, re
         local path = e2tool.sourceconfig(src)
         local types = { "e2source", }
@@ -1074,7 +1083,11 @@ end
 --- gather result paths.
 local function gather_result_paths(info, basedir, results)
     results = results or {}
-    for dir in e2lib.directory(info.root .. "/" .. e2tool.resultdir(basedir)) do
+    for dir, re in e2lib.directory(e2lib.join(info.root, e2tool.resultdir(basedir))) do
+        if not dir then
+            return false, re
+        end
+
         local tmp
         if basedir then
             tmp = basedir .. "/" .. dir
@@ -1099,7 +1112,12 @@ local function load_result_config(info)
     local e = err.new("error loading result configuration")
     info.results = {}
 
-    for _,res in ipairs(gather_result_paths(info)) do
+    local results, re = gather_result_paths(info)
+    if not results then
+        return false, e:cat(re)
+    end
+
+    for _,res in ipairs(results) do
         local list, re
         local path = e2tool.resultconfig(res)
         local types = { "e2result", }
@@ -1860,7 +1878,11 @@ local function projid(info)
     end
     -- catch proj/init/*
     local hc = hash.hash_start()
-    for f in e2lib.directory(info.root .. "/proj/init") do
+    for f, re in e2lib.directory(e2lib.join(info.root, "proj/init")) do
+        if not f then
+            return false, re
+        end
+
         if not e2lib.is_backup_file(f) then
             local location = string.format("proj/init/%s",
             e2lib.basename(f))