Skip to content

Commit 40af813

Browse files
authored
Merge pull request #183 from covexo/sync-refactoring
Make evaluater functions pure
2 parents 068ae90 + 45edfa3 commit 40af813

4 files changed

Lines changed: 54 additions & 25 deletions

File tree

pkg/devspace/sync/downstream.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,19 @@ func (d *downstream) evaluateFile(fileline string, createFiles *[]*fileInformati
490490
// File found don't delete it
491491
delete(removeFiles, fileInformation.Name)
492492

493+
// Update mode, gid & uid if exists
494+
if d.config.fileIndex.fileMap[fileInformation.Name] != nil {
495+
d.config.fileIndex.fileMap[fileInformation.Name].RemoteMode = fileInformation.RemoteMode
496+
d.config.fileIndex.fileMap[fileInformation.Name].RemoteGID = fileInformation.RemoteGID
497+
d.config.fileIndex.fileMap[fileInformation.Name].RemoteUID = fileInformation.RemoteUID
498+
}
499+
500+
// Exclude symlinks
501+
if fileInformation.IsSymbolicLink {
502+
// Add them to the fileMap though
503+
d.config.fileIndex.fileMap[fileInformation.Name] = fileInformation
504+
}
505+
493506
// Should we download the file / folder?
494507
if shouldDownload(fileInformation, d.config) {
495508
*createFiles = append(*createFiles, fileInformation)

pkg/devspace/sync/evaluater.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,11 @@ func shouldUpload(relativePath string, stat os.FileInfo, s *SyncConfig, isInitia
4848
}
4949

5050
// Exclude changes on the upload exclude list
51-
if s.uploadIgnoreMatcher != nil {
52-
if s.uploadIgnoreMatcher.MatchesPath(relativePath) {
53-
// Add to file map and prevent download if local file is newer than the remote one
54-
if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) {
55-
// Add it to the fileMap
56-
s.fileIndex.fileMap[relativePath] = &fileInformation{
57-
Name: relativePath,
58-
Mtime: ceilMtime(stat.ModTime()),
59-
Size: stat.Size(),
60-
IsDirectory: stat.IsDir(),
61-
}
62-
}
63-
64-
return false
65-
}
66-
}
51+
// if s.uploadIgnoreMatcher != nil {
52+
// if s.uploadIgnoreMatcher.MatchesPath(relativePath) {
53+
// return false
54+
// }
55+
// }
6756

6857
// Exclude local symlinks
6958
if stat.Mode()&os.ModeSymlink != 0 {
@@ -109,13 +98,6 @@ func shouldDownload(fileInformation *fileInformation, s *SyncConfig) bool {
10998
}
11099
}
111100

112-
// Update mode, gid & uid if exists
113-
if s.fileIndex.fileMap[fileInformation.Name] != nil {
114-
s.fileIndex.fileMap[fileInformation.Name].RemoteMode = fileInformation.RemoteMode
115-
s.fileIndex.fileMap[fileInformation.Name].RemoteGID = fileInformation.RemoteGID
116-
s.fileIndex.fileMap[fileInformation.Name].RemoteUID = fileInformation.RemoteUID
117-
}
118-
119101
// Exclude files on the exclude list
120102
if s.downloadIgnoreMatcher != nil {
121103
if s.downloadIgnoreMatcher.MatchesPath(fileInformation.Name) {
@@ -125,8 +107,6 @@ func shouldDownload(fileInformation *fileInformation, s *SyncConfig) bool {
125107

126108
// Exclude symlinks
127109
if fileInformation.IsSymbolicLink {
128-
// Add them to the fileMap though
129-
s.fileIndex.fileMap[fileInformation.Name] = fileInformation
130110
return false
131111
}
132112

pkg/devspace/sync/sync_config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,24 @@ func (s *SyncConfig) diffServerClient(filepath string, sendChanges *[]*fileInfor
294294
delete(downloadChanges, relativePath)
295295

296296
s.fileIndex.fileMapMutex.Lock()
297+
// Exclude changes on the upload exclude list
298+
if s.uploadIgnoreMatcher != nil {
299+
if s.uploadIgnoreMatcher.MatchesPath(relativePath) {
300+
// Add to file map and prevent download if local file is newer than the remote one
301+
if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) {
302+
// Add it to the fileMap
303+
s.fileIndex.fileMap[relativePath] = &fileInformation{
304+
Name: relativePath,
305+
Mtime: ceilMtime(stat.ModTime()),
306+
Size: stat.Size(),
307+
IsDirectory: stat.IsDir(),
308+
}
309+
}
310+
311+
return nil
312+
}
313+
}
314+
297315
shouldUpload := shouldUpload(relativePath, stat, s, true)
298316
s.fileIndex.fileMapMutex.Unlock()
299317

pkg/devspace/sync/upstream.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ func evaluateChange(s *SyncConfig, fileMap map[string]*fileInformation, relative
167167
// File / Folder exist -> Create File or Folder
168168
// if File / Folder does not exist, we create a new remove change
169169
if err == nil {
170+
// Exclude changes on the upload exclude list
171+
if s.uploadIgnoreMatcher != nil {
172+
if s.uploadIgnoreMatcher.MatchesPath(relativePath) {
173+
// Add to file map and prevent download if local file is newer than the remote one
174+
if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) {
175+
// Add it to the fileMap
176+
s.fileIndex.fileMap[relativePath] = &fileInformation{
177+
Name: relativePath,
178+
Mtime: ceilMtime(stat.ModTime()),
179+
Size: stat.Size(),
180+
IsDirectory: stat.IsDir(),
181+
}
182+
}
183+
184+
return nil
185+
}
186+
}
187+
170188
if shouldUpload(relativePath, stat, s, false) {
171189
// New Create Task
172190
return &fileInformation{

0 commit comments

Comments
 (0)