@@ -3,6 +3,7 @@ package sync
33import (
44 "context"
55 "fmt"
6+ "github.com/loft-sh/devspace/helper/server/ignoreparser"
67 "github.com/loft-sh/devspace/pkg/util/fsutil"
78 "io"
89 "io/ioutil"
@@ -26,6 +27,8 @@ type downstream struct {
2627 writer io.WriteCloser
2728 client remote.DownstreamClient
2829
30+ ignoreMatcher ignoreparser.IgnoreParser
31+
2932 unarchiver * Unarchiver
3033}
3134
@@ -52,20 +55,27 @@ func newDownstream(reader io.ReadCloser, writer io.WriteCloser, sync *Sync) (*do
5255 return nil , errors .Wrap (err , "new client connection" )
5356 }
5457
58+ // Create download exclude paths
59+ ignoreMatcher , err := ignoreparser .CompilePaths (sync .Options .DownloadExcludePaths , sync .log )
60+ if err != nil {
61+ return nil , errors .Wrap (err , "compile paths" )
62+ }
63+
5564 return & downstream {
56- sync : sync ,
57- reader : reader ,
58- writer : writer ,
59- client : remote .NewDownstreamClient (conn ),
60- unarchiver : NewUnarchiver (sync , false , sync .log ),
65+ sync : sync ,
66+ reader : reader ,
67+ writer : writer ,
68+ client : remote .NewDownstreamClient (conn ),
69+ ignoreMatcher : ignoreMatcher ,
70+ unarchiver : NewUnarchiver (sync , false , sync .log ),
6171 }, nil
6272}
6373
6474func (d * downstream ) populateFileMap () error {
6575 d .sync .fileIndex .fileMapMutex .Lock ()
6676 defer d .sync .fileIndex .fileMapMutex .Unlock ()
6777
68- changes , err := d .collectChanges ()
78+ changes , err := d .collectChanges (true )
6979 if err != nil {
7080 return errors .Wrap (err , "collect changes" )
7181 }
@@ -79,7 +89,7 @@ func (d *downstream) populateFileMap() error {
7989 return nil
8090}
8191
82- func (d * downstream ) collectChanges () ([]* remote.Change , error ) {
92+ func (d * downstream ) collectChanges (skipIgnore bool ) ([]* remote.Change , error ) {
8393 d .sync .log .Debugf ("Downstream - Start collecting changes" )
8494 defer d .sync .log .Debugf ("Downstream - Done collecting changes" )
8595
@@ -97,9 +107,14 @@ func (d *downstream) collectChanges() ([]*remote.Change, error) {
97107 changeChunk , err := changesClient .Recv ()
98108 if changeChunk != nil {
99109 for _ , change := range changeChunk .Changes {
100- if d .shouldKeep (change ) {
101- changes = append (changes , change )
110+ if ! skipIgnore && d .ignoreMatcher .Matches (change .Path , change .IsDir ) {
111+ continue
112+ }
113+ if ! d .shouldKeep (change ) {
114+ continue
102115 }
116+
117+ changes = append (changes , change )
103118 }
104119 }
105120
@@ -168,7 +183,7 @@ func (d *downstream) mainLoop() error {
168183 // Compare change amount
169184 if lastAmountChanges > 0 && (time .Now ().After (changeTimer ) || changeAmount .Amount > 25000 || changeAmount .Amount == lastAmountChanges ) {
170185 d .sync .fileIndex .fileMapMutex .Lock ()
171- changes , err := d .collectChanges ()
186+ changes , err := d .collectChanges (false )
172187 d .sync .fileIndex .fileMapMutex .Unlock ()
173188 if err != nil {
174189 return errors .Wrap (err , "collect changes" )
0 commit comments