Added conflict checking
This commit is contained in:
parent
db6a776763
commit
6e11f937a6
19
main.go
19
main.go
@ -222,6 +222,25 @@ func resolveCommand() {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for conflicts
|
||||
conflicts, err := operation.CheckForConflicts()
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not complete package conflict check: %s\n", err)
|
||||
}
|
||||
if len(conflicts) > 0 {
|
||||
if !force {
|
||||
log.Println("Error: conflicting packages found")
|
||||
} else {
|
||||
log.Fatalf("Warning: conflicting packages found")
|
||||
}
|
||||
for pkg, conflict := range conflicts {
|
||||
fmt.Printf("%s is in conflict with the following packages: %s\n", pkg, strings.Join(conflict, ", "))
|
||||
}
|
||||
if !force {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Show operation summary
|
||||
operation.ShowOperationSummary()
|
||||
|
||||
|
@ -122,6 +122,53 @@ func (operation *BPMOperation) ResolveDependencies(reinstallDependencies, instal
|
||||
return nil
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error) {
|
||||
conflicts := make(map[string][]string)
|
||||
installedPackages, err := GetInstalledPackages(operation.RootDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allPackages := make([]*PackageInfo, len(installedPackages))
|
||||
for i, value := range installedPackages {
|
||||
bpmpkg := GetPackage(value, operation.RootDir)
|
||||
if bpmpkg == nil {
|
||||
return nil, errors.New(fmt.Sprintf("could not find installed package (%s)", value))
|
||||
}
|
||||
allPackages[i] = bpmpkg.PkgInfo
|
||||
}
|
||||
|
||||
// Add all new packages to the allPackages slice
|
||||
for _, value := range slices.Clone(operation.Actions) {
|
||||
if value.GetActionType() == "install" {
|
||||
action := value.(*InstallPackageAction)
|
||||
pkgInfo := action.BpmPackage.PkgInfo
|
||||
allPackages = append(allPackages, pkgInfo)
|
||||
} else if value.GetActionType() == "fetch" {
|
||||
action := value.(*FetchPackageAction)
|
||||
pkgInfo := action.RepositoryEntry.Info
|
||||
allPackages = append(allPackages, pkgInfo)
|
||||
} else if value.GetActionType() == "remove" {
|
||||
action := value.(*RemovePackageAction)
|
||||
pkgInfo := action.BpmPackage.PkgInfo
|
||||
slices.DeleteFunc(allPackages, func(info *PackageInfo) bool {
|
||||
return info.Name == pkgInfo.Name
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for _, value := range allPackages {
|
||||
for _, conflict := range value.Conflicts {
|
||||
if slices.ContainsFunc(allPackages, func(info *PackageInfo) bool {
|
||||
return info.Name == conflict
|
||||
}) {
|
||||
conflicts[value.Name] = append(conflicts[value.Name], conflict)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return conflicts, nil
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) ShowOperationSummary() {
|
||||
if len(operation.Actions) == 0 {
|
||||
fmt.Println("All packages are up to date!")
|
||||
|
Loading…
x
Reference in New Issue
Block a user