Fix test cases.

Signed-off-by: Christoph Fiehe <c.fiehe@eurodata.de>
This commit is contained in:
Christoph Fiehe
2024-10-10 16:14:25 +02:00
committed by André Roth
parent 9dffe791ad
commit d87d8bac92
30 changed files with 942 additions and 300 deletions

View File

@@ -56,6 +56,9 @@ func aptlyPublishSourceAdd(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to save to DB: %s", err)
}
context.Progress().Printf("\nYou can run 'aptly publish update %s %s' to update the content of the published repository.\n",
distribution, published.StoragePrefix())
return err
}
@@ -63,9 +66,9 @@ func makeCmdPublishSourceAdd() *commander.Command {
cmd := &commander.Command{
Run: aptlyPublishSourceAdd,
UsageLine: "add <distribution> <source>",
Short: "add package source to published repository",
Short: "add source to staged source list of published repository",
Long: `
The command adds (in place) one or multiple package sources to a published repository.
The command adds sources to the staged source list of the published repository.
The flag -component is mandatory. Use a comma-separated list of components, if
multiple components should be modified. The number of given components must be

View File

@@ -45,13 +45,13 @@ func makeCmdPublishSourceDrop() *commander.Command {
cmd := &commander.Command{
Run: aptlyPublishSourceDrop,
UsageLine: "drop <distribution>",
Short: "drops revision of published repository",
Short: "drops staged source changes of published repository",
Long: `
Command drops revision of a published repository.
Command drops the staged source changes of the published repository.
Example:
$ aptly publish revision drop wheezy
$ aptly publish source drop wheezy
`,
Flag: *flag.NewFlagSet("aptly-publish-revision-create", flag.ExitOnError),
}

View File

@@ -42,7 +42,7 @@ func aptlyPublishSourceRemove(cmd *commander.Command, args []string) error {
for _, component := range components {
name, exists := sources[component]
if !exists {
return fmt.Errorf("unable to remove: Component %q is not part of revision", component)
return fmt.Errorf("unable to remove: component %q does not exist", component)
}
context.Progress().Printf("Removing component %q with source %q [%s]...\n", component, name, published.SourceKind)
@@ -54,6 +54,9 @@ func aptlyPublishSourceRemove(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to save to DB: %s", err)
}
context.Progress().Printf("\nYou can run 'aptly publish update %s %s' to update the content of the published repository.\n",
distribution, published.StoragePrefix())
return err
}
@@ -61,9 +64,9 @@ func makeCmdPublishSourceRemove() *commander.Command {
cmd := &commander.Command{
Run: aptlyPublishSourceRemove,
UsageLine: "remove <distribution> [[<endpoint>:]<prefix>] <source>",
Short: "remove package source to published repository",
Short: "remove source from staged source list of published repository",
Long: `
The command removes one or multiple components from a published repository.
The command removes sources from the staged source list of the published repository.
The flag -component is mandatory. Use a comma-separated list of components, if
multiple components should be removed, e.g.:

View File

@@ -56,6 +56,9 @@ func aptlyPublishSourceUpdate(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to save to DB: %s", err)
}
context.Progress().Printf("\nYou can run 'aptly publish update %s %s' to update the content of the published repository.\n",
distribution, published.StoragePrefix())
return err
}
@@ -63,9 +66,9 @@ func makeCmdPublishSourceUpdate() *commander.Command {
cmd := &commander.Command{
Run: aptlyPublishSourceUpdate,
UsageLine: "update <distribution> <source>",
Short: "update package source to published repository",
Short: "update source in staged source list of published repository",
Long: `
The command updates one or multiple components in a published repository.
The command updates sources in the staged source list of the published repository.
The flag -component is mandatory. Use a comma-separated list of components, if
multiple components should be modified. The number of given components must be

View File

@@ -43,6 +43,10 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to switch: %s", err)
}
if published.SourceKind != deb.SourceSnapshot {
return fmt.Errorf("unable to switch: not a published snapshot repository")
}
err = collectionFactory.PublishedRepoCollection().LoadComplete(published, collectionFactory)
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
@@ -57,46 +61,23 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
return fmt.Errorf("mismatch in number of components (%d) and snapshots (%d)", len(components), len(names))
}
if published.SourceKind == deb.SourceLocalRepo {
localRepoCollection := collectionFactory.LocalRepoCollection()
for i, component := range components {
if !utils.StrSliceHasItem(publishedComponents, component) {
return fmt.Errorf("unable to switch: component %s does not exist in published repository", component)
}
localRepo, err := localRepoCollection.ByName(names[i])
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
err = localRepoCollection.LoadComplete(localRepo)
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
published.UpdateLocalRepo(component, localRepo)
snapshotCollection := collectionFactory.SnapshotCollection()
for i, component := range components {
if !utils.StrSliceHasItem(publishedComponents, component) {
return fmt.Errorf("unable to switch: component %s does not exist in published repository", component)
}
} else if published.SourceKind == deb.SourceSnapshot {
snapshotCollection := collectionFactory.SnapshotCollection()
for i, component := range components {
if !utils.StrSliceHasItem(publishedComponents, component) {
return fmt.Errorf("unable to switch: component %s does not exist in published repository", component)
}
snapshot, err := snapshotCollection.ByName(names[i])
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
err = snapshotCollection.LoadComplete(snapshot)
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
published.UpdateSnapshot(component, snapshot)
snapshot, err := snapshotCollection.ByName(names[i])
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
} else {
return fmt.Errorf("unknown published repository type")
err = snapshotCollection.LoadComplete(snapshot)
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
published.UpdateSnapshot(component, snapshot)
}
signer, err := getSigner(context.Flags())

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"path/filepath"
"github.com/aptly-dev/aptly/deb"
"github.com/smira/commander"
@@ -76,11 +77,20 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
skipCleanup := context.Flags().Lookup("skip-cleanup").Value.Get().(bool)
if !skipCleanup {
publishedStorage := context.GetPublishedStorage(storage)
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(published.Prefix, result.UpdatedComponents(),
context.GetPublishedStorage(storage), collectionFactory, context.Progress())
publishedStorage, collectionFactory, context.Progress())
if err != nil {
return fmt.Errorf("unable to update: %s", err)
}
// Cleanup files belonging to a removed component by dropping the component directory from the storage backend.
for _, component := range result.RemovedComponents() {
err = publishedStorage.RemoveDirs(filepath.Join(prefix, "dists", distribution, component), context.Progress())
if err != nil {
return fmt.Errorf("unable to update: %s", err)
}
}
}
context.Progress().Printf("\nPublished %s repository %s has been successfully updated.\n", published.SourceKind, published.String())