mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
This commit allows to add, remove and update components of published repositories without the need to recreate them. Signed-off-by: Christoph Fiehe <c.fiehe@eurodata.de>
90 lines
2.7 KiB
Go
90 lines
2.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/aptly-dev/aptly/deb"
|
|
"github.com/smira/commander"
|
|
"github.com/smira/flag"
|
|
)
|
|
|
|
func aptlyPublishSourceAdd(cmd *commander.Command, args []string) error {
|
|
if len(args) < 2 {
|
|
cmd.Usage()
|
|
return commander.ErrCommandError
|
|
}
|
|
|
|
distribution := args[0]
|
|
names := args[1:]
|
|
components := strings.Split(context.Flags().Lookup("component").Value.String(), ",")
|
|
|
|
if len(names) != len(components) {
|
|
return fmt.Errorf("mismatch in number of components (%d) and sources (%d)", len(components), len(names))
|
|
}
|
|
|
|
prefix := context.Flags().Lookup("prefix").Value.String()
|
|
storage, prefix := deb.ParsePrefix(prefix)
|
|
|
|
collectionFactory := context.NewCollectionFactory()
|
|
published, err := collectionFactory.PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to add: %s", err)
|
|
}
|
|
|
|
err = collectionFactory.PublishedRepoCollection().LoadComplete(published, collectionFactory)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to add: %s", err)
|
|
}
|
|
|
|
revision := published.ObtainRevision()
|
|
sources := revision.Sources
|
|
|
|
for i, component := range components {
|
|
name := names[i]
|
|
_, exists := sources[component]
|
|
if exists {
|
|
return fmt.Errorf("unable to add: Component %q has already been added", component)
|
|
}
|
|
context.Progress().Printf("Adding component %q with source %q [%s]...\n", component, name, published.SourceKind)
|
|
|
|
sources[component] = names[i]
|
|
}
|
|
|
|
err = collectionFactory.PublishedRepoCollection().Update(published)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to save to DB: %s", err)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func makeCmdPublishSourceAdd() *commander.Command {
|
|
cmd := &commander.Command{
|
|
Run: aptlyPublishSourceAdd,
|
|
UsageLine: "add <distribution> <source>",
|
|
Short: "add package source to published repository",
|
|
Long: `
|
|
The command adds (in place) one or multiple package sources to a 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
|
|
equal to the number of given sources, e.g.:
|
|
|
|
aptly publish add -component=main,contrib wheezy wheezy-main wheezy-contrib
|
|
|
|
Example:
|
|
|
|
$ aptly publish add -component=contrib wheezy ppa wheezy-contrib
|
|
|
|
This command assigns the snapshot wheezy-contrib to the component contrib and
|
|
adds it to published repository revision of ppa/wheezy.
|
|
`,
|
|
Flag: *flag.NewFlagSet("aptly-publish-add", flag.ExitOnError),
|
|
}
|
|
cmd.Flag.String("prefix", ".", "publishing prefix in the form of [<endpoint>:]<prefix>")
|
|
cmd.Flag.String("component", "", "component names to add (for multi-component publishing, separate components with commas)")
|
|
|
|
return cmd
|
|
}
|