Compare commits

...

5 Commits

14 changed files with 120 additions and 104 deletions

View File

@ -15,7 +15,7 @@ endif
build: build:
mkdir -p build mkdir -p build
$(GO) build -ldflags "-w" -o build/bpm gitlab.com/bubble-package-manager/bpm cd src/bpm; $(GO) build -ldflags "-w" -o ../../build/bpm git.enumerated.dev/bubble-package-manager/bpm/src/bpm
install: build/bpm config/ install: build/bpm config/
mkdir -p $(DESTDIR)$(BINDIR) mkdir -p $(DESTDIR)$(BINDIR)

9
go.mod
View File

@ -1,9 +0,0 @@
module gitlab.com/bubble-package-manager/bpm
go 1.22
require (
github.com/elliotchance/orderedmap/v2 v2.4.0 // indirect
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

14
src/bpm/go.mod Normal file
View File

@ -0,0 +1,14 @@
module git.enumerated.dev/bubble-package-manager/bpm/src/bpm
go 1.23
toolchain go1.23.7
require git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib v0.5.0
replace git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib => ../bpmlib
require (
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@ -1,9 +1,6 @@
github.com/elliotchance/orderedmap/v2 v2.4.0 h1:6tUmMwD9F998FNpwFxA5E6NQvSpk2PVw7RKsVq3+2Cw=
github.com/elliotchance/orderedmap/v2 v2.4.0/go.mod h1:85lZyVbpGaGvHvnKa7Qhx7zncAdBIBq6u56Hb1PRU5Q=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g= github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0= github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -4,7 +4,7 @@ import (
"bufio" "bufio"
"flag" "flag"
"fmt" "fmt"
"gitlab.com/bubble-package-manager/bpm/utils" "git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -42,7 +42,7 @@ var doCleanup = false
var showRepoInfo = false var showRepoInfo = false
func main() { func main() {
utils.ReadConfig() bpmlib.ReadConfig()
resolveFlags() resolveFlags()
resolveCommand() resolveCommand()
} }
@ -102,30 +102,30 @@ func resolveCommand() {
return return
} }
for n, pkg := range packages { for n, pkg := range packages {
var info *utils.PackageInfo var info *bpmlib.PackageInfo
isFile := false isFile := false
if showRepoInfo { if showRepoInfo {
var err error var err error
var entry *utils.RepositoryEntry var entry *bpmlib.RepositoryEntry
entry, _, err = utils.GetRepositoryEntry(pkg) entry, _, err = bpmlib.GetRepositoryEntry(pkg)
if err != nil { if err != nil {
if entry = utils.ResolveVirtualPackage(pkg); entry == nil { if entry = bpmlib.ResolveVirtualPackage(pkg); entry == nil {
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg) log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
} }
} }
info = entry.Info info = entry.Info
} else if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() { } else if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
bpmpkg, err := utils.ReadPackage(pkg) bpmpkg, err := bpmlib.ReadPackage(pkg)
if err != nil { if err != nil {
log.Fatalf("Error: could not read package: %s\n", err) log.Fatalf("Error: could not read package: %s\n", err)
} }
info = bpmpkg.PkgInfo info = bpmpkg.PkgInfo
isFile = true isFile = true
} else { } else {
if isVirtual, p := utils.IsVirtualPackage(pkg, rootDir); isVirtual { if isVirtual, p := bpmlib.IsVirtualPackage(pkg, rootDir); isVirtual {
info = utils.GetPackageInfo(p, rootDir) info = bpmlib.GetPackageInfo(p, rootDir)
} else { } else {
info = utils.GetPackageInfo(pkg, rootDir) info = bpmlib.GetPackageInfo(pkg, rootDir)
} }
} }
if info == nil { if info == nil {
@ -141,10 +141,10 @@ func resolveCommand() {
} }
fmt.Println("File: " + abs) fmt.Println("File: " + abs)
} }
fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir)) fmt.Println(bpmlib.CreateReadableInfo(true, true, true, info, rootDir))
} }
case list: case list:
packages, err := utils.GetInstalledPackages(rootDir) packages, err := bpmlib.GetInstalledPackages(rootDir)
if err != nil { if err != nil {
log.Fatalf("Error: could not get installed packages: %s", err.Error()) log.Fatalf("Error: could not get installed packages: %s", err.Error())
return return
@ -161,7 +161,7 @@ func resolveCommand() {
return return
} }
for n, pkg := range packages { for n, pkg := range packages {
info := utils.GetPackageInfo(pkg, rootDir) info := bpmlib.GetPackageInfo(pkg, rootDir)
if info == nil { if info == nil {
fmt.Printf("Package (%s) could not be found\n", pkg) fmt.Printf("Package (%s) could not be found\n", pkg)
continue continue
@ -169,7 +169,7 @@ func resolveCommand() {
if n != 0 { if n != 0 {
fmt.Println() fmt.Println()
} }
fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir)) fmt.Println(bpmlib.CreateReadableInfo(true, true, true, info, rootDir))
} }
} }
case search: case search:
@ -178,9 +178,9 @@ func resolveCommand() {
log.Fatalf("Error: no search terms given") log.Fatalf("Error: no search terms given")
} }
for i, term := range searchTerms { for i, term := range searchTerms {
nameResults := make([]*utils.PackageInfo, 0) nameResults := make([]*bpmlib.PackageInfo, 0)
descResults := make([]*utils.PackageInfo, 0) descResults := make([]*bpmlib.PackageInfo, 0)
for _, repo := range utils.BPMConfig.Repositories { for _, repo := range bpmlib.BPMConfig.Repositories {
for _, entry := range repo.Entries { for _, entry := range repo.Entries {
if strings.Contains(entry.Info.Name, term) { if strings.Contains(entry.Info.Name, term) {
nameResults = append(nameResults, entry.Info) nameResults = append(nameResults, entry.Info)
@ -212,17 +212,17 @@ func resolveCommand() {
} }
// Check if installationReason argument is valid // Check if installationReason argument is valid
ir := utils.Unknown ir := bpmlib.Unknown
if installationReason == "manual" { if installationReason == "manual" {
ir = utils.Manual ir = bpmlib.Manual
} else if installationReason == "dependency" { } else if installationReason == "dependency" {
ir = utils.Dependency ir = bpmlib.Dependency
} else if installationReason != "" { } else if installationReason != "" {
log.Fatalf("Error: %s is not a valid installation reason", installationReason) log.Fatalf("Error: %s is not a valid installation reason", installationReason)
} }
operation := utils.BPMOperation{ operation := bpmlib.BPMOperation{
Actions: make([]utils.OperationAction, 0), Actions: make([]bpmlib.OperationAction, 0),
UnresolvedDepends: make([]string, 0), UnresolvedDepends: make([]string, 0),
Changes: make(map[string]string), Changes: make(map[string]string),
RootDir: rootDir, RootDir: rootDir,
@ -232,37 +232,37 @@ func resolveCommand() {
// Search for packages // Search for packages
for _, pkg := range pkgs { for _, pkg := range pkgs {
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() { if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
bpmpkg, err := utils.ReadPackage(pkg) bpmpkg, err := bpmlib.ReadPackage(pkg)
if err != nil { if err != nil {
log.Fatalf("Error: could not read package: %s\n", err) log.Fatalf("Error: could not read package: %s\n", err)
} }
if !reinstall && utils.IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) && utils.GetPackageInfo(bpmpkg.PkgInfo.Name, rootDir).GetFullVersion() == bpmpkg.PkgInfo.GetFullVersion() { if !reinstall && bpmlib.IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) && bpmlib.GetPackageInfo(bpmpkg.PkgInfo.Name, rootDir).GetFullVersion() == bpmpkg.PkgInfo.GetFullVersion() {
continue continue
} }
operation.AppendAction(&utils.InstallPackageAction{ operation.AppendAction(&bpmlib.InstallPackageAction{
File: pkg, File: pkg,
IsDependency: false, IsDependency: false,
BpmPackage: bpmpkg, BpmPackage: bpmpkg,
}) })
} else { } else {
var entry *utils.RepositoryEntry var entry *bpmlib.RepositoryEntry
if e, _, err := utils.GetRepositoryEntry(pkg); err == nil { if e, _, err := bpmlib.GetRepositoryEntry(pkg); err == nil {
entry = e entry = e
} else if isVirtual, p := utils.IsVirtualPackage(pkg, rootDir); isVirtual { } else if isVirtual, p := bpmlib.IsVirtualPackage(pkg, rootDir); isVirtual {
entry, _, err = utils.GetRepositoryEntry(p) entry, _, err = bpmlib.GetRepositoryEntry(p)
if err != nil { if err != nil {
log.Fatalf("Error: could not find package (%s) in any repository\n", p) log.Fatalf("Error: could not find package (%s) in any repository\n", p)
} }
} else if e := utils.ResolveVirtualPackage(pkg); e != nil { } else if e := bpmlib.ResolveVirtualPackage(pkg); e != nil {
entry = e entry = e
} else { } else {
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg) log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
} }
if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir).GetFullVersion() == entry.Info.GetFullVersion() { if !reinstall && bpmlib.IsPackageInstalled(entry.Info.Name, rootDir) && bpmlib.GetPackageInfo(entry.Info.Name, rootDir).GetFullVersion() == entry.Info.GetFullVersion() {
continue continue
} }
operation.AppendAction(&utils.FetchPackageAction{ operation.AppendAction(&bpmlib.FetchPackageAction{
IsDependency: false, IsDependency: false,
RepositoryEntry: entry, RepositoryEntry: entry,
}) })
@ -342,7 +342,7 @@ func resolveCommand() {
// Sync repositories // Sync repositories
if !nosync { if !nosync {
for _, repo := range utils.BPMConfig.Repositories { for _, repo := range bpmlib.BPMConfig.Repositories {
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name) fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
err := repo.SyncLocalDatabase() err := repo.SyncLocalDatabase()
if err != nil { if err != nil {
@ -352,42 +352,42 @@ func resolveCommand() {
fmt.Println("All package databases synced successfully!") fmt.Println("All package databases synced successfully!")
} }
utils.ReadConfig() bpmlib.ReadConfig()
// Get installed packages and check for updates // Get installed packages and check for updates
pkgs, err := utils.GetInstalledPackages(rootDir) pkgs, err := bpmlib.GetInstalledPackages(rootDir)
if err != nil { if err != nil {
log.Fatalf("Error: could not get installed packages: %s\n", err) log.Fatalf("Error: could not get installed packages: %s\n", err)
} }
operation := utils.BPMOperation{ operation := bpmlib.BPMOperation{
Actions: make([]utils.OperationAction, 0), Actions: make([]bpmlib.OperationAction, 0),
UnresolvedDepends: make([]string, 0), UnresolvedDepends: make([]string, 0),
Changes: make(map[string]string), Changes: make(map[string]string),
RootDir: rootDir, RootDir: rootDir,
ForceInstallationReason: utils.Unknown, ForceInstallationReason: bpmlib.Unknown,
} }
// Search for packages // Search for packages
for _, pkg := range pkgs { for _, pkg := range pkgs {
if slices.Contains(utils.BPMConfig.IgnorePackages, pkg) { if slices.Contains(bpmlib.BPMConfig.IgnorePackages, pkg) {
continue continue
} }
var entry *utils.RepositoryEntry var entry *bpmlib.RepositoryEntry
// Check if installed package can be replaced and install that instead // Check if installed package can be replaced and install that instead
if e := utils.FindReplacement(pkg); e != nil { if e := bpmlib.FindReplacement(pkg); e != nil {
entry = e entry = e
} else if entry, _, err = utils.GetRepositoryEntry(pkg); err != nil { } else if entry, _, err = bpmlib.GetRepositoryEntry(pkg); err != nil {
continue continue
} }
installedInfo := utils.GetPackageInfo(pkg, rootDir) installedInfo := bpmlib.GetPackageInfo(pkg, rootDir)
if installedInfo == nil { if installedInfo == nil {
log.Fatalf("Error: could not get package info for (%s)\n", pkg) log.Fatalf("Error: could not get package info for (%s)\n", pkg)
} else { } else {
comparison := utils.ComparePackageVersions(*entry.Info, *installedInfo) comparison := bpmlib.ComparePackageVersions(*entry.Info, *installedInfo)
if comparison > 0 || reinstall { if comparison > 0 || reinstall {
operation.AppendAction(&utils.FetchPackageAction{ operation.AppendAction(&bpmlib.FetchPackageAction{
IsDependency: false, IsDependency: false,
RepositoryEntry: entry, RepositoryEntry: entry,
}) })
@ -450,7 +450,7 @@ func resolveCommand() {
os.Exit(1) os.Exit(1)
} }
} }
for _, repo := range utils.BPMConfig.Repositories { for _, repo := range bpmlib.BPMConfig.Repositories {
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name) fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
err := repo.SyncLocalDatabase() err := repo.SyncLocalDatabase()
if err != nil { if err != nil {
@ -468,8 +468,8 @@ func resolveCommand() {
return return
} }
operation := &utils.BPMOperation{ operation := &bpmlib.BPMOperation{
Actions: make([]utils.OperationAction, 0), Actions: make([]bpmlib.OperationAction, 0),
UnresolvedDepends: make([]string, 0), UnresolvedDepends: make([]string, 0),
Changes: make(map[string]string), Changes: make(map[string]string),
RootDir: rootDir, RootDir: rootDir,
@ -477,11 +477,11 @@ func resolveCommand() {
// Search for packages // Search for packages
for _, pkg := range packages { for _, pkg := range packages {
bpmpkg := utils.GetPackage(pkg, rootDir) bpmpkg := bpmlib.GetPackage(pkg, rootDir)
if bpmpkg == nil { if bpmpkg == nil {
continue continue
} }
operation.AppendAction(&utils.RemovePackageAction{BpmPackage: bpmpkg}) operation.AppendAction(&bpmlib.RemovePackageAction{BpmPackage: bpmpkg})
} }
// Skip needed packages if the --unused flag is on // Skip needed packages if the --unused flag is on
@ -531,8 +531,8 @@ func resolveCommand() {
log.Fatalf("Error: this subcommand needs to be run with superuser permissions") log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
} }
operation := &utils.BPMOperation{ operation := &bpmlib.BPMOperation{
Actions: make([]utils.OperationAction, 0), Actions: make([]bpmlib.OperationAction, 0),
UnresolvedDepends: make([]string, 0), UnresolvedDepends: make([]string, 0),
Changes: make(map[string]string), Changes: make(map[string]string),
RootDir: rootDir, RootDir: rootDir,
@ -585,7 +585,7 @@ func resolveCommand() {
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Fatalf("Error: file (%s) does not exist!\n", absFile) log.Fatalf("Error: file (%s) does not exist!\n", absFile)
} }
pkgs, err := utils.GetInstalledPackages(rootDir) pkgs, err := bpmlib.GetInstalledPackages(rootDir)
if err != nil { if err != nil {
log.Fatalf("Error: could not get installed packages: %s\n", err.Error()) log.Fatalf("Error: could not get installed packages: %s\n", err.Error())
} }
@ -604,7 +604,7 @@ func resolveCommand() {
var pkgList []string var pkgList []string
for _, pkg := range pkgs { for _, pkg := range pkgs {
if slices.ContainsFunc(utils.GetPackageFiles(pkg, rootDir), func(entry *utils.PackageFileEntry) bool { if slices.ContainsFunc(bpmlib.GetPackageFiles(pkg, rootDir), func(entry *bpmlib.PackageFileEntry) bool {
return entry.Path == absFile return entry.Path == absFile
}) { }) {
pkgList = append(pkgList, pkg) pkgList = append(pkgList, pkg)
@ -694,8 +694,8 @@ func resolveFlags() {
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root") installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
installFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing") installFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts") installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
installFlagSet.StringVar(&utils.BPMConfig.BinaryOutputDir, "o", utils.BPMConfig.BinaryOutputDir, "Set the binary output directory") installFlagSet.StringVar(&bpmlib.BPMConfig.BinaryOutputDir, "o", bpmlib.BPMConfig.BinaryOutputDir, "Set the binary output directory")
installFlagSet.StringVar(&utils.BPMConfig.CompilationDir, "c", utils.BPMConfig.CompilationDir, "Set the compilation directory") installFlagSet.StringVar(&bpmlib.BPMConfig.CompilationDir, "c", bpmlib.BPMConfig.CompilationDir, "Set the compilation directory")
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package") installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation") installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation")
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation") installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"

8
src/bpmlib/go.mod Normal file
View File

@ -0,0 +1,8 @@
module git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib
go 1.23
require (
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f
gopkg.in/yaml.v3 v3.0.1
)

6
src/bpmlib/go.sum Normal file
View File

@ -0,0 +1,6 @@
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"errors" "errors"
@ -23,8 +23,8 @@ type BPMHook struct {
Run string `yaml:"run"` Run string `yaml:"run"`
} }
// CreateHook returns a BPMHook instance based on the content of the given string // createHook returns a BPMHook instance based on the content of the given string
func CreateHook(sourcePath string) (*BPMHook, error) { func createHook(sourcePath string) (*BPMHook, error) {
// Read hook from source path // Read hook from source path
bytes, err := os.ReadFile(sourcePath) bytes, err := os.ReadFile(sourcePath)
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"errors" "errors"
@ -372,12 +372,12 @@ func (operation *BPMOperation) ShowOperationSummary() {
fmt.Println("Warning: Operating in " + operation.RootDir) fmt.Println("Warning: Operating in " + operation.RootDir)
} }
if operation.GetTotalDownloadSize() > 0 { if operation.GetTotalDownloadSize() > 0 {
fmt.Printf("%s will be downloaded to complete this operation\n", UnsignedBytesToHumanReadable(operation.GetTotalDownloadSize())) fmt.Printf("%s will be downloaded to complete this operation\n", unsignedBytesToHumanReadable(operation.GetTotalDownloadSize()))
} }
if operation.GetFinalActionSize(operation.RootDir) > 0 { if operation.GetFinalActionSize(operation.RootDir) > 0 {
fmt.Printf("A total of %s will be installed after the operation finishes\n", BytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir))) fmt.Printf("A total of %s will be installed after the operation finishes\n", bytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)))
} else if operation.GetFinalActionSize(operation.RootDir) < 0 { } else if operation.GetFinalActionSize(operation.RootDir) < 0 {
fmt.Printf("A total of %s will be freed after the operation finishes\n", strings.TrimPrefix(BytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)), "-")) fmt.Printf("A total of %s will be freed after the operation finishes\n", strings.TrimPrefix(bytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)), "-"))
} }
} }
@ -391,7 +391,7 @@ func (operation *BPMOperation) RunHooks(verbose bool) error {
// Find all hooks, validate and execute them // Find all hooks, validate and execute them
for _, entry := range dirEntries { for _, entry := range dirEntries {
if entry.Type().IsRegular() && strings.HasSuffix(entry.Name(), ".bpmhook") { if entry.Type().IsRegular() && strings.HasSuffix(entry.Name(), ".bpmhook") {
hook, err := CreateHook(path.Join(operation.RootDir, "var/lib/bpm/hooks", entry.Name())) hook, err := createHook(path.Join(operation.RootDir, "var/lib/bpm/hooks", entry.Name()))
if err != nil { if err != nil {
log.Printf("Error while reading hook (%s): %s", entry.Name(), err) log.Printf("Error while reading hook (%s): %s", entry.Name(), err)
} }
@ -458,7 +458,7 @@ func (operation *BPMOperation) Execute(verbose, force bool) error {
for _, action := range operation.Actions { for _, action := range operation.Actions {
if action.GetActionType() == "remove" { if action.GetActionType() == "remove" {
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 errors.New(fmt.Sprintf("could not remove package (%s): %s\n", pkgInfo.Name, err))
} }
@ -468,9 +468,9 @@ func (operation *BPMOperation) Execute(verbose, force bool) error {
isReinstall := IsPackageInstalled(bpmpkg.PkgInfo.Name, operation.RootDir) isReinstall := IsPackageInstalled(bpmpkg.PkgInfo.Name, operation.RootDir)
var err error var err error
if value.IsDependency { if value.IsDependency {
err = InstallPackage(value.File, operation.RootDir, verbose, true, false, false, false) err = installPackage(value.File, operation.RootDir, verbose, true, false, false, false)
} else { } else {
err = InstallPackage(value.File, operation.RootDir, verbose, force, false, false, false) err = installPackage(value.File, operation.RootDir, verbose, force, false, false, false)
} }
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))

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"archive/tar" "archive/tar"
@ -288,7 +288,7 @@ const (
Remove = 2 Remove = 2
) )
func ExecutePackageScripts(filename, rootDir string, operation Operation, postOperation bool) error { func executePackageScripts(filename, rootDir string, operation Operation, postOperation bool) error {
pkgInfo, err := ReadPackage(filename) pkgInfo, err := ReadPackage(filename)
if err != nil { if err != nil {
return err return err
@ -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, Install, false)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
err := ExecutePackageScripts(filename, rootDir, Update, false) err := executePackageScripts(filename, rootDir, Update, false)
if err != nil { if err != nil {
return err return err
} }
@ -494,7 +494,7 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
return err return err
} }
tarballFile, err := ReadTarballContent(filename, "files.tar.gz") tarballFile, err := readTarballContent(filename, "files.tar.gz")
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, Install, 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, Update, 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, Install, 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, Update, false)
if err != nil { if err != nil {
return err, nil return err, nil
} }
@ -1051,7 +1051,7 @@ fi
return nil, files return nil, files
} }
func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc, skipCheck, keepTempDir bool) error { func installPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc, skipCheck, keepTempDir bool) error {
if _, err := os.Stat(filename); os.IsNotExist(err) { if _, err := os.Stat(filename); os.IsNotExist(err) {
return err return err
} }
@ -1198,7 +1198,7 @@ func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc,
return err return err
} }
tarballFile, err := ReadTarballContent(filename, "pkg.files") tarballFile, err := readTarballContent(filename, "pkg.files")
if err != nil { if err != nil {
return err return err
} }
@ -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, Install, true)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
err = ExecutePackageScripts(filename, rootDir, Update, true) err = executePackageScripts(filename, rootDir, Update, true)
if err != nil { if err != nil {
return err return err
} }
@ -1552,7 +1552,7 @@ func GetAllPackageFiles(rootDir string, excludePackages ...string) (map[string][
return ret, nil return ret, nil
} }
func RemovePackage(pkg string, verbose bool, rootDir string) error { func removePackage(pkg string, verbose bool, rootDir string) error {
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)
pkgInfo := GetPackageInfo(pkg, rootDir) pkgInfo := GetPackageInfo(pkg, rootDir)

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"archive/tar" "archive/tar"
@ -7,12 +7,12 @@ import (
"os" "os"
) )
type TarballFileReader struct { type tarballFileReader struct {
tarReader *tar.Reader tarReader *tar.Reader
file *os.File file *os.File
} }
func ReadTarballContent(tarballPath, fileToExtract string) (*TarballFileReader, error) { func readTarballContent(tarballPath, fileToExtract string) (*tarballFileReader, error) {
file, err := os.Open(tarballPath) file, err := os.Open(tarballPath)
if err != nil { if err != nil {
return nil, err return nil, err
@ -32,7 +32,7 @@ func ReadTarballContent(tarballPath, fileToExtract string) (*TarballFileReader,
return nil, errors.New("file to extract must be a regular file") return nil, errors.New("file to extract must be a regular file")
} }
return &TarballFileReader{ return &tarballFileReader{
tarReader: tr, tarReader: tr,
file: file, file: file,
}, nil }, nil

View File

@ -1,4 +1,4 @@
package utils package bpmlib
import ( import (
"fmt" "fmt"
@ -55,7 +55,7 @@ func stringSliceRemove(s []string, r string) []string {
return s return s
} }
func UnsignedBytesToHumanReadable(b uint64) string { func unsignedBytesToHumanReadable(b uint64) string {
bf := float64(b) bf := float64(b)
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} { for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} {
if math.Abs(bf) < 1024.0 { if math.Abs(bf) < 1024.0 {
@ -66,7 +66,7 @@ func UnsignedBytesToHumanReadable(b uint64) string {
return fmt.Sprintf("%.1fYiB", bf) return fmt.Sprintf("%.1fYiB", bf)
} }
func BytesToHumanReadable(b int64) string { func bytesToHumanReadable(b int64) string {
bf := float64(b) bf := float64(b)
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} { for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} {
if math.Abs(bf) < 1024.0 { if math.Abs(bf) < 1024.0 {