diff --git a/api/publish.go b/api/publish.go index c0f3de70..01e1d8e5 100644 --- a/api/publish.go +++ b/api/publish.go @@ -429,6 +429,17 @@ func apiPublishUpdateSwitch(c *gin.Context) { published.MultiDist = *b.MultiDist } + revision := published.ObtainRevision() + sources := revision.Sources + + if published.SourceKind == deb.SourceSnapshot { + for _, snapshotInfo := range b.Snapshots { + component := snapshotInfo.Component + name := snapshotInfo.Name + sources[component] = name + } + } + resources := []string{string(published.Key())} taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution) maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { @@ -625,7 +636,7 @@ func apiPublishSourcesList(c *gin.Context) { return } - c.JSON(http.StatusOK, revision.ToJSON()["Sources"]) + c.JSON(http.StatusOK, revision.SourceList()) } // @Router /api/publish/{prefix}/{distribution}/sources [put] diff --git a/cmd/publish_source_list.go b/cmd/publish_source_list.go index 2a915439..a12b5ac9 100644 --- a/cmd/publish_source_list.go +++ b/cmd/publish_source_list.go @@ -57,7 +57,7 @@ func aptlyPublishSourceListTxt(published *deb.PublishedRepo) error { func aptlyPublishSourceListJSON(published *deb.PublishedRepo) error { revision := published.Revision - output, err := json.MarshalIndent(revision.ToJSON()["Sources"], "", " ") + output, err := json.MarshalIndent(revision.SourceList(), "", " ") if err != nil { return fmt.Errorf("unable to list: %s", err) } diff --git a/deb/publish.go b/deb/publish.go index e5472093..b900077d 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -21,6 +21,10 @@ import ( "github.com/aptly-dev/aptly/utils" ) +type SourceEntry struct { + Component, Name string +} + type PublishedRepoUpdateResult struct { AddedSources map[string]string UpdatedSources map[string]string @@ -129,6 +133,21 @@ func (revision *PublishedRepoRevision) Components() []string { return components } +func (revision *PublishedRepoRevision) SourceList() []SourceEntry { + sources := revision.Sources + components := revision.Components() + sourceList := make([]SourceEntry, 0, len(sources)) + for _, component := range components { + name := sources[component] + sourceList = append(sourceList, SourceEntry{ + Component: component, + Name: name, + }) + } + + return sourceList +} + func (revision *PublishedRepoRevision) SourceNames() []string { sources := revision.Sources names := make([]string, 0, len(sources)) @@ -449,40 +468,26 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri return result, nil } -type sourceInfo struct { - Component, Name string -} - -func (revision *PublishedRepoRevision) ToJSON() map[string]any { - sources := []sourceInfo{} - for _, component := range revision.Components() { - name := revision.Sources[component] - sources = append(sources, sourceInfo{ - Component: component, - Name: name, - }) - } - return map[string]any{"Sources": sources} -} - func (revision *PublishedRepoRevision) MarshalJSON() ([]byte, error) { - sources := []sourceInfo{} - for _, component := range revision.Components() { - name := revision.Sources[component] - sources = append(sources, sourceInfo{ + sources := revision.Sources + components := revision.Components() + sourceList := make([]SourceEntry, 0, len(sources)) + for _, component := range components { + name := sources[component] + sourceList = append(sourceList, SourceEntry{ Component: component, Name: name, }) } return json.Marshal(map[string]interface{}{ - "Sources": sources, + "Sources": sourceList, }) } // MarshalJSON requires object to filled by "LoadShallow" or "LoadComplete" func (p *PublishedRepo) MarshalJSON() ([]byte, error) { - sources := []sourceInfo{} + sources := []SourceEntry{} for _, component := range p.Components() { item := p.sourceItems[component] name := "" @@ -493,7 +498,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) { } else { panic("no snapshot/local repo") } - sources = append(sources, sourceInfo{ + sources = append(sources, SourceEntry{ Component: component, Name: name, }) diff --git a/system/t06_publish/PublishSwitch12Test_gold b/system/t06_publish/PublishSwitch12Test_gold index 8a50172b..ce8636a4 100644 --- a/system/t06_publish/PublishSwitch12Test_gold +++ b/system/t06_publish/PublishSwitch12Test_gold @@ -1,8 +1 @@ -Loading packages... -Generating metadata files and linking package files... -Finalizing metadata files... -Signing file 'Release' with gpg, please enter your passphrase when prompted: -Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: -Cleaning up prefix "." components a, c... - -Publish for snapshot ./maverick [i386] publishes {a: [snap2]: Created as empty}, {b: [snap2]: Created as empty}, {c: [snap3]: Created as empty} has been successfully switched to new snapshot. +ERROR: unable to switch: component c does not exist in published repository diff --git a/system/t06_publish/PublishUpdate10Test_gold b/system/t06_publish/PublishUpdate10Test_gold index 082275a3..05b56b2a 100644 --- a/system/t06_publish/PublishUpdate10Test_gold +++ b/system/t06_publish/PublishUpdate10Test_gold @@ -1,5 +1,3 @@ -WARNING: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool. - Loading packages... Generating metadata files and linking package files... Finalizing metadata files... diff --git a/system/t06_publish/PublishUpdate12Test_binary b/system/t06_publish/PublishUpdate11Test_binary similarity index 100% rename from system/t06_publish/PublishUpdate12Test_binary rename to system/t06_publish/PublishUpdate11Test_binary diff --git a/system/t06_publish/PublishUpdate11Test_gold b/system/t06_publish/PublishUpdate11Test_gold index 05b56b2a..7488eec4 100644 --- a/system/t06_publish/PublishUpdate11Test_gold +++ b/system/t06_publish/PublishUpdate11Test_gold @@ -3,6 +3,5 @@ Generating metadata files and linking package files... Finalizing metadata files... Signing file 'Release' with gpg, please enter your passphrase when prompted: Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: -Cleaning up prefix "." components main... Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated. diff --git a/system/t06_publish/PublishUpdate12Test_release b/system/t06_publish/PublishUpdate11Test_release similarity index 100% rename from system/t06_publish/PublishUpdate12Test_release rename to system/t06_publish/PublishUpdate11Test_release diff --git a/system/t06_publish/PublishUpdate10Test/pyspi_0.6.1.orig.tar.gz b/system/t06_publish/PublishUpdate11Test_sources similarity index 100% rename from system/t06_publish/PublishUpdate10Test/pyspi_0.6.1.orig.tar.gz rename to system/t06_publish/PublishUpdate11Test_sources diff --git a/system/t06_publish/PublishUpdate12Test_gold b/system/t06_publish/PublishUpdate12Test_gold index 7488eec4..05b56b2a 100644 --- a/system/t06_publish/PublishUpdate12Test_gold +++ b/system/t06_publish/PublishUpdate12Test_gold @@ -3,5 +3,6 @@ Generating metadata files and linking package files... Finalizing metadata files... Signing file 'Release' with gpg, please enter your passphrase when prompted: Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: +Cleaning up prefix "." components main... Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated. diff --git a/system/t06_publish/PublishUpdate13Test_gold b/system/t06_publish/PublishUpdate13Test_gold index 05b56b2a..e0d3ab8c 100644 --- a/system/t06_publish/PublishUpdate13Test_gold +++ b/system/t06_publish/PublishUpdate13Test_gold @@ -5,4 +5,4 @@ Signing file 'Release' with gpg, please enter your passphrase when prompted: Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: Cleaning up prefix "." components main... -Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated. +Published local repository ./bookworm [i386, source] publishes {main: [local-repo]} has been successfully updated. diff --git a/system/t06_publish/PublishUpdate14Test_gold b/system/t06_publish/PublishUpdate14Test_gold deleted file mode 100644 index e0d3ab8c..00000000 --- a/system/t06_publish/PublishUpdate14Test_gold +++ /dev/null @@ -1,8 +0,0 @@ -Loading packages... -Generating metadata files and linking package files... -Finalizing metadata files... -Signing file 'Release' with gpg, please enter your passphrase when prompted: -Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: -Cleaning up prefix "." components main... - -Published local repository ./bookworm [i386, source] publishes {main: [local-repo]} has been successfully updated. diff --git a/system/t06_publish/PublishUpdate10Test_file b/system/t06_publish/PublishUpdate6Test_binary similarity index 100% rename from system/t06_publish/PublishUpdate10Test_file rename to system/t06_publish/PublishUpdate6Test_binary diff --git a/system/t06_publish/PublishUpdate7Test_binary2 b/system/t06_publish/PublishUpdate6Test_binary2 similarity index 100% rename from system/t06_publish/PublishUpdate7Test_binary2 rename to system/t06_publish/PublishUpdate6Test_binary2 diff --git a/system/t06_publish/PublishUpdate6Test_gold b/system/t06_publish/PublishUpdate6Test_gold index 98523831..a13b260c 100644 --- a/system/t06_publish/PublishUpdate6Test_gold +++ b/system/t06_publish/PublishUpdate6Test_gold @@ -1 +1,8 @@ -ERROR: unable to update: not a local repository publish +Loading packages... +Generating metadata files and linking package files... +Finalizing metadata files... +Signing file 'Release' with gpg, please enter your passphrase when prompted: +Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: +Cleaning up prefix "." components contrib, main... + +Published local repository ./maverick [i386, source] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated. diff --git a/system/t06_publish/PublishUpdate7Test_sources b/system/t06_publish/PublishUpdate6Test_sources similarity index 100% rename from system/t06_publish/PublishUpdate7Test_sources rename to system/t06_publish/PublishUpdate6Test_sources diff --git a/system/t06_publish/PublishUpdate12Test_sources b/system/t06_publish/PublishUpdate6Test_sources2 similarity index 100% rename from system/t06_publish/PublishUpdate12Test_sources rename to system/t06_publish/PublishUpdate6Test_sources2 diff --git a/system/t06_publish/PublishUpdate7Test_gold b/system/t06_publish/PublishUpdate7Test_gold index a13b260c..1a6ebd26 100644 --- a/system/t06_publish/PublishUpdate7Test_gold +++ b/system/t06_publish/PublishUpdate7Test_gold @@ -1,8 +1,6 @@ Loading packages... Generating metadata files and linking package files... Finalizing metadata files... -Signing file 'Release' with gpg, please enter your passphrase when prompted: -Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: Cleaning up prefix "." components contrib, main... -Published local repository ./maverick [i386, source] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated. +Published local repository ./squeeze [i386] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated. diff --git a/system/t06_publish/PublishUpdate10Test/pyspi_0.6.1-1.5.dsc b/system/t06_publish/PublishUpdate8Test/pyspi_0.6.1-1.5.dsc similarity index 100% rename from system/t06_publish/PublishUpdate10Test/pyspi_0.6.1-1.5.dsc rename to system/t06_publish/PublishUpdate8Test/pyspi_0.6.1-1.5.dsc diff --git a/system/t06_publish/PublishUpdate7Test_binary b/system/t06_publish/PublishUpdate8Test/pyspi_0.6.1.orig.tar.gz similarity index 100% rename from system/t06_publish/PublishUpdate7Test_binary rename to system/t06_publish/PublishUpdate8Test/pyspi_0.6.1.orig.tar.gz diff --git a/system/t06_publish/PublishUpdate8Test_gold b/system/t06_publish/PublishUpdate8Test_gold index 1a6ebd26..8279ee7d 100644 --- a/system/t06_publish/PublishUpdate8Test_gold +++ b/system/t06_publish/PublishUpdate8Test_gold @@ -1,6 +1,3 @@ Loading packages... Generating metadata files and linking package files... -Finalizing metadata files... -Cleaning up prefix "." components contrib, main... - -Published local repository ./squeeze [i386] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated. +ERROR: unable to publish: unable to process packages: error linking file to ${HOME}/.aptly/public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz: file already exists and is different diff --git a/system/t06_publish/PublishUpdate7Test_sources2 b/system/t06_publish/PublishUpdate9Test_file similarity index 100% rename from system/t06_publish/PublishUpdate7Test_sources2 rename to system/t06_publish/PublishUpdate9Test_file diff --git a/system/t06_publish/PublishUpdate9Test_gold b/system/t06_publish/PublishUpdate9Test_gold index 8279ee7d..082275a3 100644 --- a/system/t06_publish/PublishUpdate9Test_gold +++ b/system/t06_publish/PublishUpdate9Test_gold @@ -1,3 +1,10 @@ +WARNING: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool. + Loading packages... Generating metadata files and linking package files... -ERROR: unable to publish: unable to process packages: error linking file to ${HOME}/.aptly/public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz: file already exists and is different +Finalizing metadata files... +Signing file 'Release' with gpg, please enter your passphrase when prompted: +Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: +Cleaning up prefix "." components main... + +Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated. diff --git a/system/t06_publish/switch.py b/system/t06_publish/switch.py index dc777b91..4243a978 100644 --- a/system/t06_publish/switch.py +++ b/system/t06_publish/switch.py @@ -424,22 +424,15 @@ class PublishSwitch11Test(BaseTest): class PublishSwitch12Test(BaseTest): """ - publish switch: add new component to publish + publish switch: wrong component names """ fixtureCmds = [ "aptly snapshot create snap1 empty", "aptly snapshot create snap2 empty", - "aptly snapshot create snap3 empty", "aptly publish snapshot -architectures=i386 -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick -component=a,b snap1 snap2", ] - runCmd = "aptly publish switch -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=a,c maverick snap2 snap3" - gold_processor = BaseTest.expand_environ - - def check(self): - super(PublishSwitch12Test, self).check() - - self.check_exists('public/dists/maverick/a/binary-i386/Packages') - self.check_exists('public/dists/maverick/c/binary-i386/Packages') + runCmd = "aptly publish switch -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=a,c maverick snap2 snap1" + expectedCode = 1 class PublishSwitch13Test(BaseTest): diff --git a/system/t06_publish/update.py b/system/t06_publish/update.py index 7757715a..5d00d842 100644 --- a/system/t06_publish/update.py +++ b/system/t06_publish/update.py @@ -217,20 +217,6 @@ class PublishUpdate5Test(BaseTest): class PublishUpdate6Test(BaseTest): - """ - publish update: not a local repo - """ - fixtureDB = True - fixturePool = True - fixtureCmds = [ - "aptly snapshot create snap1 from mirror gnuplot-maverick", - "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap1", - ] - runCmd = "aptly publish update maverick" - expectedCode = 1 - - -class PublishUpdate7Test(BaseTest): """ publish update: multiple components, add some packages """ @@ -246,7 +232,7 @@ class PublishUpdate7Test(BaseTest): gold_processor = BaseTest.expand_environ def check(self): - super(PublishUpdate7Test, self).check() + super(PublishUpdate6Test, self).check() self.check_exists('public/dists/maverick/InRelease') self.check_exists('public/dists/maverick/Release') @@ -280,7 +266,7 @@ class PublishUpdate7Test(BaseTest): self.check_file_contents('public/dists/maverick/contrib/binary-i386/Packages', 'binary2', match_prepare=lambda s: "\n".join(sorted(s.split("\n")))) -class PublishUpdate8Test(BaseTest): +class PublishUpdate7Test(BaseTest): """ publish update: update empty repos to empty repos """ @@ -293,7 +279,7 @@ class PublishUpdate8Test(BaseTest): gold_processor = BaseTest.expand_environ -class PublishUpdate9Test(BaseTest): +class PublishUpdate8Test(BaseTest): """ publish update: conflicting files in the repo """ @@ -309,7 +295,7 @@ class PublishUpdate9Test(BaseTest): gold_processor = BaseTest.expand_environ -class PublishUpdate10Test(BaseTest): +class PublishUpdate9Test(BaseTest): """ publish update: -force-overwrite """ @@ -324,12 +310,12 @@ class PublishUpdate10Test(BaseTest): gold_processor = BaseTest.expand_environ def check(self): - super(PublishUpdate10Test, self).check() + super(PublishUpdate9Test, self).check() self.check_file_contents("public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz", "file") -class PublishUpdate11Test(BaseTest): +class PublishUpdate10Test(BaseTest): """ publish update: -skip-contents """ @@ -343,7 +329,7 @@ class PublishUpdate11Test(BaseTest): gold_processor = BaseTest.expand_environ def check(self): - super(PublishUpdate11Test, self).check() + super(PublishUpdate10Test, self).check() self.check_exists('public/dists/maverick/InRelease') self.check_exists('public/dists/maverick/Release') @@ -353,7 +339,7 @@ class PublishUpdate11Test(BaseTest): self.check_not_exists('public/dists/maverick/main/Contents-i386.gz') -class PublishUpdate12Test(BaseTest): +class PublishUpdate11Test(BaseTest): """ publish update: removed some packages skipping cleanup """ @@ -367,7 +353,7 @@ class PublishUpdate12Test(BaseTest): gold_processor = BaseTest.expand_environ def check(self): - super(PublishUpdate12Test, self).check() + super(PublishUpdate11Test, self).check() self.check_exists('public/dists/maverick/InRelease') self.check_exists('public/dists/maverick/Release') @@ -439,7 +425,7 @@ class PublishUpdate12Test(BaseTest): raise Exception("path seen wrong: %r" % (pathsSeen, )) -class PublishUpdate13Test(BaseTest): +class PublishUpdate12Test(BaseTest): """ publish update: -skip-bz2 """ @@ -453,7 +439,7 @@ class PublishUpdate13Test(BaseTest): gold_processor = BaseTest.expand_environ def check(self): - super(PublishUpdate13Test, self).check() + super(PublishUpdate12Test, self).check() self.check_exists('public/dists/maverick/InRelease') self.check_exists('public/dists/maverick/Release') @@ -464,7 +450,7 @@ class PublishUpdate13Test(BaseTest): self.check_not_exists('public/dists/maverick/main/binary-i386/Packages.bz2') -class PublishUpdate14Test(BaseTest): +class PublishUpdate13Test(BaseTest): """ publish update: -multi-dist """ @@ -477,7 +463,7 @@ class PublishUpdate14Test(BaseTest): gold_processor = BaseTest.expand_environ def check(self): - super(PublishUpdate14Test, self).check() + super(PublishUpdate13Test, self).check() self.check_exists('public/dists/bookworm/InRelease') self.check_exists('public/dists/bookworm/Release')