mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Remove all log.Fatal and os.Exit calls from bpmlib
This commit is contained in:
+12
-7
@@ -2,7 +2,6 @@ package bpmlib
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -17,14 +16,16 @@ type BPMConfigStruct struct {
|
||||
|
||||
var BPMConfig BPMConfigStruct
|
||||
|
||||
func ReadConfig() {
|
||||
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||
log.Fatal(err)
|
||||
func ReadConfig() (err error) {
|
||||
if _, err = os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile("/etc/bpm.conf")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
BPMConfig = BPMConfigStruct{
|
||||
CompilationEnv: make([]string, 0),
|
||||
SilentCompilation: false,
|
||||
@@ -33,19 +34,23 @@ func ReadConfig() {
|
||||
}
|
||||
err = yaml.Unmarshal(bytes, &BPMConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
||||
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
||||
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
for _, repo := range BPMConfig.Repositories {
|
||||
repo.Entries = make(map[string]*RepositoryEntry)
|
||||
repo.VirtualPackages = make(map[string][]string)
|
||||
err := repo.ReadLocalDatabase()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -179,7 +179,10 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
||||
}
|
||||
|
||||
// Reload config and local databases
|
||||
ReadConfig()
|
||||
err = ReadConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read BPM config: %s", err)
|
||||
}
|
||||
|
||||
// Get installed packages and check for updates
|
||||
pkgs, err := GetInstalledPackages(rootDir)
|
||||
|
||||
@@ -195,7 +195,7 @@ func (operation *BPMOperation) Cleanup(verbose bool) error {
|
||||
// Get all installed packages
|
||||
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not get installed packages: %s\n", err)
|
||||
return fmt.Errorf("could not get installed packages: %s", err)
|
||||
}
|
||||
installedPackages := make([]*PackageInfo, len(installedPackageNames))
|
||||
for i, value := range installedPackageNames {
|
||||
@@ -329,8 +329,8 @@ func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error)
|
||||
|
||||
func (operation *BPMOperation) ShowOperationSummary() {
|
||||
if len(operation.Actions) == 0 {
|
||||
fmt.Println("All packages are up to date!")
|
||||
os.Exit(0)
|
||||
fmt.Println("No action needs to be taken")
|
||||
return
|
||||
}
|
||||
|
||||
for _, value := range operation.Actions {
|
||||
@@ -348,9 +348,6 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
||||
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||
sourceInfo := ""
|
||||
if pkgInfo.Type == "source" {
|
||||
if operation.RootDir != "/" {
|
||||
log.Fatalf("cannot compile and install source packages to a different root directory")
|
||||
}
|
||||
sourceInfo = "(From Source)"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user