mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
Don't allow to drop repo if it is published.
This commit is contained in:
+17
-6
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gonuts/commander"
|
"github.com/gonuts/commander"
|
||||||
"github.com/gonuts/flag"
|
"github.com/gonuts/flag"
|
||||||
"github.com/smira/aptly/debian"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
||||||
@@ -16,16 +15,28 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
localRepoCollection := debian.NewLocalRepoCollection(context.database)
|
repo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
repo, err := localRepoCollection.ByName(name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
published := context.collectionFactory.PublishedRepoCollection().ByLocalRepo(repo)
|
||||||
|
if len(published) > 0 {
|
||||||
|
fmt.Printf("Local repo `%s` is published currently:\n", repo.Name)
|
||||||
|
for _, repo := range published {
|
||||||
|
err = context.collectionFactory.PublishedRepoCollection().LoadComplete(repo, context.collectionFactory)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load published: %s", err)
|
||||||
|
}
|
||||||
|
fmt.Printf(" * %s\n", repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("unable to drop: local repo is published")
|
||||||
|
}
|
||||||
|
|
||||||
force := cmd.Flag.Lookup("force").Value.Get().(bool)
|
force := cmd.Flag.Lookup("force").Value.Get().(bool)
|
||||||
if !force {
|
if !force {
|
||||||
snapshotCollection := debian.NewSnapshotCollection(context.database)
|
snapshots := context.collectionFactory.SnapshotCollection().ByLocalRepoSource(repo)
|
||||||
snapshots := snapshotCollection.ByLocalRepoSource(repo)
|
|
||||||
|
|
||||||
if len(snapshots) > 0 {
|
if len(snapshots) > 0 {
|
||||||
fmt.Printf("Local repo `%s` was used to create following snapshots:\n", repo.Name)
|
fmt.Printf("Local repo `%s` was used to create following snapshots:\n", repo.Name)
|
||||||
@@ -37,7 +48,7 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = localRepoCollection.Drop(repo)
|
err = context.collectionFactory.LocalRepoCollection().Drop(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user