forked from cego/zfs-cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplancheck.go
62 lines (50 loc) · 1.14 KB
/
plancheck.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/cego/zfs-cleaner/conf"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(plancheckCmd)
}
var plancheckCmd = &cobra.Command{
Use: "plancheck [config file]",
Short: "Print mounts that have no plan and exit",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("%s /path/to/config.conf", cmd.Name())
}
confFile, err := os.Open(args[0])
if err != nil {
return fmt.Errorf("failed to open %s: %s", args[0], err.Error())
}
defer confFile.Close()
conf, err := readConf(confFile)
if err != nil {
return err
}
return planCheck(conf)
},
}
func planCheck(conf *conf.Config) error {
args := []string{"list", "-t", "filesystem", "-o", "name", "-H"}
output, err := exec.Command(commandName, args...).Output()
if err != nil {
return err
}
m := map[string]bool{}
for _, plan := range conf.Plans {
for _, path := range plan.Paths {
m[path] = true
}
}
for _, store := range strings.Fields(string(output)) {
if !m[store] {
fmt.Printf("No plan found for path: '%s'\n", store)
}
}
return nil
}