-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm.go
56 lines (46 loc) · 1.31 KB
/
rm.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
package main
import (
"bufio"
"bytes"
"context"
"encoding/csv"
"fmt"
"os"
"strconv"
"sync"
"github.com/minio/minio-go/v7"
)
func RemoveArchive(config *BackupConfig) {
archives := List(config, true)
fmt.Printf("\n\nChoose which archive you'd like to delete (comma seperated numbers, or \"all\"): ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
archivesToDeleteRaw := scanner.Text()
var archivesToDeleteRawIndexes []string
if archivesToDeleteRaw == "all" {
for i, _ := range archives {
archivesToDeleteRawIndexes = append(archivesToDeleteRawIndexes, fmt.Sprintf("%d", i))
}
} else {
reader := csv.NewReader(bytes.NewBuffer([]byte(archivesToDeleteRaw)))
archivesToDeleteRawIndexes = check(reader.Read())
}
archivesToDelete := make([]int, len(archivesToDeleteRawIndexes))
for _, v := range archivesToDeleteRawIndexes {
archivesToDelete = append(archivesToDelete, check(strconv.Atoi(v)))
}
var wg sync.WaitGroup
wg.Add(len(archivesToDelete))
for _, v := range archivesToDelete {
go func(v int) {
defer wg.Done()
objects := getObjectsFromArchives(config, archives[v])
errs := config.MinioClient.RemoveObjects(context.Background(), config.Config.S3.Bucket, objects, minio.RemoveObjectsOptions{})
for roe := range errs {
if roe.Err == nil {
}
}
}(v)
}
wg.Wait()
}