1
- package container
1
+ package filecollector
2
2
3
3
import (
4
4
"archive/tar"
@@ -17,18 +17,18 @@ import (
17
17
"github.com/go-git/go-git/v5/plumbing/format/index"
18
18
)
19
19
20
- type fileCollectorHandler interface {
20
+ type Handler interface {
21
21
WriteFile (path string , fi fs.FileInfo , linkName string , f io.Reader ) error
22
22
}
23
23
24
- type tarCollector struct {
24
+ type TarCollector struct {
25
25
TarWriter * tar.Writer
26
26
UID int
27
27
GID int
28
28
DstDir string
29
29
}
30
30
31
- func (tc tarCollector ) WriteFile (fpath string , fi fs.FileInfo , linkName string , f io.Reader ) error {
31
+ func (tc TarCollector ) WriteFile (fpath string , fi fs.FileInfo , linkName string , f io.Reader ) error {
32
32
// create a new dir/file header
33
33
header , err := tar .FileInfoHeader (fi , linkName )
34
34
if err != nil {
@@ -59,11 +59,11 @@ func (tc tarCollector) WriteFile(fpath string, fi fs.FileInfo, linkName string,
59
59
return nil
60
60
}
61
61
62
- type copyCollector struct {
62
+ type CopyCollector struct {
63
63
DstDir string
64
64
}
65
65
66
- func (cc * copyCollector ) WriteFile (fpath string , fi fs.FileInfo , linkName string , f io.Reader ) error {
66
+ func (cc * CopyCollector ) WriteFile (fpath string , fi fs.FileInfo , linkName string , f io.Reader ) error {
67
67
fdestpath := filepath .Join (cc .DstDir , fpath )
68
68
if err := os .MkdirAll (filepath .Dir (fdestpath ), 0o777 ); err != nil {
69
69
return err
@@ -82,29 +82,29 @@ func (cc *copyCollector) WriteFile(fpath string, fi fs.FileInfo, linkName string
82
82
return nil
83
83
}
84
84
85
- type fileCollector struct {
85
+ type FileCollector struct {
86
86
Ignorer gitignore.Matcher
87
87
SrcPath string
88
88
SrcPrefix string
89
- Fs fileCollectorFs
90
- Handler fileCollectorHandler
89
+ Fs Fs
90
+ Handler Handler
91
91
}
92
92
93
- type fileCollectorFs interface {
93
+ type Fs interface {
94
94
Walk (root string , fn filepath.WalkFunc ) error
95
95
OpenGitIndex (path string ) (* index.Index , error )
96
96
Open (path string ) (io.ReadCloser , error )
97
97
Readlink (path string ) (string , error )
98
98
}
99
99
100
- type defaultFs struct {
100
+ type DefaultFs struct {
101
101
}
102
102
103
- func (* defaultFs ) Walk (root string , fn filepath.WalkFunc ) error {
103
+ func (* DefaultFs ) Walk (root string , fn filepath.WalkFunc ) error {
104
104
return filepath .Walk (root , fn )
105
105
}
106
106
107
- func (* defaultFs ) OpenGitIndex (path string ) (* index.Index , error ) {
107
+ func (* DefaultFs ) OpenGitIndex (path string ) (* index.Index , error ) {
108
108
r , err := git .PlainOpen (path )
109
109
if err != nil {
110
110
return nil , err
@@ -116,16 +116,16 @@ func (*defaultFs) OpenGitIndex(path string) (*index.Index, error) {
116
116
return i , nil
117
117
}
118
118
119
- func (* defaultFs ) Open (path string ) (io.ReadCloser , error ) {
119
+ func (* DefaultFs ) Open (path string ) (io.ReadCloser , error ) {
120
120
return os .Open (path )
121
121
}
122
122
123
- func (* defaultFs ) Readlink (path string ) (string , error ) {
123
+ func (* DefaultFs ) Readlink (path string ) (string , error ) {
124
124
return os .Readlink (path )
125
125
}
126
126
127
127
//nolint:gocyclo
128
- func (fc * fileCollector ) collectFiles (ctx context.Context , submodulePath []string ) filepath.WalkFunc {
128
+ func (fc * FileCollector ) CollectFiles (ctx context.Context , submodulePath []string ) filepath.WalkFunc {
129
129
i , _ := fc .Fs .OpenGitIndex (path .Join (fc .SrcPath , path .Join (submodulePath ... )))
130
130
return func (file string , fi os.FileInfo , err error ) error {
131
131
if err != nil {
@@ -166,7 +166,7 @@ func (fc *fileCollector) collectFiles(ctx context.Context, submodulePath []strin
166
166
}
167
167
}
168
168
if err == nil && entry .Mode == filemode .Submodule {
169
- err = fc .Fs .Walk (file , fc .collectFiles (ctx , split ))
169
+ err = fc .Fs .Walk (file , fc .CollectFiles (ctx , split ))
170
170
if err != nil {
171
171
return err
172
172
}
0 commit comments