-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
75 lines (60 loc) · 1.75 KB
/
options.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package copy
import "hash"
const defaultBufferSize = 4096
// options allows to configure Copy behavior.
type options struct {
exclude []string
hash hash.Hash
bufSize int
force bool
contentOnly bool
move bool
revert bool
follow bool
}
func defaultOptions() *options {
return &options{bufSize: defaultBufferSize}
}
type (
optFunc func(*options)
// Type to create custom slices of copy options.
Options []optFunc
)
// Force re-writes destination if it is already exists.
func Force(o *options) { o.force = true }
// ContentOnly copies only source folder content without creating
// root folder in destination.
func ContentOnly(o *options) { o.contentOnly = true }
// FollowSymlink resolves source file path before copy, to follow symlink
// if needed.
func FollowSymlink(o *options) { o.follow = true }
// WithMove removes source after copying process is finished.
func WithMove(o *options) { o.move = true }
// WithBufferSize allows to set custom buffer size for file copy.
// If provided size <= 0, then default will be used.
func WithBufferSize(size int) optFunc {
return func(o *options) {
if size <= 0 {
return
}
o.bufSize = size
}
}
// RevertOnErr removes destination file if there was an error during copy process.
func RevertOnErr(o *options) { o.revert = true }
// WithHash calculates hash of the copied file(s).
//
// Note: if hash is not nil, it guarantee the copied file(s) will be read.
// Might increase total execution time.
func WithHash(h hash.Hash) optFunc {
return func(o *options) {
o.hash = h
}
}
// WithExclude excludes paths from copy which includes one of the given
// strings.
func WithExclude(s ...string) optFunc {
return func(o *options) {
o.exclude = append(o.exclude, s...)
}
}