Skip to content

Commit da6af1c

Browse files
authored
Merge pull request #1806 from FabianKramm/master
Show file system events for sync in debug
2 parents de5bebc + e993cf7 commit da6af1c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pkg/devspace/sync/evaluater.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sync
22

33
import (
4+
"github.com/loft-sh/devspace/pkg/util/log"
45
"os"
56

67
"github.com/loft-sh/devspace/helper/remote"
@@ -36,7 +37,7 @@ func shouldRemoveRemote(relativePath string, s *Sync) bool {
3637
}
3738

3839
// s.fileIndex needs to be locked before this function is called
39-
func shouldUpload(s *Sync, fileInformation *FileInformation) bool {
40+
func shouldUpload(s *Sync, fileInformation *FileInformation, log log.Logger) bool {
4041
// Exclude if stat is nil
4142
if fileInformation == nil {
4243
return false
@@ -50,12 +51,14 @@ func shouldUpload(s *Sync, fileInformation *FileInformation) bool {
5051

5152
// Exclude local symlinks
5253
if fileInformation.IsSymbolicLink {
54+
log.Debugf("Don't upload %s because it is a symbolic link", fileInformation.Name)
5355
return false
5456
}
5557

5658
// Exclude changes on the exclude list
5759
if s.ignoreMatcher != nil {
5860
if s.ignoreMatcher.Matches(fileInformation.Name, fileInformation.IsDirectory) {
61+
log.Debugf("Don't upload %s because it is excluded", fileInformation.Name)
5962
return false
6063
}
6164
}
@@ -64,16 +67,19 @@ func shouldUpload(s *Sync, fileInformation *FileInformation) bool {
6467
if s.fileIndex.fileMap[fileInformation.Name] != nil {
6568
// Folder already exists, don't send change
6669
if fileInformation.IsDirectory {
70+
log.Debugf("Don't upload %s because directory already exists", fileInformation.Name)
6771
return false
6872
}
6973

7074
// Exclude symlinks
7175
if s.fileIndex.fileMap[fileInformation.Name].IsSymbolicLink {
76+
log.Debugf("Don't upload %s because it is a symbolic link", fileInformation.Name)
7277
return false
7378
}
7479

7580
// File did not change or was changed by downstream
7681
if fileInformation.Mtime == s.fileIndex.fileMap[fileInformation.Name].Mtime && fileInformation.Size == s.fileIndex.fileMap[fileInformation.Name].Size {
82+
log.Debugf("Don't upload %s because mtime and size have not changed", fileInformation.Name)
7783
return false
7884
}
7985
}
@@ -141,7 +147,7 @@ func shouldRemoveLocal(absFilepath string, fileInformation *FileInformation, s *
141147
// We don't delete the file if we haven't tracked it
142148
if stat != nil && s.fileIndex.fileMap[fileInformation.Name] != nil {
143149
if stat.IsDir() != s.fileIndex.fileMap[fileInformation.Name].IsDirectory || stat.IsDir() != fileInformation.IsDirectory {
144-
s.log.Infof("Skip %s because stat returned unequal isdir with fileMap", absFilepath)
150+
s.log.Debugf("Skip %s because stat returned unequal isdir with fileMap", absFilepath)
145151
return false
146152
}
147153

@@ -153,7 +159,7 @@ func shouldRemoveLocal(absFilepath string, fileInformation *FileInformation, s *
153159
return true
154160
}
155161

156-
s.log.Infof("Skip %s because stat.ModTime() %d is greater than fileInformation.Mtime %d", absFilepath, stat.ModTime().Unix(), fileInformation.Mtime)
162+
s.log.Debugf("Skip %s because stat.ModTime() %d is greater than fileInformation.Mtime %d", absFilepath, stat.ModTime().Unix(), fileInformation.Mtime)
157163
} else {
158164
// s.log.Infof("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)
159165
return true

pkg/devspace/sync/upstream.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ func (u *upstream) getFileInformationFromEvent(events []notify.EventInfo) ([]*Fi
403403
if ok {
404404
changes = append(changes, fileInfo)
405405
} else {
406+
u.sync.log.Debugf("Upstream - Event from filesystem for %s", event.Path())
407+
406408
// check if path is correct
407409
fullPath := event.Path()
408410
if !strings.HasPrefix(filepath.ToSlash(fullPath), filepath.ToSlash(u.sync.LocalPath)+"/") {
@@ -475,6 +477,7 @@ func (u *upstream) evaluateChange(relativePath, fullpath string) (*FileInformati
475477
}
476478
}
477479
} else if err != nil {
480+
u.sync.log.Debugf("Error in lstat %s: %v", fullpath, err)
478481
return nil, nil
479482
} else if stat == nil {
480483
return nil, nil
@@ -489,7 +492,7 @@ func (u *upstream) evaluateChange(relativePath, fullpath string) (*FileInformati
489492
IsDirectory: stat.IsDir(),
490493
IsSymbolicLink: stat.Mode()&os.ModeSymlink != 0,
491494
}
492-
if shouldUpload(u.sync, fileInfo) {
495+
if shouldUpload(u.sync, fileInfo, u.sync.log) {
493496
// New Create Task
494497
return fileInfo, nil
495498
}
@@ -669,7 +672,7 @@ func (u *upstream) ExecuteBatchCommand() error {
669672
func (u *upstream) updateUploadChanges(files []*FileInformation) []*FileInformation {
670673
newChanges := make([]*FileInformation, 0, len(files))
671674
for _, change := range files {
672-
if shouldUpload(u.sync, change) {
675+
if shouldUpload(u.sync, change, u.sync.log) {
673676
newChanges = append(newChanges, change)
674677
}
675678
}

0 commit comments

Comments
 (0)