Reorganize codebase #10
@ -214,12 +214,12 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if installationReason argument is valid
|
// Check if installationReason argument is valid
|
||||||
ir := bpmlib.Unknown
|
ir := bpmlib.InstallationReasonUnknown
|
||||||
switch installationReason {
|
switch installationReason {
|
||||||
case "manual":
|
case "manual":
|
||||||
ir = bpmlib.Manual
|
ir = bpmlib.InstallationReasonManual
|
||||||
case "dependency":
|
case "dependency":
|
||||||
ir = bpmlib.Dependency
|
ir = bpmlib.InstallationReasonDependency
|
||||||
case "":
|
case "":
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Error: %s is not a valid installation reason", installationReason)
|
log.Fatalf("Error: %s is not a valid installation reason", installationReason)
|
||||||
|
@ -185,7 +185,7 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
|||||||
UnresolvedDepends: make([]string, 0),
|
UnresolvedDepends: make([]string, 0),
|
||||||
Changes: make(map[string]string),
|
Changes: make(map[string]string),
|
||||||
RootDir: rootDir,
|
RootDir: rootDir,
|
||||||
ForceInstallationReason: Unknown,
|
ForceInstallationReason: InstallationReasonUnknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for packages
|
// Search for packages
|
||||||
|
@ -217,7 +217,7 @@ func (operation *BPMOperation) Cleanup(verbose bool) error {
|
|||||||
// Get manually installed packages, resolve all their dependencies and add them to the keepPackages slice
|
// Get manually installed packages, resolve all their dependencies and add them to the keepPackages slice
|
||||||
keepPackages := make([]string, 0)
|
keepPackages := make([]string, 0)
|
||||||
for _, pkg := range slices.Clone(installedPackages) {
|
for _, pkg := range slices.Clone(installedPackages) {
|
||||||
if GetInstallationReason(pkg.Name, operation.RootDir) != Manual {
|
if GetInstallationReason(pkg.Name, operation.RootDir) != InstallationReasonManual {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,13 +475,13 @@ func (operation *BPMOperation) Execute(verbose, force bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
||||||
}
|
}
|
||||||
if operation.ForceInstallationReason != Unknown && !value.IsDependency {
|
if operation.ForceInstallationReason != InstallationReasonUnknown && !value.IsDependency {
|
||||||
err := SetInstallationReason(bpmpkg.PkgInfo.Name, operation.ForceInstallationReason, operation.RootDir)
|
err := SetInstallationReason(bpmpkg.PkgInfo.Name, operation.ForceInstallationReason, operation.RootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
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 {
|
} else if value.IsDependency && !isReinstall {
|
||||||
err := SetInstallationReason(bpmpkg.PkgInfo.Name, Dependency, operation.RootDir)
|
err := SetInstallationReason(bpmpkg.PkgInfo.Name, InstallationReasonDependency, operation.RootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,9 @@ func (pkgInfo *PackageInfo) GetFullVersion() string {
|
|||||||
type InstallationReason string
|
type InstallationReason string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Manual InstallationReason = "manual"
|
InstallationReasonManual InstallationReason = "manual"
|
||||||
Dependency InstallationReason = "dependency"
|
InstallationReasonDependency InstallationReason = "dependency"
|
||||||
Unknown InstallationReason = "unknown"
|
InstallationReasonUnknown InstallationReason = "unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ComparePackageVersions(info1, info2 PackageInfo) int {
|
func ComparePackageVersions(info1, info2 PackageInfo) int {
|
||||||
@ -90,19 +90,19 @@ func GetInstallationReason(pkg, rootDir string) InstallationReason {
|
|||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
if stat, err := os.Stat(path.Join(pkgDir, "installation_reason")); err != nil || stat.IsDir() {
|
if stat, err := os.Stat(path.Join(pkgDir, "installation_reason")); err != nil || stat.IsDir() {
|
||||||
return Manual
|
return InstallationReasonManual
|
||||||
}
|
}
|
||||||
b, err := os.ReadFile(path.Join(pkgDir, "installation_reason"))
|
b, err := os.ReadFile(path.Join(pkgDir, "installation_reason"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Unknown
|
return InstallationReasonUnknown
|
||||||
}
|
}
|
||||||
reason := strings.TrimSpace(string(b))
|
reason := strings.TrimSpace(string(b))
|
||||||
if reason == "manual" {
|
if reason == "manual" {
|
||||||
return Manual
|
return InstallationReasonManual
|
||||||
} else if reason == "dependency" {
|
} else if reason == "dependency" {
|
||||||
return Dependency
|
return InstallationReasonDependency
|
||||||
}
|
}
|
||||||
return Unknown
|
return InstallationReasonUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetInstallationReason(pkg string, reason InstallationReason, rootDir string) error {
|
func SetInstallationReason(pkg string, reason InstallationReason, rootDir string) error {
|
||||||
@ -280,15 +280,15 @@ func ReadPackageScripts(filename string) (map[string]string, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Operation uint8
|
type packageOperation uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Install Operation = 0
|
packageOperationInstall packageOperation = 0
|
||||||
Update = 1
|
packageOperationUpdate = 1
|
||||||
Remove = 2
|
packageOperationRemove = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
func executePackageScripts(filename, rootDir string, operation Operation, postOperation bool) error {
|
func executePackageScripts(filename, rootDir string, operation packageOperation, postOperation bool) error {
|
||||||
pkgInfo, err := ReadPackage(filename)
|
pkgInfo, err := ReadPackage(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -320,11 +320,11 @@ func executePackageScripts(filename, rootDir string, operation Operation, postOp
|
|||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.PkgInfo.Name))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.PkgInfo.Name))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.PkgInfo.Description))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.PkgInfo.Description))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.PkgInfo.Version))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.PkgInfo.Version))
|
||||||
if operation != Install {
|
if operation != packageOperationInstall {
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_OLD_VERSION=%s", GetPackageInfo(pkgInfo.PkgInfo.Name, rootDir).Version))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_OLD_VERSION=%s", GetPackageInfo(pkgInfo.PkgInfo.Name, rootDir).Version))
|
||||||
}
|
}
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", pkgInfo.PkgInfo.Revision))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", pkgInfo.PkgInfo.Revision))
|
||||||
if operation != Install {
|
if operation != packageOperationInstall {
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_OLD_REVISION=%d", GetPackageInfo(pkgInfo.PkgInfo.Name, rootDir).Revision))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_OLD_REVISION=%d", GetPackageInfo(pkgInfo.PkgInfo.Name, rootDir).Revision))
|
||||||
}
|
}
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.PkgInfo.Url))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.PkgInfo.Url))
|
||||||
@ -349,7 +349,7 @@ func executePackageScripts(filename, rootDir string, operation Operation, postOp
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if operation == Install {
|
if operation == packageOperationInstall {
|
||||||
if val, ok := scripts["pre_install.sh"]; !postOperation && ok {
|
if val, ok := scripts["pre_install.sh"]; !postOperation && ok {
|
||||||
err := run("pre_install.sh", val)
|
err := run("pre_install.sh", val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -362,7 +362,7 @@ func executePackageScripts(filename, rootDir string, operation Operation, postOp
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if operation == Update {
|
} else if operation == packageOperationUpdate {
|
||||||
if val, ok := scripts["pre_update.sh"]; !postOperation && ok {
|
if val, ok := scripts["pre_update.sh"]; !postOperation && ok {
|
||||||
err := run("pre_update.sh", val)
|
err := run("pre_update.sh", val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -375,7 +375,7 @@ func executePackageScripts(filename, rootDir string, operation Operation, postOp
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if operation == Remove {
|
} else if operation == packageOperationRemove {
|
||||||
if val, ok := scripts["pre_remove.sh"]; !postOperation && ok {
|
if val, ok := scripts["pre_remove.sh"]; !postOperation && ok {
|
||||||
err := run("pre_remove.sh", val)
|
err := run("pre_remove.sh", val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -478,12 +478,12 @@ func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, p
|
|||||||
|
|
||||||
func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string) error {
|
func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string) error {
|
||||||
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||||
err := executePackageScripts(filename, rootDir, Install, false)
|
err := executePackageScripts(filename, rootDir, packageOperationInstall, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := executePackageScripts(filename, rootDir, Update, false)
|
err := executePackageScripts(filename, rootDir, packageOperationUpdate, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -629,12 +629,12 @@ func isSplitPackage(filename string) bool {
|
|||||||
func compilePackage(bpmpkg *BPMPackage, filename, rootDir string, verbose, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) {
|
func compilePackage(bpmpkg *BPMPackage, filename, rootDir string, verbose, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) {
|
||||||
var files []string
|
var files []string
|
||||||
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||||
err := executePackageScripts(filename, rootDir, Install, false)
|
err := executePackageScripts(filename, rootDir, packageOperationInstall, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := executePackageScripts(filename, rootDir, Update, false)
|
err := executePackageScripts(filename, rootDir, packageOperationUpdate, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
@ -747,12 +747,12 @@ func compilePackage(bpmpkg *BPMPackage, filename, rootDir string, verbose, binar
|
|||||||
}
|
}
|
||||||
fmt.Println("Running source.sh file...")
|
fmt.Println("Running source.sh file...")
|
||||||
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||||
err = executePackageScripts(filename, rootDir, Install, false)
|
err = executePackageScripts(filename, rootDir, packageOperationInstall, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = executePackageScripts(filename, rootDir, Update, false)
|
err = executePackageScripts(filename, rootDir, packageOperationUpdate, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
@ -1246,12 +1246,12 @@ func installPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !packageInstalled {
|
if !packageInstalled {
|
||||||
err = executePackageScripts(filename, rootDir, Install, true)
|
err = executePackageScripts(filename, rootDir, packageOperationInstall, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = executePackageScripts(filename, rootDir, Update, true)
|
err = executePackageScripts(filename, rootDir, packageOperationUpdate, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user