Skip to content

Commit e993cf7

Browse files
committed
refactor: show file system events for sync in debug
1 parent aa66999 commit e993cf7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pkg/devspace/sync/evaluater.go

Lines changed: 7 additions & 1 deletion
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
}

pkg/devspace/sync/upstream.go

Lines changed: 4 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)+"/") {
@@ -490,7 +492,7 @@ func (u *upstream) evaluateChange(relativePath, fullpath string) (*FileInformati
490492
IsDirectory: stat.IsDir(),
491493
IsSymbolicLink: stat.Mode()&os.ModeSymlink != 0,
492494
}
493-
if shouldUpload(u.sync, fileInfo) {
495+
if shouldUpload(u.sync, fileInfo, u.sync.log) {
494496
// New Create Task
495497
return fileInfo, nil
496498
}
@@ -670,7 +672,7 @@ func (u *upstream) ExecuteBatchCommand() error {
670672
func (u *upstream) updateUploadChanges(files []*FileInformation) []*FileInformation {
671673
newChanges := make([]*FileInformation, 0, len(files))
672674
for _, change := range files {
673-
if shouldUpload(u.sync, change) {
675+
if shouldUpload(u.sync, change, u.sync.log) {
674676
newChanges = append(newChanges, change)
675677
}
676678
}

0 commit comments

Comments
 (0)