-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (61 loc) · 1.61 KB
/
main.go
File metadata and controls
74 lines (61 loc) · 1.61 KB
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
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"io"
"move-plots/internal/cli"
"move-plots/internal/logging"
"move-plots/internal/plot"
"os"
)
var (
GitVersion = "0.0.0"
stdout io.Writer = os.Stdout
stderr io.Writer = os.Stderr
log logging.LogFacade = logging.NewLoggers(stdout, stderr)
)
func main() {
if err := run(); err != nil {
log.E().Fatalln(err.Error())
}
}
// run the cli
func run() error {
ctx, err := cli.RunCli(stdout, GitVersion)
if err != nil {
return err
}
if ctx.Done {
return nil
}
if ctx.Verbose {
log = logging.NewVerboseLoggers(stdout, stderr)
}
plots, err := plot.FindPlots(ctx.Source)
if err != nil {
return err
}
if len(plots) == 0 {
log.I().Printf("no plots found in %s. nothing to do\n", ctx.Source)
return nil
}
log.I().Printf("found %d plots in %s\n", len(plots), ctx.Source)
for _, plotFilename := range plots {
sourcePlot := plot.AbsoluteFilename(ctx.Source, plotFilename)
log.V().Println("try to move", sourcePlot)
targetDisk, err := plot.FindDisk(ctx.Reserved, ctx.Targets)
if err != nil {
return err
}
if targetDisk == nil {
return fmt.Errorf("can not move plot %s. no disk space left", sourcePlot)
}
log.V().Printf("found %s with available capacity for %d plots\n", targetDisk.Path, targetDisk.PlotsLeft())
targetPlot := plot.AbsoluteFilename(targetDisk.Path, plotFilename)
log.V().Printf("try to move %s to %s\n", sourcePlot, targetPlot)
if err := plot.MovePlot(ctx.Source, plotFilename, targetDisk); err != nil {
return err
}
log.I().Printf("moved %s to %s\n", sourcePlot, targetPlot)
}
return nil
}