mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36: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"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -13,6 +12,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* -------------BPM | Bubble Package Manager-------------- */
|
/* -------------BPM | Bubble Package Manager-------------- */
|
||||||
@@ -250,7 +251,7 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if installationReason argument is valid
|
// Check if installationReason argument is valid
|
||||||
ir := bpmlib.InstallationReasonManual
|
ir := bpmlib.InstallationReasonUnknown
|
||||||
switch installationReason {
|
switch installationReason {
|
||||||
case "manual":
|
case "manual":
|
||||||
ir = bpmlib.InstallationReasonManual
|
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
|
// 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
|
// Setup operation struct
|
||||||
operation = &BPMOperation{
|
operation = &BPMOperation{
|
||||||
Actions: make([]OperationAction, 0),
|
Actions: make([]OperationAction, 0),
|
||||||
@@ -44,6 +45,16 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
continue
|
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{
|
operation.AppendAction(&InstallPackageAction{
|
||||||
File: pkg,
|
File: pkg,
|
||||||
InstallationReason: installationReason,
|
InstallationReason: installationReason,
|
||||||
@@ -58,6 +69,16 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
continue
|
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{
|
operation.AppendAction(&InstallPackageAction{
|
||||||
File: pkg,
|
File: pkg,
|
||||||
InstallationReason: installationReason,
|
InstallationReason: installationReason,
|
||||||
@@ -84,6 +105,16 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
continue
|
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{
|
operation.AppendAction(&FetchPackageAction{
|
||||||
InstallationReason: installationReason,
|
InstallationReason: installationReason,
|
||||||
DatabaseEntry: entry,
|
DatabaseEntry: entry,
|
||||||
|
|||||||
+12
-12
@@ -287,7 +287,7 @@ func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error)
|
|||||||
for i, value := range installedPackages {
|
for i, value := range installedPackages {
|
||||||
bpmpkg := GetPackage(value, operation.RootDir)
|
bpmpkg := GetPackage(value, operation.RootDir)
|
||||||
if bpmpkg == nil {
|
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
|
allPackages[i] = bpmpkg.PkgInfo
|
||||||
}
|
}
|
||||||
@@ -452,13 +452,13 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
|||||||
// Fetch package from database
|
// Fetch package from database
|
||||||
fetchedPackage, err := entry.Database.FetchPackage(entry.Info.Name)
|
fetchedPackage, err := entry.Database.FetchPackage(entry.Info.Name)
|
||||||
if err != nil {
|
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
|
// Read fetched package
|
||||||
bpmpkg, err = ReadPackage(fetchedPackage)
|
bpmpkg, err = ReadPackage(fetchedPackage)
|
||||||
if err != nil {
|
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
|
// Add fetched package to map
|
||||||
@@ -469,7 +469,7 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
|||||||
// Read fetched package
|
// Read fetched package
|
||||||
bpmpkg, err = ReadPackage(fetchedPackages[entry.Download])
|
bpmpkg, err = ReadPackage(fetchedPackages[entry.Download])
|
||||||
if err != nil {
|
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)
|
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
|
pkgInfo := action.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||||
err := removePackage(pkgInfo.Name, verbose, operation.RootDir)
|
err := removePackage(pkgInfo.Name, verbose, operation.RootDir)
|
||||||
if err != nil {
|
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" {
|
} else if action.GetActionType() == "install" {
|
||||||
value := action.(*InstallPackageAction)
|
value := action.(*InstallPackageAction)
|
||||||
fileToInstall := value.File
|
fileToInstall := value.File
|
||||||
bpmpkg := value.BpmPackage
|
bpmpkg := value.BpmPackage
|
||||||
isReinstall := IsPackageInstalled(bpmpkg.PkgInfo.Name, operation.RootDir)
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Compile package if type is 'source'
|
// 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)
|
err = installPackage(fileToInstall, operation.RootDir, verbose, force)
|
||||||
}
|
}
|
||||||
if err != nil {
|
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)
|
// Set installed package's installation reason
|
||||||
if err != nil {
|
err = SetInstallationReason(bpmpkg.PkgInfo.Name, value.InstallationReason, operation.RootDir)
|
||||||
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
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)
|
fmt.Printf("Package (%s) was successfully installed\n", bpmpkg.PkgInfo.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user