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:
2024-04-18 15:04:52 +03:00
parent 6472a113cf
commit c8fc1b902c
5 changed files with 26 additions and 4 deletions
+24 -2
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