Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with progress == nil causing panics #871

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions deb/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
}
defer packagesFile.Close()

stat, _ := packagesFile.Stat()
progress.InitBar(stat.Size(), true)
if progress != nil {
stat, _ := packagesFile.Stat()
progress.InitBar(stat.Size(), true)
}

sreader := NewControlFileReader(packagesReader, false, isInstaller)

Expand All @@ -519,8 +521,10 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
break
}

off, _ := packagesFile.Seek(0, 1)
progress.SetBar(int(off))
if progress != nil {
off, _ := packagesFile.Seek(0, 1)
progress.SetBar(int(off))
}

var p *Package

Expand All @@ -541,13 +545,17 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
}
err = repo.packageList.Add(p)
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 {
return err
}
}

progress.ShutdownBar()
if progress != nil {
progress.ShutdownBar()
}
}

return nil
Expand Down
10 changes: 8 additions & 2 deletions http/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
if downLimit > 0 {
downloader.aggWriter = flowrate.NewWriter(progress, downLimit)
downloader.aggWriter = flowrate.NewWriter(progressWriter, downLimit)
} else {
downloader.aggWriter = progress
downloader.aggWriter = progressWriter
}

return downloader
Expand Down