@@ -23,6 +23,7 @@ import (
2323 "strings"
2424
2525 "github.com/google/uuid"
26+ "github.com/moby/patternmatcher"
2627
2728 "github.com/apple/container-builder-shim/pkg/api"
2829 "github.com/apple/container-builder-shim/pkg/fileutils"
@@ -83,6 +84,10 @@ func (f *FS) Walk(ctx context.Context, target string, fn fs.WalkDirFunc) error {
8384 if err != nil {
8485 return err
8586 }
87+ excludeMatcher , err := patternmatcher .New (strings .Split (walkMeta .ExcludedPatterns , "," ))
88+ if err != nil {
89+ return err
90+ }
8691
8792 id := uuid .NewString ()
8893 demux := stream .NewDemuxWithContext (cancellableCtx , id , stream .FilterByBuildID (id ), func (any ) {})
@@ -119,7 +124,14 @@ func (f *FS) Walk(ctx context.Context, target string, fn fs.WalkDirFunc) error {
119124 switch walkMeta .Mode {
120125 case ModeTAR :
121126 receiver := fileutils .NewTarReceiver (f .fsPath , demux )
122- checksum , err := receiver .Receive (ctx , fn )
127+ checksum , err := receiver .Receive (ctx , func (path string , d fs.DirEntry , err error ) error {
128+ excluded , err := excludeMatcher .MatchesOrParentMatches (path )
129+ if excluded {
130+ return nil
131+ }
132+
133+ return fn (path , d , err )
134+ })
123135 if err != nil {
124136 return err
125137 }
@@ -145,16 +157,18 @@ type RawFileInfo struct {
145157}
146158
147159type WalkMetadata struct {
148- IncludePatterns string
149- FollowPaths string
150- DirName string
151- Mode TransferMode
160+ IncludePatterns string
161+ ExcludedPatterns string
162+ FollowPaths string
163+ DirName string
164+ Mode TransferMode
152165}
153166
154167func unmarshalWalkMetadata (ctx context.Context ) (* WalkMetadata , error ) {
155168 md := & WalkMetadata {}
156169 if m , ok := metadata .FromIncomingContext (ctx ); ok {
157170 md .IncludePatterns = strings .Join (m ["include-patterns" ], "," )
171+ md .ExcludedPatterns = strings .Join (m ["exclude-patterns" ], "," )
158172 md .FollowPaths = strings .Join (m ["followpaths" ], "," )
159173 md .DirName = strings .Join (m ["dir-name" ], "," )
160174 modeStr := strings .Join (m ["mode" ], "," )
0 commit comments