From df887d871b3ffb37d0a2b08ae5424a3c74efb625 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 2 Apr 2015 00:29:20 +0300 Subject: [PATCH] Skipping contents generation. #142 --- deb/publish.go | 37 +++++++++++++++++++++++++++++++++++++ deb/publish_test.go | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/deb/publish.go b/deb/publish.go index e19778f1..81f73074 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -43,6 +43,8 @@ type PublishedRepo struct { Architectures []string // SourceKind is "local"/"repo" SourceKind string + // Skip contents generation + SkipContents bool // Map of sources by each component: component name -> source UUID Sources map[string]string @@ -525,6 +527,8 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP list.PrepareIndex() + contentIndexes := map[string]*ContentsIndex{} + err = list.ForEachIndexed(func(pkg *Package) error { if progress != nil { progress.AddBar(1) @@ -550,6 +554,19 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP if pkg.MatchesArchitecture(arch) { var bufWriter *bufio.Writer + if !p.SkipContents { + key := fmt.Sprintf("%s-%v", arch, pkg.IsUdeb) + + contentIndex := contentIndexes[key] + + if contentIndex == nil { + contentIndex = NewContentsIndex() + contentIndexes[key] = contentIndex + } + + contentIndex.Push(pkg, packagePool) + } + bufWriter, err = indexes.PackageIndex(component, arch, pkg.IsUdeb).BufWriter() if err != nil { return err @@ -569,6 +586,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP pkg.files = nil pkg.deps = nil pkg.extra = nil + pkg.contents = nil return nil }) @@ -577,6 +595,25 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP return fmt.Errorf("unable to process packages: %s", err) } + for _, arch := range p.Architectures { + for _, udeb := range []bool{true, false} { + index := contentIndexes[fmt.Sprintf("%s-%v", arch, udeb)] + if index == nil || index.Empty() { + continue + } + + bufWriter, err := indexes.ContentsIndex(component, arch, udeb).BufWriter() + if err != nil { + return fmt.Errorf("unable to generate contents index: %v", err) + } + + _, err = index.WriteTo(bufWriter) + if err != nil { + return fmt.Errorf("unable to generate contents index: %v", err) + } + } + } + if progress != nil { progress.ShutdownBar() } diff --git a/deb/publish_test.go b/deb/publish_test.go index 05e2f730..b114c1e0 100644 --- a/deb/publish_test.go +++ b/deb/publish_test.go @@ -117,14 +117,19 @@ func (s *PublishedRepoSuite) SetUpTest(c *C) { s.packageCollection.Update(s.p3) s.repo, _ = NewPublishedRepo("", "ppa", "squeeze", nil, []string{"main"}, []interface{}{s.snapshot}, s.factory) + s.repo.SkipContents = true s.repo2, _ = NewPublishedRepo("", "ppa", "maverick", nil, []string{"main"}, []interface{}{s.localRepo}, s.factory) + s.repo2.SkipContents = true s.repo3, _ = NewPublishedRepo("", "linux", "natty", nil, []string{"main", "contrib"}, []interface{}{s.snapshot, s.snapshot2}, s.factory) + s.repo3.SkipContents = true s.repo4, _ = NewPublishedRepo("", "ppa", "maverick", []string{"source"}, []string{"main"}, []interface{}{s.localRepo}, s.factory) + s.repo4.SkipContents = true s.repo5, _ = NewPublishedRepo("files:other", "ppa", "maverick", []string{"source"}, []string{"main"}, []interface{}{s.localRepo}, s.factory) + s.repo5.SkipContents = true poolPath, _ := s.packagePool.Path(s.p1.Files()[0].Filename, s.p1.Files()[0].Checksums.MD5) err := os.MkdirAll(filepath.Dir(poolPath), 0755)