mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-27 13:57:46 +00:00
Progress when downloading single files and when parsing remote mirrors.
This commit is contained in:
@@ -54,6 +54,8 @@ type Progress interface {
|
|||||||
ShutdownBar()
|
ShutdownBar()
|
||||||
// AddBar increments progress for progress bar
|
// AddBar increments progress for progress bar
|
||||||
AddBar(count int)
|
AddBar(count int)
|
||||||
|
// SetBar sets current position for progress bar
|
||||||
|
SetBar(count int)
|
||||||
// Printf does printf but in safe manner: not overwriting progress bar
|
// Printf does printf but in safe manner: not overwriting progress bar
|
||||||
Printf(msg string, a ...interface{})
|
Printf(msg string, a ...interface{})
|
||||||
// ColoredPrintf does printf in colored way + newline
|
// ColoredPrintf does printf in colored way + newline
|
||||||
@@ -73,4 +75,6 @@ type Downloader interface {
|
|||||||
// Shutdown stops downloader after current tasks are finished,
|
// Shutdown stops downloader after current tasks are finished,
|
||||||
// but doesn't process rest of queue
|
// but doesn't process rest of queue
|
||||||
Shutdown()
|
Shutdown()
|
||||||
|
// GetProgress returns Progress object
|
||||||
|
GetProgress() Progress
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ func (p *Progress) AddBar(count int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBar sets current position for progress bar
|
||||||
|
func (p *Progress) SetBar(count int) {
|
||||||
|
if p.bar != nil {
|
||||||
|
p.bar.Set(count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Printf does printf but in safe manner: not overwriting progress bar
|
// Printf does printf but in safe manner: not overwriting progress bar
|
||||||
func (p *Progress) Printf(msg string, a ...interface{}) {
|
func (p *Progress) Printf(msg string, a ...interface{}) {
|
||||||
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}
|
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}
|
||||||
|
|||||||
Vendored
+8
@@ -342,6 +342,9 @@ func (repo *RemoteRepo) Download(progress aptly.Progress, d aptly.Downloader, pa
|
|||||||
}
|
}
|
||||||
defer packagesFile.Close()
|
defer packagesFile.Close()
|
||||||
|
|
||||||
|
stat, _ := packagesFile.Stat()
|
||||||
|
progress.InitBar(stat.Size(), true)
|
||||||
|
|
||||||
sreader := NewControlFileReader(packagesReader)
|
sreader := NewControlFileReader(packagesReader)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -353,6 +356,9 @@ func (repo *RemoteRepo) Download(progress aptly.Progress, d aptly.Downloader, pa
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
off, _ := packagesFile.Seek(0, 1)
|
||||||
|
progress.SetBar(int(off))
|
||||||
|
|
||||||
var p *Package
|
var p *Package
|
||||||
|
|
||||||
if kind == "binary" {
|
if kind == "binary" {
|
||||||
@@ -373,6 +379,8 @@ func (repo *RemoteRepo) Download(progress aptly.Progress, d aptly.Downloader, pa
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress.ShutdownBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.Printf("Building download queue...\n")
|
progress.Printf("Building download queue...\n")
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ func (downloader *downloaderImpl) Resume() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProgress returns Progress object
|
||||||
|
func (downloader *downloaderImpl) GetProgress() aptly.Progress {
|
||||||
|
return downloader.progress
|
||||||
|
}
|
||||||
|
|
||||||
// Download starts new download task
|
// Download starts new download task
|
||||||
func (downloader *downloaderImpl) Download(url string, destination string, result chan<- error) {
|
func (downloader *downloaderImpl) Download(url string, destination string, result chan<- error) {
|
||||||
downloader.DownloadWithChecksum(url, destination, result, utils.ChecksumInfo{Size: -1}, false)
|
downloader.DownloadWithChecksum(url, destination, result, utils.ChecksumInfo{Size: -1}, false)
|
||||||
@@ -211,6 +216,10 @@ func DownloadTempWithChecksum(downloader aptly.Downloader, url string, expected
|
|||||||
|
|
||||||
tempfile := filepath.Join(tempdir, "buffer")
|
tempfile := filepath.Join(tempdir, "buffer")
|
||||||
|
|
||||||
|
if expected.Size != -1 && downloader.GetProgress() != nil {
|
||||||
|
downloader.GetProgress().InitBar(expected.Size, true)
|
||||||
|
}
|
||||||
|
|
||||||
ch := make(chan error, 1)
|
ch := make(chan error, 1)
|
||||||
downloader.DownloadWithChecksum(url, tempfile, ch, expected, ignoreMismatch)
|
downloader.DownloadWithChecksum(url, tempfile, ch, expected, ignoreMismatch)
|
||||||
|
|
||||||
@@ -219,6 +228,10 @@ func DownloadTempWithChecksum(downloader aptly.Downloader, url string, expected
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if expected.Size != -1 && downloader.GetProgress() != nil {
|
||||||
|
downloader.GetProgress().ShutdownBar()
|
||||||
|
}
|
||||||
|
|
||||||
file, err := os.Open(tempfile)
|
file, err := os.Open(tempfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -130,3 +130,8 @@ func (f *FakeDownloader) Pause() {
|
|||||||
// Resume does nothing
|
// Resume does nothing
|
||||||
func (f *FakeDownloader) Resume() {
|
func (f *FakeDownloader) Resume() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProgress returns Progress object
|
||||||
|
func (f *FakeDownloader) GetProgress() aptly.Progress {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user