This commit is contained in:
wheelchairy 2025-02-04 21:53:22 +03:00
parent a606043450
commit 00a56fa985
3 changed files with 21 additions and 3 deletions

View File

@ -195,6 +195,23 @@ func RemovePackage(name string) error {
if _, err := os.Stat(packagePath); os.IsNotExist(err) {
return errors.New("package not found")
}
manifestPath := filepath.Join(packagePath, "manifest.json")
data, err := ioutil.ReadFile(manifestPath)
if err == nil {
var m manifest.Manifest
if err := json.Unmarshal(data, &m); err == nil {
if len(m.Uninstall) > 0 {
for _, cmdStr := range m.Uninstall {
cmd := exec.Command("sh", "-c", cmdStr)
cmd.Dir = packagePath
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("uninstall command '%s' failed: %s", cmdStr, string(output))
}
}
}
}
}
if err := os.RemoveAll(packagePath); err != nil {
return fmt.Errorf("failed to remove package: %w", err)
}
@ -232,4 +249,4 @@ func GetPackageInfo(name string) (string, error) {
return "", err
}
return string(data), nil
}
}

View File

@ -23,6 +23,7 @@ type Manifest struct {
Dependencies []string `json:"dependencies"`
Build []string `json:"build"`
Binaries map[string]BinaryInfo `json:"binaries"`
Uninstall []string `json:"uninstall"`
}
func FetchManifest(name string) (*Manifest, error) {
@ -66,4 +67,4 @@ func fetchManifestFromURL(url string) (*Manifest, error) {
return nil, err
}
return &m, nil
}
}

View File

@ -1,3 +1,3 @@
package version
const CurrentVersion = "1.0.6"
const CurrentVersion = "1.0.7"