package Package
|
|
|
|
import (
|
|
"PackageManager/Archive"
|
|
"PackageManager/Color"
|
|
"PackageManager/Variables"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func UninstallPackage(pkgs []string) error {
|
|
var (
|
|
pkgFiles []string
|
|
pkg string
|
|
f string
|
|
err error
|
|
)
|
|
|
|
for _, pkg = range pkgs {
|
|
_, err = os.Stat(pkg)
|
|
if os.IsNotExist(err) {
|
|
return fmt.Errorf("invalid package %s", pkg)
|
|
}
|
|
}
|
|
|
|
for _, pkg = range pkgs {
|
|
fmt.Printf(
|
|
"Uninstalling %s...\n",
|
|
pkg,
|
|
)
|
|
|
|
pkgFiles, err = Archive.GetPackageFilePaths(pkg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, f = range pkgFiles {
|
|
err = os.Remove(filepath.Join(Variables.RootDir, f))
|
|
if os.IsNotExist(err) {
|
|
continue
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
fmt.Printf(
|
|
Color.Green("%s uninstalled\n"),
|
|
pkg,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
}
|