bulk download

This commit is contained in:
kepler155c@gmail.com 2019-03-06 16:56:41 -05:00
parent ce9ffa6c3a
commit a4145951f7
2 changed files with 47 additions and 2 deletions

33
sys/apis/bulkget.lua Normal file
View File

@ -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

View File

@ -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