// Download downloads all repo files func (repo *RemoteRepo) Download(d utils.Downloader, db database.Storage, packageRepo *Repository) error { list := NewPackageList() // Download and parse all Release files for _, component := range repo.Components { for _, architecture := range repo.Architectures { packagesReader, packagesFile, err := utils.DownloadTryCompression(d, repo.BinaryURL(component, architecture).String()) if err != nil { return err } defer packagesFile.Close() paras, err := debc.Parse(packagesReader) if err != nil { return err } for _, para := range paras { p := NewPackageFromControlFile(para) list.Add(p) } } } // Save package meta information to DB list.ForEach(func(p *Package) { db.Put(p.Key(), p.Encode()) }) // Download all package files ch := make(chan error, list.Len()) count := 0 list.ForEach(func(p *Package) { poolPath, err := packageRepo.PoolPath(p.Filename) if err == nil { if !p.VerifyFile(poolPath) { d.Download(repo.PackageURL(p.Filename).String(), poolPath, ch) count++ } } }) // Wait for all downloads to finish // TODO: report errors for count > 0 { _ = <-ch count-- } repo.LastDownloadDate = time.Now() repo.packageRefs = NewPackageRefListFromPackageList(list) return nil }
// Fetch updates information about repository func (repo *RemoteRepo) Fetch(d utils.Downloader) error { // Download release file to temporary URL release, err := utils.DownloadTemp(d, repo.ReleaseURL().String()) if err != nil { return err } defer release.Close() paras, err := debc.Parse(release) if err != nil { return err } if len(paras) != 1 { return fmt.Errorf("wrong number of parts in Release file") } para := paras[0] architectures := strings.Split(para["Architectures"], " ") if len(repo.Architectures) == 0 { repo.Architectures = architectures } else { err = utils.StringsIsSubset(repo.Architectures, architectures, fmt.Sprintf("architecture %%s not available in repo %s", repo)) if err != nil { return err } } components := strings.Split(para["Components"], " ") if len(repo.Components) == 0 { repo.Components = components } else { err = utils.StringsIsSubset(repo.Components, components, fmt.Sprintf("component %%s not available in repo %s", repo)) if err != nil { return err } } delete(para, "MD5Sum") delete(para, "SHA1") delete(para, "SHA256") repo.Meta = para return nil }