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

Method Run

pkg/devspace/sync/initial.go:53–181  ·  view source on GitHub ↗
(remoteState map[string]*FileInformation, localState map[string]*FileInformation)

Source from the content-addressed store, hash-verified

51}
52
53func (i *initialSyncer) Run(remoteState map[string]*FileInformation, localState map[string]*FileInformation) error {
54 // Here we calculate the delta between the remote and local state, the result of this operation
55 // are files we should download (new and override) and files we should upload (new and override)
56 download := remoteState
57 i.o.Log.Debugf("Initial Sync - Calculate Delta from Remote State")
58 upload, err := i.CalculateDelta(download, localState)
59 i.o.Log.Debugf("Initial Sync - Done Calculating Delta (Download: %d, Upload: %d)", len(download), len(upload))
60 if err != nil {
61 return errors.Wrap(err, "diff server client")
62 }
63
64 // Upstream initial sync
65 go func() {
66 if !i.o.UpstreamDisabled && i.o.Strategy != latest.InitialSyncStrategyDisabled {
67 // Remove remote if mirror local
68 if len(download) > 0 && i.o.Strategy == latest.InitialSyncStrategyMirrorLocal {
69 deleteRemote := make([]*FileInformation, 0, len(download))
70 for _, element := range download {
71 if i.o.UploadIgnoreMatcher != nil && i.o.UploadIgnoreMatcher.Matches(element.Name, element.IsDirectory) {
72 continue
73 }
74
75 deleteRemote = append(deleteRemote, &FileInformation{
76 Name: element.Name,
77 IsDirectory: element.IsDirectory,
78 })
79 }
80
81 i.o.ApplyRemote(deleteRemote, true)
82 }
83
84 // Upload remote if not mirror remote
85 if len(upload) > 0 {
86 if i.o.Strategy == latest.InitialSyncStrategyMirrorRemote {
87 // only apply the ones that match the downstream ignore matcher
88 changes := []*FileInformation{}
89 for _, element := range upload {
90 if i.o.DownloadIgnoreMatcher != nil && i.o.DownloadIgnoreMatcher.Matches(element.Name, element.IsDirectory) {
91 changes = append(changes, element)
92 }
93 }
94 if len(changes) > 0 {
95 i.o.ApplyRemote(changes, false)
96 }
97 } else {
98 i.o.ApplyRemote(upload, false)
99 }
100 }
101 }
102
103 i.o.UpstreamDone()
104 }()
105
106 // Download changes if enabled
107 if !i.o.DownstreamDisabled && i.o.Strategy != latest.InitialSyncStrategyDisabled {
108 // Remove local if mirror remote
109 if len(upload) > 0 && i.o.Strategy == latest.InitialSyncStrategyMirrorRemote {
110 remoteChanges := make([]*remote.Change, 0, len(upload))

Callers

nothing calls this directly

Calls 3

CalculateDeltaMethod · 0.95
MatchesMethod · 0.65
DebugfMethod · 0.45

Tested by

no test coverage detected