mirror of
https://github.com/kepler155c/opus
synced 2025-05-25 18:54:09 +00:00
bulk download
This commit is contained in:
parent
ce9ffa6c3a
commit
a4145951f7
33
sys/apis/bulkget.lua
Normal file
33
sys/apis/bulkget.lua
Normal 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
|
@ -1,3 +1,4 @@
|
|||||||
|
local BulkGet = require('bulkget')
|
||||||
local Git = require('git')
|
local Git = require('git')
|
||||||
local Packages = require('packages')
|
local Packages = require('packages')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@ -53,10 +54,21 @@ local function install(name, isUpdate)
|
|||||||
|
|
||||||
local list = Git.list(manifest.repository)
|
local list = Git.list(manifest.repository)
|
||||||
local showProgress = progress(Util.size(list))
|
local showProgress = progress(Util.size(list))
|
||||||
|
|
||||||
|
local getList = { }
|
||||||
for path, entry in pairs(list) do
|
for path, entry in pairs(list) do
|
||||||
Util.download(entry.url, fs.combine(packageDir, path))
|
table.insert(getList, {
|
||||||
showProgress()
|
path = fs.combine(packageDir, path),
|
||||||
|
url = entry.url
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
BulkGet.download(getList, function(_, s, m)
|
||||||
|
if not s then
|
||||||
|
error(m)
|
||||||
|
end
|
||||||
|
showProgress()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
if action == 'list' then
|
if action == 'list' then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user