Add -force-replace flag to repo aptly add to replace conflicting packages. #83

This commit is contained in:
Andrey Smirnov
2014-09-01 17:59:29 +04:00
parent de32595d29
commit 0130fc0392
8 changed files with 58 additions and 1 deletions
+15
View File
@@ -40,6 +40,8 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to load packages: %s", err)
}
forceReplace := context.flags.Lookup("force-replace").Value.Get().(bool)
packageFiles := []string{}
failedFiles := []string{}
@@ -79,6 +81,10 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
processedFiles := []string{}
sort.Strings(packageFiles)
if forceReplace {
list.PrepareIndex()
}
for _, file := range packageFiles {
var (
stanza deb.Stanza
@@ -155,6 +161,14 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
continue
}
if forceReplace {
conflictingPackages := list.Search(deb.Dependency{Pkg: p.Name, Version: p.Version, Architecture: p.Architecture}, true)
for _, cp := range conflictingPackages {
context.Progress().ColoredPrintf("@r[-]@| %s removed due to conflict with package being added", cp)
list.Remove(cp)
}
}
err = list.Add(p)
if err != nil {
context.Progress().ColoredPrintf("@y[!]@| @!Unable to add package to repo %s: %s@|", p, err)
@@ -216,6 +230,7 @@ Example:
}
cmd.Flag.Bool("remove-files", false, "remove files that have been imported successfully into repository")
cmd.Flag.Bool("force-replace", false, "when adding package that conflicts with existing package, remove existing package")
return cmd
}