mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-27 13:57:46 +00:00
Fix issues with progress == nil causing panics
Part of PR #459 This prepares for more methods to be exposed via the API.
This commit is contained in:
committed by
Oliver Sauder
parent
98e75f6d97
commit
769e984ef4
+14
-6
@@ -505,8 +505,10 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
|
|||||||
}
|
}
|
||||||
defer packagesFile.Close()
|
defer packagesFile.Close()
|
||||||
|
|
||||||
stat, _ := packagesFile.Stat()
|
if progress != nil {
|
||||||
progress.InitBar(stat.Size(), true)
|
stat, _ := packagesFile.Stat()
|
||||||
|
progress.InitBar(stat.Size(), true)
|
||||||
|
}
|
||||||
|
|
||||||
sreader := NewControlFileReader(packagesReader, false, isInstaller)
|
sreader := NewControlFileReader(packagesReader, false, isInstaller)
|
||||||
|
|
||||||
@@ -519,8 +521,10 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
off, _ := packagesFile.Seek(0, 1)
|
if progress != nil {
|
||||||
progress.SetBar(int(off))
|
off, _ := packagesFile.Seek(0, 1)
|
||||||
|
progress.SetBar(int(off))
|
||||||
|
}
|
||||||
|
|
||||||
var p *Package
|
var p *Package
|
||||||
|
|
||||||
@@ -541,13 +545,17 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
|
|||||||
}
|
}
|
||||||
err = repo.packageList.Add(p)
|
err = repo.packageList.Add(p)
|
||||||
if _, ok := err.(*PackageConflictError); ok {
|
if _, ok := err.(*PackageConflictError); ok {
|
||||||
progress.ColoredPrintf("@y[!]@| @!skipping package %s: duplicate in packages index@|", p)
|
if progress != nil {
|
||||||
|
progress.ColoredPrintf("@y[!]@| @!skipping package %s: duplicate in packages index@|", p)
|
||||||
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.ShutdownBar()
|
if progress != nil {
|
||||||
|
progress.ShutdownBar()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+8
-2
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -53,11 +54,16 @@ func NewDownloader(downLimit int64, maxTries int, progress aptly.Progress) aptly
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressWriter := io.Writer(progress)
|
||||||
|
if progress == nil {
|
||||||
|
progressWriter = ioutil.Discard
|
||||||
|
}
|
||||||
|
|
||||||
downloader.client.CheckRedirect = downloader.checkRedirect
|
downloader.client.CheckRedirect = downloader.checkRedirect
|
||||||
if downLimit > 0 {
|
if downLimit > 0 {
|
||||||
downloader.aggWriter = flowrate.NewWriter(progress, downLimit)
|
downloader.aggWriter = flowrate.NewWriter(progressWriter, downLimit)
|
||||||
} else {
|
} else {
|
||||||
downloader.aggWriter = progress
|
downloader.aggWriter = progressWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
return downloader
|
return downloader
|
||||||
|
|||||||
Reference in New Issue
Block a user