From 45edfa3a3228d3d850ac5e9fbcf4f2ecee387b65 Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Wed, 12 Sep 2018 16:43:53 +0200 Subject: [PATCH] Make evaluater functions pure --- pkg/devspace/sync/downstream.go | 13 +++++++++++++ pkg/devspace/sync/evaluater.go | 30 +++++------------------------- pkg/devspace/sync/sync_config.go | 18 ++++++++++++++++++ pkg/devspace/sync/upstream.go | 18 ++++++++++++++++++ 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/pkg/devspace/sync/downstream.go b/pkg/devspace/sync/downstream.go index 0988212eca..58fad5052a 100644 --- a/pkg/devspace/sync/downstream.go +++ b/pkg/devspace/sync/downstream.go @@ -490,6 +490,19 @@ func (d *downstream) evaluateFile(fileline string, createFiles *[]*fileInformati // File found don't delete it delete(removeFiles, fileInformation.Name) + // Update mode, gid & uid if exists + if d.config.fileIndex.fileMap[fileInformation.Name] != nil { + d.config.fileIndex.fileMap[fileInformation.Name].RemoteMode = fileInformation.RemoteMode + d.config.fileIndex.fileMap[fileInformation.Name].RemoteGID = fileInformation.RemoteGID + d.config.fileIndex.fileMap[fileInformation.Name].RemoteUID = fileInformation.RemoteUID + } + + // Exclude symlinks + if fileInformation.IsSymbolicLink { + // Add them to the fileMap though + d.config.fileIndex.fileMap[fileInformation.Name] = fileInformation + } + // Should we download the file / folder? if shouldDownload(fileInformation, d.config) { *createFiles = append(*createFiles, fileInformation) diff --git a/pkg/devspace/sync/evaluater.go b/pkg/devspace/sync/evaluater.go index 9d789e60fe..790294971a 100644 --- a/pkg/devspace/sync/evaluater.go +++ b/pkg/devspace/sync/evaluater.go @@ -48,22 +48,11 @@ func shouldUpload(relativePath string, stat os.FileInfo, s *SyncConfig, isInitia } // Exclude changes on the upload exclude list - if s.uploadIgnoreMatcher != nil { - if s.uploadIgnoreMatcher.MatchesPath(relativePath) { - // Add to file map and prevent download if local file is newer than the remote one - if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) { - // Add it to the fileMap - s.fileIndex.fileMap[relativePath] = &fileInformation{ - Name: relativePath, - Mtime: ceilMtime(stat.ModTime()), - Size: stat.Size(), - IsDirectory: stat.IsDir(), - } - } - - return false - } - } + // if s.uploadIgnoreMatcher != nil { + // if s.uploadIgnoreMatcher.MatchesPath(relativePath) { + // return false + // } + // } // Exclude local symlinks if stat.Mode()&os.ModeSymlink != 0 { @@ -109,13 +98,6 @@ func shouldDownload(fileInformation *fileInformation, s *SyncConfig) bool { } } - // Update mode, gid & uid if exists - if s.fileIndex.fileMap[fileInformation.Name] != nil { - s.fileIndex.fileMap[fileInformation.Name].RemoteMode = fileInformation.RemoteMode - s.fileIndex.fileMap[fileInformation.Name].RemoteGID = fileInformation.RemoteGID - s.fileIndex.fileMap[fileInformation.Name].RemoteUID = fileInformation.RemoteUID - } - // Exclude files on the exclude list if s.downloadIgnoreMatcher != nil { if s.downloadIgnoreMatcher.MatchesPath(fileInformation.Name) { @@ -125,8 +107,6 @@ func shouldDownload(fileInformation *fileInformation, s *SyncConfig) bool { // Exclude symlinks if fileInformation.IsSymbolicLink { - // Add them to the fileMap though - s.fileIndex.fileMap[fileInformation.Name] = fileInformation return false } diff --git a/pkg/devspace/sync/sync_config.go b/pkg/devspace/sync/sync_config.go index 7d40eba449..8fd6900af7 100644 --- a/pkg/devspace/sync/sync_config.go +++ b/pkg/devspace/sync/sync_config.go @@ -294,6 +294,24 @@ func (s *SyncConfig) diffServerClient(filepath string, sendChanges *[]*fileInfor delete(downloadChanges, relativePath) s.fileIndex.fileMapMutex.Lock() + // Exclude changes on the upload exclude list + if s.uploadIgnoreMatcher != nil { + if s.uploadIgnoreMatcher.MatchesPath(relativePath) { + // Add to file map and prevent download if local file is newer than the remote one + if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) { + // Add it to the fileMap + s.fileIndex.fileMap[relativePath] = &fileInformation{ + Name: relativePath, + Mtime: ceilMtime(stat.ModTime()), + Size: stat.Size(), + IsDirectory: stat.IsDir(), + } + } + + return nil + } + } + shouldUpload := shouldUpload(relativePath, stat, s, true) s.fileIndex.fileMapMutex.Unlock() diff --git a/pkg/devspace/sync/upstream.go b/pkg/devspace/sync/upstream.go index 5c1902d31b..1bed5dbf8c 100644 --- a/pkg/devspace/sync/upstream.go +++ b/pkg/devspace/sync/upstream.go @@ -167,6 +167,24 @@ func evaluateChange(s *SyncConfig, fileMap map[string]*fileInformation, relative // File / Folder exist -> Create File or Folder // if File / Folder does not exist, we create a new remove change if err == nil { + // Exclude changes on the upload exclude list + if s.uploadIgnoreMatcher != nil { + if s.uploadIgnoreMatcher.MatchesPath(relativePath) { + // Add to file map and prevent download if local file is newer than the remote one + if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) { + // Add it to the fileMap + s.fileIndex.fileMap[relativePath] = &fileInformation{ + Name: relativePath, + Mtime: ceilMtime(stat.ModTime()), + Size: stat.Size(), + IsDirectory: stat.IsDir(), + } + } + + return nil + } + } + if shouldUpload(relativePath, stat, s, false) { // New Create Task return &fileInformation{