// DownloadPackageIndexes downloads & parses package index files func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.Downloader, collectionFactory *CollectionFactory, ignoreMismatch bool) error { if repo.packageList != nil { panic("packageList != nil") } repo.packageList = NewPackageList() // Download and parse all Packages & Source files packagesURLs := [][]string{} if repo.IsFlat() { packagesURLs = append(packagesURLs, []string{repo.FlatBinaryURL().String(), "binary"}) if repo.DownloadSources { packagesURLs = append(packagesURLs, []string{repo.FlatSourcesURL().String(), "source"}) } } else { for _, component := range repo.Components { for _, architecture := range repo.Architectures { packagesURLs = append(packagesURLs, []string{repo.BinaryURL(component, architecture).String(), "binary"}) if repo.DownloadUdebs { packagesURLs = append(packagesURLs, []string{repo.UdebURL(component, architecture).String(), "udeb"}) } } if repo.DownloadSources { packagesURLs = append(packagesURLs, []string{repo.SourcesURL(component).String(), "source"}) } } } for _, info := range packagesURLs { url, kind := info[0], info[1] packagesReader, packagesFile, err := http.DownloadTryCompression(d, url, repo.ReleaseFiles, ignoreMismatch) if err != nil { return err } defer packagesFile.Close() stat, _ := packagesFile.Stat() progress.InitBar(stat.Size(), true) sreader := NewControlFileReader(packagesReader) for { stanza, err := sreader.ReadStanza() if err != nil { return err } if stanza == nil { break } off, _ := packagesFile.Seek(0, 1) progress.SetBar(int(off)) var p *Package if kind == "binary" { p = NewPackageFromControlFile(stanza) } else if kind == "udeb" { p = NewUdebPackageFromControlFile(stanza) } else if kind == "source" { p, err = NewSourcePackageFromControlFile(stanza) if err != nil { return err } } err = repo.packageList.Add(p) if err != nil { if _, ok := err.(*PackageConflictError); ok { progress.ColoredPrintf("@y[!]@| @!skipping package %s: duplicate in packages index@|", p) } else { return err } } err = collectionFactory.PackageCollection().Update(p) if err != nil { return err } } progress.ShutdownBar() } return nil }