-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_util.go
58 lines (46 loc) · 1.27 KB
/
sync_util.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/archivekeep/archivekeep/archive"
"github.com/archivekeep/archivekeep/internal/util"
"github.com/archivekeep/archivekeep/x/archive/wrapper/logged"
"github.com/archivekeep/archivekeep/x/operations/comparison"
"github.com/archivekeep/archivekeep/x/operations/sync"
)
func performSync(
cmd *cobra.Command,
options sync.Options,
fromName, toName, operationName string,
fromArchive archive.Reader,
toArchive archive.ReadWriter,
) error {
compareResult, err := comparison.Execute(fromArchive, toArchive)
if err != nil {
return fmt.Errorf("prepare sync: %w", err)
}
// TODO: execute sync.Plan(compareResult, options) and show the generated plan instead
compareResult.PrintAll(cmd, fromName, toName)
if len(compareResult.UnmatchedBaseExtras) == 0 && len(compareResult.Relocations) == 0 {
cmd.Printf("no files to %s ...\n", operationName)
return nil
}
if !util.AskForConfirmation(cmd, "Do you want to perform %s?", operationName) {
return nil
}
cmd.Printf("\n")
err = sync.PerformSync(
cmd.Context(),
options,
compareResult,
fromArchive,
&logged.Archive{
Base: toArchive,
Printfer: cmd,
},
)
if err != nil {
return fmt.Errorf("execute %s: %w", operationName, err)
}
return nil
}