-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.go
43 lines (38 loc) · 866 Bytes
/
copy.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
package thuder
import (
"fmt"
"time"
)
//Copy exposes a simple copy command to be used programtically.
func Copy(source, dest string, filters []Filter) error {
sourceNode, err := NewRootNode(source, false)
if err != nil {
return fmt.Errorf("source string error: %v", err)
}
err = PrepareFilters(filters)
if err != nil {
return fmt.Errorf("filter format error: %v", err)
}
actions := make(chan action, 8)
now := time.Now()
p := Processor{
stack: []layer{{from: []Node{*sourceNode}, to: dest}},
actions: actions,
accept: func(n *Node) bool {
_, a := MatchFilters(filters, n, true, now)
return a
},
}
go p.Do()
for {
a := <-actions
if len(a.from) == 0 {
return p.LoggedErrors()
}
LogP("Applying %v actions to %v.\n", len(a.from), a.to)
errs := applyAction(a)
if len(errs) != 0 {
p.logErrors(a.to, errs)
}
}
}