mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Rework downloading: first build queue, then use it to download.
This commit is contained in:
25
debian/remote.go
vendored
25
debian/remote.go
vendored
@@ -190,39 +190,46 @@ func (repo *RemoteRepo) Download(d utils.Downloader, packageCollection *PackageC
|
|||||||
|
|
||||||
fmt.Printf("Building download queue...\n")
|
fmt.Printf("Building download queue...\n")
|
||||||
|
|
||||||
// Download all package files
|
// Build download queue
|
||||||
ch := make(chan error, list.Len())
|
queued := make(map[string]PackageDownloadTask, list.Len())
|
||||||
queued := make(map[string]bool, 1024)
|
|
||||||
count := 0
|
count := 0
|
||||||
downloadSize := int64(0)
|
downloadSize := int64(0)
|
||||||
|
|
||||||
err = list.ForEach(func(p *Package) error {
|
err = list.ForEach(func(p *Package) error {
|
||||||
list, err := p.DownloadList(packageRepo)
|
list, err := p.DownloadList(packageRepo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, task := range list {
|
for _, task := range list {
|
||||||
key := task.RepoURI + "-" + task.DestinationPath
|
key := task.RepoURI + "-" + task.DestinationPath
|
||||||
_, found := queued[key]
|
_, found := queued[key]
|
||||||
if !found {
|
if !found {
|
||||||
d.Download(repo.PackageURL(task.RepoURI).String(), task.DestinationPath, ch)
|
|
||||||
count++
|
count++
|
||||||
downloadSize += task.Size
|
downloadSize += task.Size
|
||||||
} else {
|
queued[key] = task
|
||||||
queued[key] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to download packages: %s", err)
|
return fmt.Errorf("unable to build download queue: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Download queue: %d items, %.2f GiB size\n", count, float64(downloadSize)/(1024.0*1024.0*1024.0))
|
fmt.Printf("Download queue: %d items, %.2f GiB size\n", count, float64(downloadSize)/(1024.0*1024.0*1024.0))
|
||||||
|
|
||||||
errors := make([]string, 0)
|
// Download all package files
|
||||||
|
ch := make(chan error, len(queued))
|
||||||
|
|
||||||
|
for _, task := range queued {
|
||||||
|
d.Download(repo.PackageURL(task.RepoURI).String(), task.DestinationPath, ch)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for all downloads to finish
|
// Wait for all downloads to finish
|
||||||
|
errors := make([]string, 0)
|
||||||
|
|
||||||
for count > 0 {
|
for count > 0 {
|
||||||
err = <-ch
|
err = <-ch
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user