mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 02:26:12 +00:00
Fix package installation reason not being displayed or set correctly
This commit is contained in:
+3
-2
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -13,6 +12,8 @@ import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
||||
)
|
||||
|
||||
/* -------------BPM | Bubble Package Manager-------------- */
|
||||
@@ -250,7 +251,7 @@ func resolveCommand() {
|
||||
}
|
||||
|
||||
// Check if installationReason argument is valid
|
||||
ir := bpmlib.InstallationReasonManual
|
||||
ir := bpmlib.InstallationReasonUnknown
|
||||
switch installationReason {
|
||||
case "manual":
|
||||
ir = bpmlib.InstallationReasonManual
|
||||
|
||||
+32
-1
@@ -19,7 +19,8 @@ const (
|
||||
)
|
||||
|
||||
// InstallPackages installs the specified packages into the given root directory by fetching them from databases or directly from local bpm archives
|
||||
func InstallPackages(rootDir string, installationReason InstallationReason, reinstallMethod ReinstallMethod, installOptionalDependencies, forceInstallation, verbose bool, packages ...string) (operation *BPMOperation, err error) {
|
||||
func InstallPackages(rootDir string, forceInstallationReason InstallationReason, reinstallMethod ReinstallMethod, installOptionalDependencies, forceInstallation, verbose bool, packages ...string) (operation *BPMOperation, err error) {
|
||||
|
||||
// Setup operation struct
|
||||
operation = &BPMOperation{
|
||||
Actions: make([]OperationAction, 0),
|
||||
@@ -44,6 +45,16 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
||||
continue
|
||||
}
|
||||
|
||||
// Set package installation reason
|
||||
installationReason := forceInstallationReason
|
||||
if installationReason == InstallationReasonUnknown {
|
||||
if IsPackageInstalled(splitPkg.Name, rootDir) {
|
||||
installationReason = GetInstallationReason(splitPkg.Name, rootDir)
|
||||
} else {
|
||||
installationReason = InstallationReasonManual
|
||||
}
|
||||
}
|
||||
|
||||
operation.AppendAction(&InstallPackageAction{
|
||||
File: pkg,
|
||||
InstallationReason: installationReason,
|
||||
@@ -58,6 +69,16 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
||||
continue
|
||||
}
|
||||
|
||||
// Set package installation reason
|
||||
installationReason := forceInstallationReason
|
||||
if installationReason == InstallationReasonUnknown {
|
||||
if IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||
installationReason = GetInstallationReason(bpmpkg.PkgInfo.Name, rootDir)
|
||||
} else {
|
||||
installationReason = InstallationReasonManual
|
||||
}
|
||||
}
|
||||
|
||||
operation.AppendAction(&InstallPackageAction{
|
||||
File: pkg,
|
||||
InstallationReason: installationReason,
|
||||
@@ -84,6 +105,16 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
||||
continue
|
||||
}
|
||||
|
||||
// Set package installation reason
|
||||
installationReason := forceInstallationReason
|
||||
if installationReason == InstallationReasonUnknown {
|
||||
if IsPackageInstalled(entry.Info.Name, rootDir) {
|
||||
installationReason = GetInstallationReason(entry.Info.Name, rootDir)
|
||||
} else {
|
||||
installationReason = InstallationReasonManual
|
||||
}
|
||||
}
|
||||
|
||||
operation.AppendAction(&FetchPackageAction{
|
||||
InstallationReason: installationReason,
|
||||
DatabaseEntry: entry,
|
||||
|
||||
+12
-12
@@ -287,7 +287,7 @@ func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error)
|
||||
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))
|
||||
return nil, fmt.Errorf("could not find installed package (%s)", value)
|
||||
}
|
||||
allPackages[i] = bpmpkg.PkgInfo
|
||||
}
|
||||
@@ -452,13 +452,13 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
// Fetch package from database
|
||||
fetchedPackage, err := entry.Database.FetchPackage(entry.Info.Name)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not fetch package (%s): %s\n", entry.Info.Name, err))
|
||||
return fmt.Errorf("could not fetch package (%s): %s\n", entry.Info.Name, err)
|
||||
}
|
||||
|
||||
// Read fetched package
|
||||
bpmpkg, err = ReadPackage(fetchedPackage)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not fetch package (%s): %s\n", entry.Info.Name, err))
|
||||
return fmt.Errorf("could not fetch package (%s): %s\n", entry.Info.Name, err)
|
||||
}
|
||||
|
||||
// Add fetched package to map
|
||||
@@ -469,7 +469,7 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
// Read fetched package
|
||||
bpmpkg, err = ReadPackage(fetchedPackages[entry.Download])
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not read package (%s): %s\n", entry.Info.Name, err))
|
||||
return fmt.Errorf("could not read package (%s): %s\n", entry.Info.Name, err)
|
||||
}
|
||||
|
||||
fmt.Printf("Package (%s) was successfully fetched!\n", entry.Info.Name)
|
||||
@@ -517,13 +517,12 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
pkgInfo := action.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||
err := removePackage(pkgInfo.Name, verbose, operation.RootDir)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not remove package (%s): %s\n", pkgInfo.Name, err))
|
||||
return fmt.Errorf("could not remove package (%s): %s\n", pkgInfo.Name, err)
|
||||
}
|
||||
} else if action.GetActionType() == "install" {
|
||||
value := action.(*InstallPackageAction)
|
||||
fileToInstall := value.File
|
||||
bpmpkg := value.BpmPackage
|
||||
isReinstall := IsPackageInstalled(bpmpkg.PkgInfo.Name, operation.RootDir)
|
||||
var err error
|
||||
|
||||
// Compile package if type is 'source'
|
||||
@@ -572,14 +571,15 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||
err = installPackage(fileToInstall, operation.RootDir, verbose, force)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
||||
return fmt.Errorf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err)
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
// Set installed package's installation reason
|
||||
err = SetInstallationReason(bpmpkg.PkgInfo.Name, value.InstallationReason, operation.RootDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err)
|
||||
}
|
||||
|
||||
fmt.Printf("Package (%s) was successfully installed\n", bpmpkg.PkgInfo.Name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user