Add "make_dependency" installation reason
This commit is contained in:
parent
966d351a80
commit
458c091ac2
@ -1,6 +1,7 @@
|
||||
ignore_packages: []
|
||||
privilege_escalator_cmd: "sudo"
|
||||
compilation_env: []
|
||||
cleanup_make_dependencies: true
|
||||
databases:
|
||||
- name: example-database
|
||||
source: https://my-database.xyz/
|
||||
|
@ -44,6 +44,7 @@ var installSrcPkgDepends = false
|
||||
var skipChecks = false
|
||||
var outputDirectory = ""
|
||||
var cleanupDependencies = false
|
||||
var cleanupMakeDependencies = false
|
||||
var cleanupCompilationFiles = false
|
||||
var cleanupCompiledPackages = false
|
||||
var cleanupFetchedPackages = false
|
||||
@ -249,12 +250,14 @@ func resolveCommand() {
|
||||
}
|
||||
|
||||
// Check if installationReason argument is valid
|
||||
ir := bpmlib.InstallationReasonUnknown
|
||||
ir := bpmlib.InstallationReasonManual
|
||||
switch installationReason {
|
||||
case "manual":
|
||||
ir = bpmlib.InstallationReasonManual
|
||||
case "dependency":
|
||||
ir = bpmlib.InstallationReasonDependency
|
||||
case "make-dependency":
|
||||
ir = bpmlib.InstallationReasonMakeDependency
|
||||
case "":
|
||||
default:
|
||||
log.Fatalf("Error: %s is not a valid installation reason", installationReason)
|
||||
@ -467,7 +470,7 @@ func resolveCommand() {
|
||||
log.Fatalf("Error: could not complete cache cleanup: %s", err)
|
||||
}
|
||||
|
||||
if cleanupDependencies {
|
||||
if cleanupDependencies || cleanupMakeDependencies {
|
||||
// Read local databases
|
||||
err := bpmlib.ReadLocalDatabaseFiles()
|
||||
if err != nil {
|
||||
@ -475,7 +478,7 @@ func resolveCommand() {
|
||||
}
|
||||
|
||||
// Create cleanup operation
|
||||
operation, err := bpmlib.CleanupPackages(rootDir)
|
||||
operation, err := bpmlib.CleanupPackages(cleanupMakeDependencies, rootDir)
|
||||
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
||||
log.Fatalf("Error: %s", err)
|
||||
} else if err != nil {
|
||||
@ -595,7 +598,7 @@ func resolveCommand() {
|
||||
|
||||
// Get direct runtime and make dependencies
|
||||
totalDepends := make([]string, 0)
|
||||
for _, depend := range bpmpkg.PkgInfo.GetDependencies(true, false) {
|
||||
for depend := range bpmpkg.PkgInfo.GetDependencies(true, false) {
|
||||
if !slices.Contains(totalDepends, depend) {
|
||||
totalDepends = append(totalDepends, depend)
|
||||
}
|
||||
@ -624,7 +627,7 @@ func resolveCommand() {
|
||||
}
|
||||
|
||||
// Run 'bpm install' using the set privilege escalator command
|
||||
args := []string{executable, "install", "--installation-reason=dependency"}
|
||||
args := []string{executable, "install", "--installation-reason=make-dependency"}
|
||||
args = append(args, unmetDepends...)
|
||||
cmd := exec.Command(bpmlib.BPMConfig.PrivilegeEscalatorCmd, args...)
|
||||
if yesAll {
|
||||
@ -777,6 +780,7 @@ func printHelp() {
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
fmt.Println(" --depends performs a dependency cleanup")
|
||||
fmt.Println(" --make-depends performs a make dependency cleanup")
|
||||
fmt.Println(" --compilation-files performs a cleanup of compilation files")
|
||||
fmt.Println(" --compiled-pkgs performs a cleanup of compilation compiled binary packages")
|
||||
fmt.Println(" --fetched-pkgs performs a cleanup of fetched packages from databases")
|
||||
@ -843,6 +847,7 @@ func resolveFlags() {
|
||||
cleanupFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
cleanupFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
cleanupFlagSet.BoolVar(&cleanupDependencies, "depends", false, "Perform a dependency cleanup")
|
||||
cleanupFlagSet.BoolVar(&cleanupMakeDependencies, "make-depends", false, "Perform a make dependency cleanup")
|
||||
cleanupFlagSet.BoolVar(&cleanupCompilationFiles, "compilation-files", false, "Perform a cleanup of compilation files")
|
||||
cleanupFlagSet.BoolVar(&cleanupCompiledPackages, "compiled-pkgs", false, "Perform a cleanup of compilation compiled binary packages")
|
||||
cleanupFlagSet.BoolVar(&cleanupFetchedPackages, "fetched-pkgs", false, "Perform a cleanup of fetched packages from databases")
|
||||
@ -858,8 +863,18 @@ func resolveFlags() {
|
||||
compileFlagSet.StringVar(&outputDirectory, "o", "", "Set output directory")
|
||||
compileFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
compileFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
|
||||
compileFlagSet.Usage = printHelp
|
||||
|
||||
isFlagSet := func(flagSet *flag.FlagSet, name string) bool {
|
||||
found := false
|
||||
flagSet.Visit(func(f *flag.Flag) {
|
||||
if f.Name == name {
|
||||
found = true
|
||||
}
|
||||
})
|
||||
return found
|
||||
}
|
||||
|
||||
if len(os.Args[1:]) <= 0 {
|
||||
subcommand = "help"
|
||||
} else {
|
||||
@ -906,8 +921,9 @@ func resolveFlags() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !cleanupDependencies && !cleanupCompilationFiles && !cleanupCompiledPackages && !cleanupFetchedPackages {
|
||||
if !isFlagSet(cleanupFlagSet, "depends") && !isFlagSet(cleanupFlagSet, "make-depends") && !isFlagSet(cleanupFlagSet, "compilation-files") && !isFlagSet(cleanupFlagSet, "compiled-pkgs") && !isFlagSet(cleanupFlagSet, "fetched-pkgs") {
|
||||
cleanupDependencies = true
|
||||
cleanupMakeDependencies = bpmlib.BPMConfig.CleanupMakeDependencies
|
||||
cleanupCompilationFiles = true
|
||||
cleanupCompiledPackages = true
|
||||
cleanupFetchedPackages = true
|
||||
|
@ -6,10 +6,11 @@ import (
|
||||
)
|
||||
|
||||
type BPMConfigStruct struct {
|
||||
IgnorePackages []string `yaml:"ignore_packages"`
|
||||
PrivilegeEscalatorCmd string `yaml:"privilege_escalator_cmd"`
|
||||
CompilationEnvironment []string `yaml:"compilation_env"`
|
||||
Databases []*BPMDatabase `yaml:"databases"`
|
||||
IgnorePackages []string `yaml:"ignore_packages"`
|
||||
PrivilegeEscalatorCmd string `yaml:"privilege_escalator_cmd"`
|
||||
CompilationEnvironment []string `yaml:"compilation_env"`
|
||||
CleanupMakeDependencies bool `yaml:"cleanup_make_dependencies"`
|
||||
Databases []*BPMDatabase `yaml:"databases"`
|
||||
}
|
||||
|
||||
var BPMConfig BPMConfigStruct
|
||||
@ -24,7 +25,9 @@ func ReadConfig() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
BPMConfig = BPMConfigStruct{}
|
||||
BPMConfig = BPMConfigStruct{
|
||||
CleanupMakeDependencies: true,
|
||||
}
|
||||
err = yaml.Unmarshal(bytes, &BPMConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -6,14 +6,25 @@ import (
|
||||
"slices"
|
||||
)
|
||||
|
||||
func (pkgInfo *PackageInfo) GetDependencies(includeMakeDepends, includeOptionalDepends bool) []string {
|
||||
allDepends := make([]string, 0)
|
||||
allDepends = append(allDepends, pkgInfo.Depends...)
|
||||
if includeMakeDepends {
|
||||
allDepends = append(allDepends, pkgInfo.MakeDepends...)
|
||||
func (pkgInfo *PackageInfo) GetDependencies(includeMakeDepends, includeOptionalDepends bool) map[string]InstallationReason {
|
||||
allDepends := make(map[string]InstallationReason)
|
||||
|
||||
for _, depend := range pkgInfo.Depends {
|
||||
allDepends[depend] = InstallationReasonDependency
|
||||
}
|
||||
if includeOptionalDepends {
|
||||
allDepends = append(allDepends, pkgInfo.OptionalDepends...)
|
||||
for _, depend := range pkgInfo.OptionalDepends {
|
||||
if _, ok := allDepends[depend]; !ok {
|
||||
allDepends[depend] = InstallationReasonDependency
|
||||
}
|
||||
}
|
||||
}
|
||||
if includeMakeDepends {
|
||||
for _, depend := range pkgInfo.MakeDepends {
|
||||
if _, ok := allDepends[depend]; !ok {
|
||||
allDepends[depend] = InstallationReasonMakeDependency
|
||||
}
|
||||
}
|
||||
}
|
||||
return allDepends
|
||||
}
|
||||
@ -34,7 +45,10 @@ func (pkgInfo *PackageInfo) getAllDependencies(resolved *[]string, unresolved *[
|
||||
*unresolved = append(*unresolved, pkgInfo.Name)
|
||||
|
||||
// Loop through all dependencies
|
||||
for _, depend := range pkgInfo.GetDependencies(includeMakeDepends, includeOptionalDepends) {
|
||||
for depend := range pkgInfo.GetDependencies(includeMakeDepends, includeOptionalDepends) {
|
||||
if isVirtual, p := IsVirtualPackage(depend, rootDir); isVirtual {
|
||||
depend = p
|
||||
}
|
||||
if !slices.Contains(*resolved, depend) {
|
||||
// Add current dependency to resolved slice when circular dependency is detected
|
||||
if slices.Contains(*unresolved, depend) {
|
||||
@ -44,13 +58,7 @@ func (pkgInfo *PackageInfo) getAllDependencies(resolved *[]string, unresolved *[
|
||||
continue
|
||||
}
|
||||
|
||||
var dependInfo *PackageInfo
|
||||
|
||||
if isVirtual, p := IsVirtualPackage(depend, rootDir); isVirtual {
|
||||
dependInfo = GetPackageInfo(p, rootDir)
|
||||
} else {
|
||||
dependInfo = GetPackageInfo(depend, rootDir)
|
||||
}
|
||||
dependInfo := GetPackageInfo(depend, rootDir)
|
||||
|
||||
if dependInfo != nil {
|
||||
dependInfo.getAllDependencies(resolved, unresolved, includeMakeDepends, includeOptionalDepends, rootDir)
|
||||
@ -63,31 +71,31 @@ func (pkgInfo *PackageInfo) getAllDependencies(resolved *[]string, unresolved *[
|
||||
*unresolved = stringSliceRemove(*unresolved, pkgInfo.Name)
|
||||
}
|
||||
|
||||
func ResolvePackageDependenciesFromDatabases(pkgInfo *PackageInfo, checkMake, checkOptional, ignoreInstalled, verbose bool, rootDir string) (resolved []string, unresolved []string) {
|
||||
func ResolveAllPackageDependenciesFromDatabases(pkgInfo *PackageInfo, checkMake, checkOptional, ignoreInstalled, verbose bool, rootDir string) (resolved map[string]InstallationReason, unresolved []string) {
|
||||
// Initialize slices
|
||||
resolved = make([]string, 0)
|
||||
resolved = make(map[string]InstallationReason)
|
||||
unresolved = make([]string, 0)
|
||||
|
||||
// Call unexported function
|
||||
resolvePackageDependenciesFromDatabase(&resolved, &unresolved, pkgInfo, checkMake, checkOptional, ignoreInstalled, verbose, rootDir)
|
||||
resolvePackageDependenciesFromDatabase(resolved, &unresolved, pkgInfo, InstallationReasonDependency, checkMake, checkOptional, ignoreInstalled, verbose, rootDir)
|
||||
|
||||
return resolved, unresolved
|
||||
}
|
||||
|
||||
func resolvePackageDependenciesFromDatabase(resolved, unresolved *[]string, pkgInfo *PackageInfo, checkMake, checkOptional, ignoreInstalled, verbose bool, rootDir string) {
|
||||
func resolvePackageDependenciesFromDatabase(resolved map[string]InstallationReason, unresolved *[]string, pkgInfo *PackageInfo, installationReason InstallationReason, checkMake, checkOptional, ignoreInstalled, verbose bool, rootDir string) {
|
||||
// Add current package name to unresolved slice
|
||||
*unresolved = append(*unresolved, pkgInfo.Name)
|
||||
|
||||
// Loop through all dependencies
|
||||
for _, depend := range pkgInfo.GetDependencies(checkMake, checkOptional) {
|
||||
if !slices.Contains(*resolved, depend) {
|
||||
for depend, ir := range pkgInfo.GetDependencies(pkgInfo.Type == "source", checkOptional) {
|
||||
if _, ok := resolved[depend]; !ok {
|
||||
// Add current dependency to resolved slice when circular dependency is detected
|
||||
if slices.Contains(*unresolved, depend) {
|
||||
if verbose {
|
||||
fmt.Printf("Circular dependency was detected (%s -> %s). Installing %s first\n", pkgInfo.Name, depend, depend)
|
||||
}
|
||||
if !slices.Contains(*resolved, depend) {
|
||||
*resolved = append(*resolved, depend)
|
||||
if _, ok := resolved[depend]; !ok {
|
||||
resolved[depend] = ir
|
||||
}
|
||||
continue
|
||||
} else if ignoreInstalled && IsPackageProvided(depend, rootDir) {
|
||||
@ -104,11 +112,12 @@ func resolvePackageDependenciesFromDatabase(resolved, unresolved *[]string, pkgI
|
||||
continue
|
||||
}
|
||||
}
|
||||
resolvePackageDependenciesFromDatabase(resolved, unresolved, entry.Info, checkMake, checkOptional, ignoreInstalled, verbose, rootDir)
|
||||
resolvePackageDependenciesFromDatabase(resolved, unresolved, entry.Info, ir, checkMake, checkOptional, ignoreInstalled, verbose, rootDir)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(*resolved, pkgInfo.Name) {
|
||||
*resolved = append(*resolved, pkgInfo.Name)
|
||||
|
||||
if _, ok := resolved[pkgInfo.Name]; !ok {
|
||||
resolved[pkgInfo.Name] = installationReason
|
||||
}
|
||||
*unresolved = stringSliceRemove(*unresolved, pkgInfo.Name)
|
||||
}
|
||||
@ -145,7 +154,7 @@ func GetPackageDependants(pkgName string, rootDir string) ([]string, error) {
|
||||
dependencies := installedPkg.PkgInfo.GetDependencies(false, true)
|
||||
|
||||
// Add installed package to list if its dependencies include pkgName
|
||||
if slices.Contains(dependencies, pkgName) {
|
||||
if _, ok := dependencies[pkgName]; ok {
|
||||
ret = append(ret, installedPkgName)
|
||||
continue
|
||||
}
|
||||
@ -153,7 +162,7 @@ func GetPackageDependants(pkgName string, rootDir string) ([]string, error) {
|
||||
// Loop through each virtual package
|
||||
for _, vpkg := range pkg.PkgInfo.Provides {
|
||||
// Add installed package to list if its dependencies contain a provided virtual package
|
||||
if slices.Contains(dependencies, vpkg) {
|
||||
if _, ok := dependencies[vpkg]; ok {
|
||||
ret = append(ret, installedPkgName)
|
||||
break
|
||||
}
|
||||
|
@ -21,12 +21,11 @@ const (
|
||||
func InstallPackages(rootDir string, installationReason InstallationReason, reinstallMethod ReinstallMethod, installOptionalDependencies, forceInstallation, verbose bool, packages ...string) (operation *BPMOperation, err error) {
|
||||
// Setup operation struct
|
||||
operation = &BPMOperation{
|
||||
Actions: make([]OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
Changes: make(map[string]string),
|
||||
RootDir: rootDir,
|
||||
ForceInstallationReason: installationReason,
|
||||
compiledPackages: make(map[string]string),
|
||||
Actions: make([]OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
Changes: make(map[string]string),
|
||||
RootDir: rootDir,
|
||||
compiledPackages: make(map[string]string),
|
||||
}
|
||||
|
||||
// Resolve packages
|
||||
@ -46,7 +45,7 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
||||
|
||||
operation.AppendAction(&InstallPackageAction{
|
||||
File: pkg,
|
||||
IsDependency: false,
|
||||
InstallationReason: installationReason,
|
||||
BpmPackage: bpmpkg,
|
||||
SplitPackageToInstall: splitPkg.Name,
|
||||
})
|
||||
@ -59,9 +58,9 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
||||
}
|
||||
|
||||
operation.AppendAction(&InstallPackageAction{
|
||||
File: pkg,
|
||||
IsDependency: false,
|
||||
BpmPackage: bpmpkg,
|
||||
File: pkg,
|
||||
InstallationReason: installationReason,
|
||||
BpmPackage: bpmpkg,
|
||||
})
|
||||
} else {
|
||||
var entry *BPMDatabaseEntry
|
||||
@ -85,8 +84,8 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
||||
}
|
||||
|
||||
operation.AppendAction(&FetchPackageAction{
|
||||
IsDependency: false,
|
||||
DatabaseEntry: entry,
|
||||
InstallationReason: installationReason,
|
||||
DatabaseEntry: entry,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -161,7 +160,7 @@ func RemovePackages(rootDir string, removeUnusedPackagesOnly, cleanupDependencie
|
||||
|
||||
// Do package cleanup
|
||||
if cleanupDependencies {
|
||||
err := operation.Cleanup()
|
||||
err := operation.Cleanup(true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform cleanup for operation: %s", err)
|
||||
}
|
||||
@ -170,7 +169,7 @@ func RemovePackages(rootDir string, removeUnusedPackagesOnly, cleanupDependencie
|
||||
}
|
||||
|
||||
// CleanupPackages finds packages installed as dependencies which are no longer required by the rest of the system in the given root directory
|
||||
func CleanupPackages(rootDir string) (operation *BPMOperation, err error) {
|
||||
func CleanupPackages(cleanupMakeDepends bool, rootDir string) (operation *BPMOperation, err error) {
|
||||
operation = &BPMOperation{
|
||||
Actions: make([]OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
@ -180,7 +179,7 @@ func CleanupPackages(rootDir string) (operation *BPMOperation, err error) {
|
||||
}
|
||||
|
||||
// Do package cleanup
|
||||
err = operation.Cleanup()
|
||||
err = operation.Cleanup(cleanupMakeDepends)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform cleanup for operation: %s", err)
|
||||
}
|
||||
@ -300,12 +299,11 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
||||
}
|
||||
|
||||
operation = &BPMOperation{
|
||||
Actions: make([]OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
Changes: make(map[string]string),
|
||||
RootDir: rootDir,
|
||||
ForceInstallationReason: InstallationReasonUnknown,
|
||||
compiledPackages: make(map[string]string),
|
||||
Actions: make([]OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
Changes: make(map[string]string),
|
||||
RootDir: rootDir,
|
||||
compiledPackages: make(map[string]string),
|
||||
}
|
||||
|
||||
// Search for packages
|
||||
@ -328,8 +326,8 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
||||
comparison := ComparePackageVersions(*entry.Info, *installedInfo)
|
||||
if comparison > 0 {
|
||||
operation.AppendAction(&FetchPackageAction{
|
||||
IsDependency: false,
|
||||
DatabaseEntry: entry,
|
||||
InstallationReason: GetInstallationReason(pkg, rootDir),
|
||||
DatabaseEntry: entry,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,11 @@ import (
|
||||
)
|
||||
|
||||
type BPMOperation struct {
|
||||
Actions []OperationAction
|
||||
UnresolvedDepends []string
|
||||
Changes map[string]string
|
||||
RootDir string
|
||||
ForceInstallationReason InstallationReason
|
||||
compiledPackages map[string]string
|
||||
Actions []OperationAction
|
||||
UnresolvedDepends []string
|
||||
Changes map[string]string
|
||||
RootDir string
|
||||
compiledPackages map[string]string
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) ActionsContainPackage(pkg string) bool {
|
||||
@ -139,11 +138,11 @@ func (operation *BPMOperation) ResolveDependencies(reinstallDependencies, instal
|
||||
continue
|
||||
}
|
||||
|
||||
resolved, unresolved := ResolvePackageDependenciesFromDatabases(pkgInfo, pkgInfo.Type == "source", installOptionalDependencies, !reinstallDependencies, verbose, operation.RootDir)
|
||||
resolved, unresolved := ResolveAllPackageDependenciesFromDatabases(pkgInfo, pkgInfo.Type == "source", installOptionalDependencies, !reinstallDependencies, verbose, operation.RootDir)
|
||||
|
||||
operation.UnresolvedDepends = append(operation.UnresolvedDepends, unresolved...)
|
||||
|
||||
for _, depend := range resolved {
|
||||
for depend, installationReason := range resolved {
|
||||
if !operation.ActionsContainPackage(depend) && depend != pkgInfo.Name {
|
||||
if !reinstallDependencies && IsPackageInstalled(depend, operation.RootDir) {
|
||||
continue
|
||||
@ -153,8 +152,8 @@ func (operation *BPMOperation) ResolveDependencies(reinstallDependencies, instal
|
||||
return errors.New("could not get database entry for package (" + depend + ")")
|
||||
}
|
||||
operation.InsertActionAt(pos, &FetchPackageAction{
|
||||
IsDependency: true,
|
||||
DatabaseEntry: entry,
|
||||
InstallationReason: installationReason,
|
||||
DatabaseEntry: entry,
|
||||
})
|
||||
pos++
|
||||
}
|
||||
@ -192,7 +191,7 @@ func (operation *BPMOperation) RemoveNeededPackages() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) Cleanup() error {
|
||||
func (operation *BPMOperation) Cleanup(cleanupMakeDepends bool) error {
|
||||
// Get all installed packages
|
||||
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
||||
if err != nil {
|
||||
@ -228,7 +227,7 @@ func (operation *BPMOperation) Cleanup() error {
|
||||
}
|
||||
|
||||
keepPackages = append(keepPackages, pkg.Name)
|
||||
resolved := pkg.GetAllDependencies(false, true, operation.RootDir)
|
||||
resolved := pkg.GetAllDependencies(!cleanupMakeDepends, true, operation.RootDir)
|
||||
for _, value := range resolved {
|
||||
if !slices.Contains(keepPackages, value) {
|
||||
keepPackages = append(keepPackages, value)
|
||||
@ -336,12 +335,15 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
||||
|
||||
for _, value := range operation.Actions {
|
||||
var pkgInfo *PackageInfo
|
||||
var installationReason = InstallationReasonUnknown
|
||||
if value.GetActionType() == "install" {
|
||||
installationReason = value.(*InstallPackageAction).InstallationReason
|
||||
pkgInfo = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||
if value.(*InstallPackageAction).SplitPackageToInstall != "" {
|
||||
pkgInfo = pkgInfo.GetSplitPackageInfo(value.(*InstallPackageAction).SplitPackageToInstall)
|
||||
}
|
||||
} else if value.GetActionType() == "fetch" {
|
||||
installationReason = value.(*FetchPackageAction).InstallationReason
|
||||
pkgInfo = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||
} else {
|
||||
pkgInfo = value.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||
@ -350,21 +352,32 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
||||
}
|
||||
|
||||
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||
sourceInfo := ""
|
||||
additionalInfo := ""
|
||||
switch installationReason {
|
||||
case InstallationReasonManual:
|
||||
additionalInfo = "(Manual)"
|
||||
case InstallationReasonDependency:
|
||||
additionalInfo = "(Dependency)"
|
||||
case InstallationReasonMakeDependency:
|
||||
additionalInfo = "(Make dependency)"
|
||||
default:
|
||||
additionalInfo = "(Unknown)"
|
||||
}
|
||||
|
||||
if pkgInfo.Type == "source" {
|
||||
sourceInfo = "(From Source)"
|
||||
additionalInfo += " (From Source)"
|
||||
}
|
||||
|
||||
if installedInfo == nil {
|
||||
fmt.Printf("%s: %s (Install) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo)
|
||||
fmt.Printf("%s: %s (Install) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), additionalInfo)
|
||||
} else {
|
||||
comparison := ComparePackageVersions(*pkgInfo, *installedInfo)
|
||||
if comparison < 0 {
|
||||
fmt.Printf("%s: %s -> %s (Downgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo)
|
||||
fmt.Printf("%s: %s -> %s (Downgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), additionalInfo)
|
||||
} else if comparison > 0 {
|
||||
fmt.Printf("%s: %s -> %s (Upgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo)
|
||||
fmt.Printf("%s: %s -> %s (Upgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), additionalInfo)
|
||||
} else {
|
||||
fmt.Printf("%s: %s (Reinstall) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo)
|
||||
fmt.Printf("%s: %s (Reinstall) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), additionalInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -465,15 +478,15 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
if bpmpkg.PkgInfo.IsSplitPackage() {
|
||||
operation.Actions[i] = &InstallPackageAction{
|
||||
File: fetchedPackages[entry.Download],
|
||||
IsDependency: action.(*FetchPackageAction).IsDependency,
|
||||
InstallationReason: action.(*FetchPackageAction).InstallationReason,
|
||||
BpmPackage: bpmpkg,
|
||||
SplitPackageToInstall: entry.Info.Name,
|
||||
}
|
||||
} else {
|
||||
operation.Actions[i] = &InstallPackageAction{
|
||||
File: fetchedPackages[entry.Download],
|
||||
IsDependency: action.(*FetchPackageAction).IsDependency,
|
||||
BpmPackage: bpmpkg,
|
||||
File: fetchedPackages[entry.Download],
|
||||
InstallationReason: action.(*FetchPackageAction).InstallationReason,
|
||||
BpmPackage: bpmpkg,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -553,7 +566,7 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if value.IsDependency {
|
||||
if value.InstallationReason != InstallationReasonManual {
|
||||
err = installPackage(fileToInstall, operation.RootDir, verbose, true)
|
||||
} else {
|
||||
err = installPackage(fileToInstall, operation.RootDir, verbose, force)
|
||||
@ -561,13 +574,8 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
||||
}
|
||||
if operation.ForceInstallationReason != InstallationReasonUnknown && !value.IsDependency {
|
||||
err := SetInstallationReason(bpmpkg.PkgInfo.Name, operation.ForceInstallationReason, operation.RootDir)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
||||
}
|
||||
} else if value.IsDependency && !isReinstall {
|
||||
err := SetInstallationReason(bpmpkg.PkgInfo.Name, InstallationReasonDependency, operation.RootDir)
|
||||
if !isReinstall {
|
||||
err := SetInstallationReason(bpmpkg.PkgInfo.Name, value.InstallationReason, operation.RootDir)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
||||
}
|
||||
@ -586,7 +594,7 @@ type OperationAction interface {
|
||||
|
||||
type InstallPackageAction struct {
|
||||
File string
|
||||
IsDependency bool
|
||||
InstallationReason InstallationReason
|
||||
SplitPackageToInstall string
|
||||
BpmPackage *BPMPackage
|
||||
}
|
||||
@ -596,8 +604,8 @@ func (action *InstallPackageAction) GetActionType() string {
|
||||
}
|
||||
|
||||
type FetchPackageAction struct {
|
||||
IsDependency bool
|
||||
DatabaseEntry *BPMDatabaseEntry
|
||||
InstallationReason InstallationReason
|
||||
DatabaseEntry *BPMDatabaseEntry
|
||||
}
|
||||
|
||||
func (action *FetchPackageAction) GetActionType() string {
|
||||
|
@ -92,9 +92,10 @@ func (pkgInfo *PackageInfo) GetSplitPackageInfo(splitPkg string) *PackageInfo {
|
||||
type InstallationReason string
|
||||
|
||||
const (
|
||||
InstallationReasonManual InstallationReason = "manual"
|
||||
InstallationReasonDependency InstallationReason = "dependency"
|
||||
InstallationReasonUnknown InstallationReason = "unknown"
|
||||
InstallationReasonManual InstallationReason = "manual"
|
||||
InstallationReasonDependency InstallationReason = "dependency"
|
||||
InstallationReasonMakeDependency InstallationReason = "make_dependency"
|
||||
InstallationReasonUnknown InstallationReason = "unknown"
|
||||
)
|
||||
|
||||
func ComparePackageVersions(info1, info2 PackageInfo) int {
|
||||
@ -119,6 +120,8 @@ func GetInstallationReason(pkg, rootDir string) InstallationReason {
|
||||
return InstallationReasonManual
|
||||
} else if reason == "dependency" {
|
||||
return InstallationReasonDependency
|
||||
} else if reason == "make_dependency" {
|
||||
return InstallationReasonMakeDependency
|
||||
}
|
||||
return InstallationReasonUnknown
|
||||
}
|
||||
@ -524,7 +527,19 @@ func CreateReadableInfo(showArchitecture, showType, showPackageRelations, showIn
|
||||
appendArray("Split Packages", splitPkgs)
|
||||
}
|
||||
if IsPackageInstalled(pkgInfo.Name, rootDir) && showInstallationReason {
|
||||
ret = append(ret, "Installation Reason: "+string(GetInstallationReason(pkgInfo.Name, rootDir)))
|
||||
installationReason := GetInstallationReason(pkgInfo.Name, rootDir)
|
||||
var installationReasonString string
|
||||
switch installationReason {
|
||||
case InstallationReasonManual:
|
||||
installationReasonString = "Manual"
|
||||
case InstallationReasonDependency:
|
||||
installationReasonString = "Dependency"
|
||||
case InstallationReasonMakeDependency:
|
||||
installationReasonString = "Make dependency"
|
||||
default:
|
||||
installationReasonString = "Unknown"
|
||||
}
|
||||
ret = append(ret, "Installation Reason: "+installationReasonString)
|
||||
}
|
||||
return strings.Join(ret, "\n")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user