From: Tobias Ulmer Date: Mon, 27 May 2013 15:38:24 +0000 (+0200) Subject: Repair, document and simplify gather_{source,result}_paths() functions X-Git-Tag: e2factory-2.3.15rc1~497 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=5e1af19c5c540d216f59b7a573d47394988f7ef7;p=e2factory.git Repair, document and simplify gather_{source,result}_paths() functions Signed-off-by: Tobias Ulmer --- diff --git a/local/e2tool.lua b/local/e2tool.lua index d70b67d..ac79ac3 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -896,30 +896,41 @@ local function read_chroot_config(info) return true end ---- gather source paths. +--- Gather source paths. +-- @param info Info table. +-- @param basedir Nil or directory from where to start scanning for more +-- sources. Only for recursion. +-- @param sources Nil or table of source paths. Only for recursion. +-- @return Table with source paths, or false on error. +-- @return Error object on failure. local function gather_source_paths(info, basedir, sources) sources = sources or {} - for dir, re in e2lib.directory(e2lib.join(info.root, e2tool.sourcedir(basedir))) do - if not dir then + + local currdir = e2lib.join(info.root, e2tool.sourcedir(basedir)) + for entry, re in e2lib.directory(currdir) do + if not entry then return false, re end - local tmp if basedir then - tmp = basedir .. "/" .. dir - else - tmp = dir + entry = e2lib.join(basedir, entry) end - local s = e2util.stat(info.root .. "/" .. e2tool.sourcedir(tmp), false) + + local fullentry = e2lib.join(info.root, e2tool.sourcedir(entry)) + local s = e2util.stat(fullentry, false) if s.type == "directory" then - if e2util.exists(e2tool.sourceconfig(tmp)) then - table.insert(sources, tmp) + if e2util.exists(e2tool.sourceconfig(entry)) then + table.insert(sources, entry) else - --try subfolder - gather_source_paths(info,tmp, sources) + -- try subfolder + local rc, re = gather_source_paths(info, entry, sources) + if not rc then + return false, re + end end end end + return sources end @@ -1076,30 +1087,41 @@ function e2tool.sourceconfig(name) return e2lib.join(e2tool.sourcedir(name), "config") end ---- gather result paths. +--- Gather result paths. +-- @param info Info table. +-- @param basedir Nil or directory from where to start scanning for more +-- results. Only for recursion. +-- @param results Nil or table of result paths. Only for recursion. +-- @return Table with result paths, or false on error. +-- @return Error object on failure. local function gather_result_paths(info, basedir, results) results = results or {} - for dir, re in e2lib.directory(e2lib.join(info.root, e2tool.resultdir(basedir))) do - if not dir then + + local currdir = e2lib.join(info.root, e2tool.resultdir(basedir)) + for entry, re in e2lib.directory(currdir) do + if not entry then return false, re end - local tmp if basedir then - tmp = basedir .. "/" .. dir - else - tmp = dir + entry = e2lib.join(basedir, entry) end - local s = e2util.stat(info.root .. "/" .. e2tool.resultdir(tmp), false) + + local fullentry = e2lib.join(info.root, e2tool.resultdir(entry)) + local s = e2util.stat(fullentry, false) if s.type == "directory" then - if e2util.exists(e2tool.resultconfig(tmp)) then - table.insert(results, tmp) + if e2util.exists(e2tool.resultconfig(entry)) then + table.insert(results, entry) else - --try subfolder - gather_result_paths(info,tmp, results) + -- try subfolder + local rc, re = gather_result_paths(info, entry, results) + if not rc then + return false, re + end end end end + return results end