From 603ad6d2dd31b53b419d2274ef3ca465e09d9c96 Mon Sep 17 00:00:00 2001 From: Christoph Fiehe Date: Fri, 20 Sep 2024 13:58:12 +0200 Subject: [PATCH] Allow to add a new component to a published repo This commit modifies the behavior of the publish switch method in the way, that also new components can be added to an already published repository. It is no longer necessary to drop and recreate the whole publish. Signed-off-by: Christoph Fiehe --- .github/workflows/ci.yml | 2 +- api/publish.go | 7 ------- cmd/publish_switch.go | 5 ----- deb/publish.go | 5 ++++- system/t06_publish/PublishSwitch12Test_gold | 9 ++++++++- system/t06_publish/switch.py | 11 +++++++++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0be86102..4be092fcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: BOTO_CONFIG: /dev/null GO111MODULE: "on" GOPROXY: "https://proxy.golang.org" - GOVER: '1.21' + GOVER: '1.22' steps: - name: Checkout repository diff --git a/api/publish.go b/api/publish.go index adce3c84e..3d8e990dd 100644 --- a/api/publish.go +++ b/api/publish.go @@ -9,7 +9,6 @@ import ( "github.com/aptly-dev/aptly/deb" "github.com/aptly-dev/aptly/pgp" "github.com/aptly-dev/aptly/task" - "github.com/aptly-dev/aptly/utils" "github.com/gin-gonic/gin" ) @@ -299,13 +298,7 @@ func apiPublishUpdateSwitch(c *gin.Context) { published.UpdateLocalRepo(component) } } else if published.SourceKind == "snapshot" { - publishedComponents := published.Components() for _, snapshotInfo := range b.Snapshots { - if !utils.StrSliceHasItem(publishedComponents, snapshotInfo.Component) { - AbortWithJSONError(c, 404, fmt.Errorf("component %s is not in published repository", snapshotInfo.Component)) - return - } - snapshotCollection := collectionFactory.SnapshotCollection() snapshot, err2 := snapshotCollection.ByName(snapshotInfo.Name) if err2 != nil { diff --git a/cmd/publish_switch.go b/cmd/publish_switch.go index 58a1195cb..a55347475 100644 --- a/cmd/publish_switch.go +++ b/cmd/publish_switch.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/aptly-dev/aptly/deb" - "github.com/aptly-dev/aptly/utils" "github.com/smira/commander" "github.com/smira/flag" ) @@ -65,10 +64,6 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error { } for i, component := range components { - if !utils.StrSliceHasItem(publishedComponents, component) { - return fmt.Errorf("unable to switch: component %s is not in published repository", component) - } - snapshot, err = collectionFactory.SnapshotCollection().ByName(names[i]) if err != nil { return fmt.Errorf("unable to switch: %s", err) diff --git a/deb/publish.go b/deb/publish.go index 0098bb212..2bdd608de 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -458,7 +458,10 @@ func (p *PublishedRepo) UpdateSnapshot(component string, snapshot *Snapshot) { panic("not snapshot publish") } - item := p.sourceItems[component] + item, exists := p.sourceItems[component] + if !exists { + item = repoSourceItem{} + } item.snapshot = snapshot p.sourceItems[component] = item diff --git a/system/t06_publish/PublishSwitch12Test_gold b/system/t06_publish/PublishSwitch12Test_gold index 2fb3bcaca..8a50172b6 100644 --- a/system/t06_publish/PublishSwitch12Test_gold +++ b/system/t06_publish/PublishSwitch12Test_gold @@ -1 +1,8 @@ -ERROR: unable to switch: component c is not in published repository +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. diff --git a/system/t06_publish/switch.py b/system/t06_publish/switch.py index 6a86a3cc4..a9588b4dc 100644 --- a/system/t06_publish/switch.py +++ b/system/t06_publish/switch.py @@ -429,10 +429,17 @@ class PublishSwitch12Test(BaseTest): 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 snap1" - expectedCode = 1 + 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') class PublishSwitch13Test(BaseTest):