Skip to content

Commit 9e06993

Browse files
committed
fix: prevent reupload with downstream exclude
1 parent 9a27eb8 commit 9e06993

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

pkg/devspace/services/sync/controller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ func (c *controller) initClient(ctx devspacecontext.Context, pod *v1.Pod, arch,
491491
for _, exclude := range options.ExcludePaths {
492492
downstreamArgs = append(downstreamArgs, "--exclude", exclude)
493493
}
494-
for _, exclude := range options.DownloadExcludePaths {
495-
downstreamArgs = append(downstreamArgs, "--exclude", exclude)
496-
}
497494
downstreamArgs = append(downstreamArgs, containerPath)
498495

499496
downStdinReader, downStdinWriter := io.Pipe()

pkg/devspace/sync/downstream.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sync
33
import (
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

6474
func (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")

pkg/devspace/sync/sync.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ func (s *Sync) initialSync(onInitUploadDone chan struct{}, onInitDownloadDone ch
342342
downloadChanges := make(map[string]*FileInformation)
343343
s.fileIndex.fileMapMutex.Lock()
344344
for key, element := range s.fileIndex.fileMap {
345+
if s.downloadIgnoreMatcher.Matches(element.Name, element.IsDirectory) {
346+
continue
347+
}
345348
if element.IsSymbolicLink {
346349
continue
347350
}

0 commit comments

Comments
 (0)