MCPcopy Index your code
hub / github.com/devspace-sh/devspace / filterChanges

Method filterChanges

pkg/devspace/sync/upstream.go:825–940  ·  view source on GitHub ↗
(files []*FileInformation)

Source from the content-addressed store, hash-verified

823}
824
825func (u *upstream) filterChanges(files []*FileInformation) ([]*FileInformation, error) {
826 alreadyUsed := map[string]bool{}
827 newChanges := make([]*FileInformation, 0, len(files))
828 needCheck := []*FileInformation{}
829
830 // filter them first
831 for _, f := range files {
832 if f.Size > largeFileSize {
833 u.sync.log.Debugf("Large file encountered at %s (%0.2f MB). Please try to avoid syncing large files as this will slow down DevSpace", u.getRelativeUpstreamPath(f.Name), float64(f.Size)/1024.0/1024.0)
834 }
835
836 if alreadyUsed[f.Name] {
837 continue
838 } else if f.IsDirectory || u.sync.fileIndex.fileMap[f.Name] == nil || u.sync.fileIndex.fileMap[f.Name].Size != f.Size {
839 newChanges = append(newChanges, f)
840 alreadyUsed[f.Name] = true
841 continue
842 } else if f.Size == 0 {
843 alreadyUsed[f.Name] = true
844 continue
845 }
846
847 alreadyUsed[f.Name] = true
848 needCheck = append(needCheck, f)
849 }
850
851 // now compare crc32 hashes
852 if len(needCheck) > 0 {
853 u.sync.log.Debugf("Start hashing %d files", len(needCheck))
854 defer u.sync.log.Debugf("Done hashing %d files", len(needCheck))
855
856 // cancel after 10 minutes
857 ctx, cancel := context.WithTimeout(u.sync.ctx, time.Minute*30)
858 defer cancel()
859
860 // create done chan
861 done := make(chan error)
862
863 // start remote hashing
864 remoteChecksums := make([]uint32, 0, len(needCheck))
865 localChecksums := make([]uint32, 0, len(needCheck))
866 go func() {
867 // send 1000 each time
868 batchSize := 1000
869 for i := 0; i < len(needCheck); i += batchSize {
870 batch := make([]*remote.TouchPath, 0, batchSize)
871 for j := 0; j < batchSize; j++ {
872 if i+j >= len(needCheck) {
873 break
874 }
875
876 change := needCheck[i+j]
877 u.sync.fileIndex.fileMap[change.Name].Mtime = change.Mtime
878 touchPath := &remote.TouchPath{
879 Path: change.Name,
880 MtimeUnix: change.Mtime,
881 }
882 if !equalFilePermissions(u.sync.fileIndex.fileMap[change.Name].Mode, change.Mode) {

Callers 1

applyCreatesMethod · 0.95

Calls 8

ChecksumFunction · 0.92
equalFilePermissionsFunction · 0.85
WithTimeoutMethod · 0.80
ChecksumsMethod · 0.65
DebugfMethod · 0.45
ErrorfMethod · 0.45
InfofMethod · 0.45

Tested by

no test coverage detected