Skip to content

Commit f253d6f

Browse files
committed
Resolve #204 & fix problem with forced deploy
1 parent 6748c06 commit f253d6f

7 files changed

Lines changed: 30 additions & 44 deletions

File tree

cmd/up.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
141141
if cmd.flags.initRegistries {
142142
cmd.initRegistries()
143143
}
144-
mustRedeploy := cmd.flags.deploy
144+
mustRedeploy := false
145145

146146
if cmd.flags.build {
147147
mustRedeploy = cmd.buildImages(cobraCmd.Flags().Changed("build"))
@@ -150,7 +150,7 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
150150
// Check if we find a running release pod
151151
pod, err := getRunningDevSpacePod(cmd.helm, cmd.kubectl)
152152

153-
if err != nil || mustRedeploy {
153+
if err != nil || mustRedeploy || cmd.flags.deploy {
154154
cmd.deployChart()
155155
} else {
156156
cmd.pod = pod

pkg/devspace/sync/evaluater.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ func shouldUpload(relativePath string, stat os.FileInfo, s *SyncConfig, isInitia
7575

7676
if isInitial {
7777
// File is older locally than remote so don't update remote
78-
if ceilMtime(stat.ModTime()) <= s.fileIndex.fileMap[relativePath].Mtime+1 {
78+
if roundMtime(stat.ModTime()) <= s.fileIndex.fileMap[relativePath].Mtime {
7979
return false
8080
}
8181
} else {
8282
// File did not change or was changed by downstream
83-
if ceilMtime(stat.ModTime()) == s.fileIndex.fileMap[relativePath].Mtime && stat.Size() == s.fileIndex.fileMap[relativePath].Size {
83+
if roundMtime(stat.ModTime()) == s.fileIndex.fileMap[relativePath].Mtime && stat.Size() == s.fileIndex.fileMap[relativePath].Size {
8484
return false
8585
}
8686
}
@@ -140,35 +140,47 @@ func shouldDownload(fileInformation *fileInformation, s *SyncConfig) bool {
140140
// - The file is present on the filesystem and did not change in terms of size and mtime on the filesystem
141141
func shouldRemoveLocal(absFilepath string, fileInformation *fileInformation, s *SyncConfig) bool {
142142
if fileInformation == nil {
143+
s.Logf("Skip %s because fileInformation is nil", absFilepath)
143144
return false
144145
}
145146

147+
// We don't need to check s.ignoreMatcher, because if a path is ignored it will never be added to the fileMap, because shouldDownload
148+
// and shouldUpload are always false, and hence it never appears in the fileMap and is not copied to the remove fileMap clone
149+
// in the beginning of the downstream mainLoop
150+
146151
// Exclude files on the exclude list
147152
if s.downloadIgnoreMatcher != nil {
148153
if s.downloadIgnoreMatcher.MatchesPath(fileInformation.Name) {
154+
s.Logf("Skip %s because downloadIgnoreMatcher matched", absFilepath)
149155
return false
150156
}
151157
}
152158

153159
// Only delete if mtime and size did not change
154160
stat, err := os.Stat(absFilepath)
155161
if err != nil {
162+
s.Logf("Skip %s because stat returned %v", absFilepath, stat)
156163
return false
157164
}
158165

159166
// We don't delete the file if we haven't tracked it
160167
if stat != nil && s.fileIndex.fileMap[fileInformation.Name] != nil {
161168
if stat.IsDir() != s.fileIndex.fileMap[fileInformation.Name].IsDirectory || stat.IsDir() != fileInformation.IsDirectory {
169+
s.Logf("Skip %s because stat returned unequal isdir with fileMap", absFilepath)
162170
return false
163171
}
164172

165173
if fileInformation.IsDirectory == false {
166174
// We don't delete the file if it has changed in the map since we collected changes
167175
if fileInformation.Mtime == s.fileIndex.fileMap[fileInformation.Name].Mtime && fileInformation.Size == s.fileIndex.fileMap[fileInformation.Name].Size {
168176
// We don't delete the file if it has changed on the filesystem meanwhile
169-
if ceilMtime(stat.ModTime()) <= fileInformation.Mtime {
177+
if roundMtime(stat.ModTime()) <= fileInformation.Mtime {
170178
return true
171179
}
180+
181+
s.Logf("Skip %s because stat.ModTime() %d is greater than fileInformation.Mtime %d", absFilepath, roundMtime(stat.ModTime()), fileInformation.Mtime)
182+
} else {
183+
s.Logf("Skip %s because Mtime (%d and %d) or Size (%d and %d) is unequal between fileInformation and fileMap", absFilepath, fileInformation.Mtime, s.fileIndex.fileMap[fileInformation.Name].Mtime, fileInformation.Size, s.fileIndex.fileMap[fileInformation.Name].Size)
172184
}
173185
} else {
174186
return true

pkg/devspace/sync/sync_config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ func (s *SyncConfig) diffServerClient(filepath string, sendChanges *[]*fileInfor
308308
if s.uploadIgnoreMatcher.MatchesPath(relativePath) {
309309
s.fileIndex.fileMapMutex.Lock()
310310
// Add to file map and prevent download if local file is newer than the remote one
311-
if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < ceilMtime(stat.ModTime()) {
311+
if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < roundMtime(stat.ModTime()) {
312312
// Add it to the fileMap
313313
s.fileIndex.fileMap[relativePath] = &fileInformation{
314314
Name: relativePath,
315-
Mtime: ceilMtime(stat.ModTime()),
315+
Mtime: roundMtime(stat.ModTime()),
316316
Size: stat.Size(),
317317
IsDirectory: stat.IsDir(),
318318
}
@@ -338,7 +338,7 @@ func (s *SyncConfig) diffServerClient(filepath string, sendChanges *[]*fileInfor
338338
// Add file to upload
339339
*sendChanges = append(*sendChanges, &fileInformation{
340340
Name: relativePath,
341-
Mtime: ceilMtime(stat.ModTime()),
341+
Mtime: roundMtime(stat.ModTime()),
342342
Size: stat.Size(),
343343
IsDirectory: false,
344344
})
@@ -358,7 +358,7 @@ func (s *SyncConfig) diffDir(filepath string, stat os.FileInfo, sendChanges *[]*
358358
if len(files) == 0 && relativePath != "" {
359359
*sendChanges = append(*sendChanges, &fileInformation{
360360
Name: relativePath,
361-
Mtime: ceilMtime(stat.ModTime()),
361+
Mtime: roundMtime(stat.ModTime()),
362362
Size: stat.Size(),
363363
IsDirectory: true,
364364
})

pkg/devspace/sync/sync_config_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,21 +611,3 @@ func TestRemoveDirInFileMap(t *testing.T) {
611611
t.Fail()
612612
}
613613
}
614-
615-
func TestCeilMtime(t *testing.T) {
616-
ceiledNumberNano := time.Unix(1533647574, 0)
617-
ceiledNumberSeconds := time.Unix(1533647574, 0)
618-
619-
unceiledNumberNano := time.Unix(1533647574, 1)
620-
unceiledNumberSeconds := time.Unix(1533647575, 0)
621-
622-
if ceilMtime(ceiledNumberNano) != ceiledNumberSeconds.Unix() {
623-
t.Error("ceilMtime failed ceiledNumberNano != ceiledNumberSeconds")
624-
t.Fail()
625-
}
626-
627-
if ceilMtime(unceiledNumberNano) != unceiledNumberSeconds.Unix() {
628-
t.Error("ceilMtime failed unceiledNumberNano != unceiledNumberSeconds")
629-
t.Fail()
630-
}
631-
}

pkg/devspace/sync/tar.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ func untarNext(tarReader *tar.Reader, destPath, prefix string, config *SyncConfi
6262
stat, err := os.Stat(outFileName)
6363

6464
if err == nil {
65-
if ceilMtime(stat.ModTime()) > header.FileInfo().ModTime().Unix() {
65+
if roundMtime(stat.ModTime()) > header.FileInfo().ModTime().Unix() {
6666
// Update filemap otherwise we download and download again
6767
config.fileIndex.fileMap[relativePath] = &fileInformation{
6868
Name: relativePath,
69-
Mtime: ceilMtime(stat.ModTime()),
69+
Mtime: roundMtime(stat.ModTime()),
7070
Size: stat.Size(),
7171
IsDirectory: stat.IsDir(),
7272
}
@@ -317,7 +317,7 @@ func createFileInformationFromStat(relativePath string, stat os.FileInfo, config
317317
fileInformation := &fileInformation{
318318
Name: relativePath,
319319
Size: stat.Size(),
320-
Mtime: ceilMtime(stat.ModTime()),
320+
Mtime: roundMtime(stat.ModTime()),
321321
IsDirectory: stat.IsDir(),
322322
}
323323

pkg/devspace/sync/upstream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ func evaluateChange(s *SyncConfig, fileMap map[string]*fileInformation, relative
171171
if s.uploadIgnoreMatcher != nil {
172172
if s.uploadIgnoreMatcher.MatchesPath(relativePath) {
173173
// 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()) {
174+
if s.fileIndex.fileMap[relativePath] != nil && s.fileIndex.fileMap[relativePath].Mtime < roundMtime(stat.ModTime()) {
175175
// Add it to the fileMap
176176
s.fileIndex.fileMap[relativePath] = &fileInformation{
177177
Name: relativePath,
178-
Mtime: ceilMtime(stat.ModTime()),
178+
Mtime: roundMtime(stat.ModTime()),
179179
Size: stat.Size(),
180180
IsDirectory: stat.IsDir(),
181181
}
@@ -189,7 +189,7 @@ func evaluateChange(s *SyncConfig, fileMap map[string]*fileInformation, relative
189189
// New Create Task
190190
return &fileInformation{
191191
Name: relativePath,
192-
Mtime: ceilMtime(stat.ModTime()),
192+
Mtime: roundMtime(stat.ModTime()),
193193
Size: stat.Size(),
194194
IsDirectory: stat.IsDir(),
195195
}

pkg/devspace/sync/util.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88
"path"
99
"path/filepath"
10-
"strconv"
1110
"strings"
1211
"time"
1312

@@ -84,16 +83,9 @@ func copyToContainerTestable(Kubectl *kubernetes.Clientset, Pod *k8sv1.Pod, Cont
8483
return nil
8584
}
8685

87-
// We need this function because tar ceils up the mtime to seconds on the server
88-
func ceilMtime(mtime time.Time) int64 {
89-
if mtime.UnixNano()%1000000000 != 0 {
90-
num := strconv.FormatInt(mtime.UnixNano(), 10)
91-
ret, _ := strconv.Atoi(num[:len(num)-9])
92-
93-
return int64(ret) + 1
94-
}
95-
96-
return mtime.Unix()
86+
// We need this function because tar rounds the mtime on the server as well
87+
func roundMtime(mtime time.Time) int64 {
88+
return mtime.Round(time.Second).Unix()
9789
}
9890

9991
func getRelativeFromFullPath(fullpath string, prefix string) string {

0 commit comments

Comments
 (0)