diff --git a/sys/apis/bulkget.lua b/sys/apis/bulkget.lua new file mode 100644 index 0000000..1135847 --- /dev/null +++ b/sys/apis/bulkget.lua @@ -0,0 +1,33 @@ +local Util = require('util') + +local parallel = _G.parallel + +local BulkGet = { } + +function BulkGet.download(list, callback) + local t = { } + local failed = false + + for _ = 1, 5 do + table.insert(t, function() + while true do + local entry = table.remove(list) + if not entry then + break + end + local s, m = Util.download(entry.url, entry.path) + if not s then + failed = true + end + callback(entry, s, m) + if failed then + break + end + end + end) + end + + parallel.waitForAll(table.unpack(t)) +end + +return BulkGet diff --git a/sys/apps/package.lua b/sys/apps/package.lua index 45016cd..f604e3c 100644 --- a/sys/apps/package.lua +++ b/sys/apps/package.lua @@ -1,3 +1,4 @@ +local BulkGet = require('bulkget') local Git = require('git') local Packages = require('packages') local Util = require('util') @@ -53,10 +54,21 @@ local function install(name, isUpdate) local list = Git.list(manifest.repository) local showProgress = progress(Util.size(list)) + + local getList = { } for path, entry in pairs(list) do - Util.download(entry.url, fs.combine(packageDir, path)) - showProgress() + table.insert(getList, { + path = fs.combine(packageDir, path), + url = entry.url + }) end + + BulkGet.download(getList, function(_, s, m) + if not s then + error(m) + end + showProgress() + end) end if action == 'list' then