From 252d3854b375935195d0e94cfc74e17594edf0e9 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 24 Jan 2014 13:43:51 +0000 Subject: pkg: replace all_deps with an each_dependency() iterator --- aports/db.lua | 13 ++++++------- aports/pkg.lua | 45 ++++++++++++++++----------------------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/aports/db.lua b/aports/db.lua index 54e2459..08247f4 100644 --- a/aports/db.lua +++ b/aports/db.lua @@ -116,11 +116,11 @@ local function init_apkdb(aportsdir, repos) table.insert(pkgdb[v], a) end -- add to reverse dependencies - for v in pairs(a:all_deps()) do - if revdeps[v] == nil then - revdeps[v] = {} + for dep in a:each_dependency() do + if revdeps[dep] == nil then + revdeps[dep] = {} end - table.insert(revdeps[v], a) + table.insert(revdeps[dep], a) end end return pkgdb, revdeps @@ -139,9 +139,8 @@ function Aports:recursive_dependencies(pn) visited[pn] = true local _, p for _, p in pairs(apkdb[pn]) do - local d - for d in pairs(p:all_deps()) do - if recurs(d) then + for dep in p:each_dependency() do + if recurs(dep) then return true end end diff --git a/aports/pkg.lua b/aports/pkg.lua index 0614ec6..b5218e0 100644 --- a/aports/pkg.lua +++ b/aports/pkg.lua @@ -3,26 +3,6 @@ local M = {} local abuild = require('aports.abuild') local lfs = require('lfs') --- return a key list with makedepends and depends -function M.all_deps(p) - local m = {} - local k,v - if p == nil then - return m - end - if type(p.depends) == "table" then - for k,v in pairs(p.depends) do - m[v] = true - end - end - if type(p.makedepends) == "table" then - for k,v in pairs(p.makedepends) do - m[v] = true - end - end - return m -end - function M.is_remote(url) local _,pref for _,pref in pairs{ "^http://", "^ftp://", "^https://", ".*::.*" } do @@ -110,15 +90,22 @@ function M.arch_enabled(pkg) return pkg.arch.all or pkg.arch.noarch or pkg.arch[abuild.arch] end +function M.each_dependency(pkg) + return coroutine.wrap(function() + for _,dep in pairs(pkg.depends or {}) do + coroutine.yield(dep) + end + for _,dep in pairs(pkg.makedepends or {}) do + coroutine.yield(dep) + end + end) +end + + function M.init(pkg) - pkg.all_deps = M.all_deps - pkg.remote_sources = M.remote_sources - pkg.get_maintainer = M.get_maintainer - pkg.get_repo_name = M.get_repo_name - pkg.get_apk_file_name = M.get_apk_file_name - pkg.get_apk_file_path = M.get_apk_file_path - pkg.apk_file_exists = M.apk_file_exists - pkg.all_apks_exists = M.all_apks_exists - pkg.arch_enabled = M.arch_enabled + for k,v in pairs(M) do + pkg[k] = v + end end + return M -- cgit v1.2.3