-
Notifications
You must be signed in to change notification settings - Fork 23
/
repair.go
66 lines (61 loc) · 1.92 KB
/
repair.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
63
64
65
66
package cmd
import (
"os"
"sync"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
// startRepair represents startRepair command
var startRepair = &cobra.Command{
Use: "start-repair",
Short: "start repair file to blobbers",
Long: `start repair file to blobbers`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
fflags := cmd.Flags() // fflags is a *flag.FlagSet
if fflags.Changed("allocation") == false { // check if the flag "path" is set
PrintError("Error: allocation flag is missing") // If not, we'll let the user know
os.Exit(1) // and return
}
if fflags.Changed("rootpath") == false {
PrintError("Error: rootpath flag is missing")
os.Exit(1)
}
if fflags.Changed("repairpath") == false {
PrintError("Error: repairpath flag is missing")
os.Exit(1)
}
allocationID := cmd.Flag("allocation").Value.String()
allocationObj, err := sdk.GetAllocation(allocationID)
if err != nil {
PrintError("Error fetching the allocation.", err)
os.Exit(1)
}
localRootPath := cmd.Flag("rootpath").Value.String()
repairPath := cmd.Flag("repairpath").Value.String()
wg := &sync.WaitGroup{}
statusBar := &StatusBar{wg: wg}
wg.Add(1)
allocUnderRepair = true
err = allocationObj.StartRepair(localRootPath, repairPath, statusBar)
if err != nil {
allocUnderRepair = false
PrintError("Repair failed.", err)
os.Exit(1)
}
wg.Wait()
if !statusBar.success {
os.Exit(1)
}
return
},
}
func init() {
rootCmd.AddCommand(startRepair)
startRepair.PersistentFlags().String("allocation", "", "Allocation ID")
startRepair.PersistentFlags().String("rootpath", "", "File path for local files ")
startRepair.PersistentFlags().String("repairpath", "", "Path to repair")
startRepair.MarkFlagRequired("allocation")
startRepair.MarkFlagRequired("rootpath")
startRepair.MarkFlagRequired("repairpath")
}