-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Command to replace the whole staged source list added.
Signed-off-by: Christoph Fiehe <[email protected]>
- Loading branch information
Christoph Fiehe
committed
Oct 23, 2024
1 parent
0d2dbb0
commit bd7d7bc
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aptly-dev/aptly/deb" | ||
"github.com/smira/commander" | ||
"github.com/smira/flag" | ||
) | ||
|
||
func aptlyPublishSourceReplace(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 | ||
context.Progress().Printf("Clearing staged source list...\n") | ||
clear(sources) | ||
|
||
for i, component := range components { | ||
name := names[i] | ||
context.Progress().Printf("Adding component '%s' with source '%s' [%s]...\n", component, name, published.SourceKind) | ||
|
||
sources[component] = name | ||
} | ||
|
||
err = collectionFactory.PublishedRepoCollection().Update(published) | ||
if err != nil { | ||
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 | ||
} | ||
|
||
func makeCmdPublishSourceReplace() *commander.Command { | ||
cmd := &commander.Command{ | ||
Run: aptlyPublishSourceReplace, | ||
UsageLine: "replace <distribution> <source>", | ||
Short: "replace staged source list of published repository", | ||
Long: ` | ||
The command replaces 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 | ||
equal to the number of given sources, e.g.: | ||
aptly publish source replace -component=main,contrib wheezy wheezy-main wheezy-contrib | ||
Example: | ||
$ aptly publish source replace -component=contrib wheezy ppa wheezy-contrib | ||
`, | ||
Flag: *flag.NewFlagSet("aptly-publish-source-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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Clearing staged source list... | ||
Adding component 'main-new' with source 'snap2' [snapshot]... | ||
Adding component 'test-new' with source 'snap3' [snapshot]... | ||
|
||
You can run 'aptly publish update maverick .' to update the content of the published repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters