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:
Andrey Smirnov
2019-09-03 12:57:44 +03:00
committed by Oliver Sauder
parent 98e75f6d97
commit 769e984ef4
2 changed files with 22 additions and 8 deletions
+14 -6
View File
@@ -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)
@@ -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
@@ -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