Unexport functions

This commit is contained in:
EnumDev 2025-04-07 17:28:26 +03:00
parent 68291e2666
commit 9485248d8e
5 changed files with 27 additions and 27 deletions

View File

@ -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

@ -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

@ -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

@ -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

@ -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 {