Fixed major bug where deleting obsolete files would delete directories with other files inside them which could brick your system

This commit is contained in:
CapCreeperGR 2024-04-18 15:04:52 +03:00
parent 6472a113cf
commit 57b8799d71
5 changed files with 26 additions and 4 deletions

View File

@ -591,11 +591,33 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
if len(filesDiff) != 0 {
fmt.Println("Removing obsolete files")
for _, f := range filesDiff {
err := os.RemoveAll(path.Join(installDir, f))
f = path.Join(installDir, f)
stat, err := os.Lstat(f)
if os.IsNotExist(err) {
continue
}
if err != nil {
return err
}
fmt.Println("Removing: " + path.Join(installDir, f))
if stat.IsDir() {
dir, err := os.ReadDir(f)
if err != nil {
return err
}
if len(dir) == 0 {
fmt.Println("Removing: " + f)
err := os.Remove(f)
if err != nil {
return err
}
}
} else {
fmt.Println("Removing: " + f)
err := os.Remove(f)
if err != nil {
return err
}
}
}
}
return nil

View File

@ -17,7 +17,7 @@ import (
/* A simple-to-use package manager */
/* ---------------------------------- */
var bpmVer = "0.1.4"
var bpmVer = "0.1.5"
var subcommand = "help"
var subcommandArgs []string

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: bpm
description: The Bubble Package Manager
version: 0.1.4
version: 0.1.5
url: https://gitlab.com/bubble-package-manager/bpm/
license: GPL3
architecture: x86_64