-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathoptions.go
More file actions
81 lines (66 loc) · 2.37 KB
/
Copy pathoptions.go
File metadata and controls
81 lines (66 loc) · 2.37 KB
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
76
77
78
79
80
81
/*
Copyright 2026 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package tar
import "os"
// Option configures the behavior of Tar and Untar. Options are
// silently ignored by operations they do not apply to.
type Option func(*tarOpts)
type tarOpts struct {
// maxUntarSize represents the limit size (bytes) for archives being decompressed by Untar.
// When max is a negative value the size checks are disabled.
maxUntarSize int
// skipSymlinks ignores symlinks instead of failing the decompression.
skipSymlinks bool
// skipGzip disables gzip compression: Tar writes a plain tar stream,
// and Untar reads one.
skipGzip bool
// filter is called for each entry during archiving or extraction.
// If it returns true, the entry is excluded.
filter func(path string, fi os.FileInfo) bool
}
// WithMaxUntarSize sets the limit size for archives being decompressed by Untar.
// When max is equal or less than 0 disables size checks.
func WithMaxUntarSize(max int) Option {
return func(t *tarOpts) {
t.maxUntarSize = max
}
}
// WithSkipSymlinks allows for symlinks to be present
// in the tarball and skips them when decompressing.
func WithSkipSymlinks() Option {
return func(t *tarOpts) {
t.skipSymlinks = true
}
}
// WithSkipGzip disables gzip compression: Tar writes a plain tar stream,
// and Untar reads one.
func WithSkipGzip() Option {
return func(t *tarOpts) {
t.skipGzip = true
}
}
// WithFilter sets a predicate called for each entry during archiving
// or extraction. Entries for which fn returns true are excluded. During
// Tar the path is the absolute filesystem path; during Untar it is the
// slash-separated name from the tar header.
func WithFilter(fn func(path string, fi os.FileInfo) bool) Option {
return func(t *tarOpts) {
t.filter = fn
}
}
// applyOpts applies the given Option to t.
func (t *tarOpts) applyOpts(opts ...Option) {
for _, opt := range opts {
opt(t)
}
}