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

Method applyChanges

pkg/devspace/sync/upstream.go:641–714  ·  view source on GitHub ↗
(changes []*FileInformation)

Source from the content-addressed store, hash-verified

639}
640
641func (u *upstream) applyChanges(changes []*FileInformation) error {
642 u.sync.log.Debugf("Upstream - Start applying %d changes", len(changes))
643 defer u.sync.log.Debugf("Upstream - Done applying changes")
644
645 var creates []*FileInformation
646 var removes []*FileInformation
647
648 // First we cluster changes into remove and create changes
649 for _, element := range changes {
650 // We determine if a change is a remove or create change by setting
651 // the mtime to 0 in the fileinformation for remove changes
652 if element.Mtime > 0 {
653 creates = append(creates, element)
654 } else {
655 removes = append(removes, element)
656 }
657 }
658
659 // Apply removes
660 if len(removes) > 0 {
661 err := u.applyRemoves(removes)
662 if err != nil {
663 return errors.Wrap(err, "apply removes")
664 }
665 }
666
667 // Apply creates
668 var writtenChanges map[string]*FileInformation
669 if len(creates) > 0 {
670 var err error
671 writtenChanges, err = func() (map[string]*FileInformation, error) {
672 u.sync.fileIndex.fileMapMutex.Lock()
673 defer u.sync.fileIndex.fileMapMutex.Unlock()
674
675 for i := 0; i < syncRetries; i++ {
676 changes, err := u.applyCreates(creates)
677 if err == nil {
678 return changes, nil
679 } else if i+1 >= syncRetries {
680 return nil, errors.Wrap(err, "apply creates")
681 } else if strings.Contains(err.Error(), "closed pipe") || strings.Contains(err.Error(), "transport is closing") || strings.Contains(err.Error(), "broken pipe") {
682 return nil, errors.Wrap(err, "apply creates")
683 }
684
685 u.sync.log.Infof("Upstream - Retry upload because of error: %v", err)
686 creates = u.updateUploadChanges(creates)
687 if len(creates) == 0 {
688 break
689 }
690 }
691
692 return nil, nil
693 }()
694 if err != nil {
695 return err
696 }
697 }
698

Callers 1

mainLoopMethod · 0.95

Calls 9

applyRemovesMethod · 0.95
applyCreatesMethod · 0.95
updateUploadChangesMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
DebugfMethod · 0.45
ErrorMethod · 0.45
InfofMethod · 0.45

Tested by

no test coverage detected