Fix remove package scripts not working with chroot

This commit is contained in:
2025-08-14 17:07:42 +03:00
parent c01ca62e34
commit 6501105dd1
+6 -7
View File
@@ -927,15 +927,14 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
} }
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/") pkgDir := path.Join("/var/lib/bpm/installed/", pkg)
pkgDir := path.Join(installedDir, pkg)
pkgInfo := GetPackageInfo(pkg, rootDir) pkgInfo := GetPackageInfo(pkg, rootDir)
if pkgInfo == nil { if pkgInfo == nil {
return errors.New("could not get package info") return errors.New("could not get package info")
} }
// Executing pre_remove script // Executing pre_remove script
if _, err := os.Stat(path.Join(pkgDir, "pre_remove.sh")); err == nil { if _, err := os.Stat(path.Join(rootDir, pkgDir, "pre_remove.sh")); err == nil {
cmd := exec.Command("/bin/bash", path.Join(pkgDir, "pre_remove.sh")) cmd := exec.Command("/bin/bash", path.Join(pkgDir, "pre_remove.sh"))
// Setup subprocess environment // Setup subprocess environment
cmd.Dir = "/" cmd.Dir = "/"
@@ -1032,7 +1031,7 @@ func removePackage(pkg string, verbose bool, rootDir string) error {
} }
// Executing post_remove script // Executing post_remove script
if _, err := os.Stat(path.Join(pkgDir, "post_remove.sh")); err == nil { if _, err := os.Stat(path.Join(rootDir, pkgDir, "post_remove.sh")); err == nil {
cmd := exec.Command("/bin/bash", path.Join(pkgDir, "post_remove.sh")) cmd := exec.Command("/bin/bash", path.Join(pkgDir, "post_remove.sh"))
// Setup subprocess environment // Setup subprocess environment
cmd.Dir = "/" cmd.Dir = "/"
@@ -1051,15 +1050,15 @@ func removePackage(pkg string, verbose bool, rootDir string) error {
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
log.Printf("Warning: could not run pre_remove.sh package script: %s", err) log.Printf("Warning: could not run post_remove.sh package script: %s", err)
} }
} }
// Removing package directory // Removing package directory
if verbose { if verbose {
fmt.Println("Removing: " + pkgDir) fmt.Println("Removing: " + path.Join(rootDir, pkgDir))
} }
err = os.RemoveAll(pkgDir) err = os.RemoveAll(path.Join(rootDir, pkgDir))
if err != nil { if err != nil {
return err return err
} }