Skip to content

Commit

Permalink
Allow to add a new component to a published repo
Browse files Browse the repository at this point in the history
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 <c.fiehe@eurodata.de>
  • Loading branch information
Christoph Fiehe committed Sep 20, 2024
1 parent 372ce3c commit 6c9a961
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
6 changes: 0 additions & 6 deletions api/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -301,11 +300,6 @@ func apiPublishUpdateSwitch(c *gin.Context) {
} else if published.SourceKind == "snapshot" {
publishedComponents := published.Components()

Check failure on line 301 in api/publish.go

View workflow job for this annotation

GitHub Actions / lint

publishedComponents declared and not used (typecheck)

Check failure on line 301 in api/publish.go

View workflow job for this annotation

GitHub Actions / lint

publishedComponents declared and not used) (typecheck)

Check failure on line 301 in api/publish.go

View workflow job for this annotation

GitHub Actions / test

publishedComponents declared and not used
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 {
Expand Down
5 changes: 0 additions & 5 deletions cmd/publish_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions system/t06_publish/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,22 @@ def check(self):

class PublishSwitch12Test(BaseTest):
"""
publish switch: wrong component names
publish switch: add new component
"""
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):
Expand Down

0 comments on commit 6c9a961

Please sign in to comment.