-
Notifications
You must be signed in to change notification settings - Fork 0
/
shrink.go
57 lines (52 loc) · 1.17 KB
/
shrink.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
//nolint:gochecknoglobals,gochecknoinits
package cmd
import (
"os"
"sync"
"github.com/Defacto2/df2/pkg/database"
"github.com/Defacto2/df2/pkg/shrink"
"github.com/spf13/cobra"
)
// shrinkCmd represents the compact command.
var shrinkCmd = &cobra.Command{
Use: "shrink",
Short: "Reduces the space used in directories.",
Long: `Shrink reduces the hard drive space used for directories on
the website. This command will only work when no records in the database
are 'waiting for approval.'`,
Aliases: []string{"s"},
GroupID: "group2",
Run: func(cmd *cobra.Command, args []string) {
db, err := database.Connect(confg)
if err != nil {
logr.Fatal(err)
}
defer db.Close()
w := os.Stdout
var wg sync.WaitGroup
const delta = 3
wg.Add(delta)
go func() {
if err := shrink.SQL(w, confg.SQLDumps); err != nil {
logr.Error(err)
}
wg.Done()
}()
go func() {
if err := shrink.Files(db, w, confg.IncomingFiles); err != nil {
logr.Error(err)
}
wg.Done()
}()
go func() {
if err := shrink.Previews(db, w, confg.IncomingImgs); err != nil {
logr.Error(err)
}
wg.Done()
}()
wg.Wait()
},
}
func init() {
rootCmd.AddCommand(shrinkCmd)
}