-
Notifications
You must be signed in to change notification settings - Fork 8
/
uninstall.go
40 lines (35 loc) · 1.02 KB
/
uninstall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"os"
"path/filepath"
)
func uninstall(t *Target) {
dir := filepath.Join(t.Config.RootDir, t.Version.Ver)
stat, err := os.Stat(dir)
if err != nil {
if !os.IsNotExist(err) {
fatalf("failed to stat %q: %v", dir, err)
}
fatalf("%s version %s is not installed.", t.Config.Name, t.Version.Ver)
}
if !stat.IsDir() {
fatalf("found %s %s (%q) but it is not a directory.\nplease remove it yourself.", t.Config.Name, t.Version.Ver, dir)
} else if err = os.RemoveAll(dir); err != nil {
fatalf("failed to uninstall version %s: %v", t.Version.Ver, err)
}
printf("%s version %s (%q) has been uninstalled.", t.Config.Name, t.Version.Ver, dir)
}
func CmdUninstall(opts []string) {
target := PickTargetVersion(opts[0], true)
// uninstall the specified version of lua
if target.Lua != nil {
uninstall(target.Lua)
// it is remove all the versions of luarocks
return
}
// uninstall the specified version of luarocks
if target.LuaRocks != nil {
CheckLuaRocksRootDir()
uninstall(target.LuaRocks)
}
}