MCPcopy
hub / github.com/syncthing/syncthing / pull

Method pull

lib/model/folder_sendrecv.go:164–236  ·  view source on GitHub ↗

pull returns true if it manages to get all needed items from peers, i.e. get the device in sync with the global state.

(ctx context.Context)

Source from the content-addressed store, hash-verified

162// pull returns true if it manages to get all needed items from peers, i.e. get
163// the device in sync with the global state.
164func (f *sendReceiveFolder) pull(ctx context.Context) (bool, error) {
165 f.sl.DebugContext(ctx, "Pulling")
166
167 scanChan := make(chan string)
168 go f.pullScannerRoutine(ctx, scanChan)
169 defer func() {
170 close(scanChan)
171 f.setState(FolderIdle)
172 }()
173
174 metricFolderPulls.WithLabelValues(f.ID).Inc()
175 pullCtx, cancel := context.WithCancel(ctx)
176 defer cancel()
177 go addTimeUntilCancelled(pullCtx, metricFolderPullSeconds.WithLabelValues(f.ID))
178
179 changed := 0
180
181 f.errorsMut.Lock()
182 f.pullErrors = nil
183 f.errorsMut.Unlock()
184
185 var err error
186 for tries := range maxPullerIterations {
187 select {
188 case <-ctx.Done():
189 return false, ctx.Err()
190 default:
191 }
192
193 // Needs to be set on every loop, as the puller might have set
194 // it to FolderSyncing during the last iteration.
195 f.setState(FolderSyncPreparing)
196
197 changed, err = f.pullerIteration(ctx, scanChan)
198 if err != nil {
199 return false, err
200 }
201
202 f.sl.DebugContext(ctx, "Pull iteration completed", "changed", changed, "try", tries+1)
203
204 if changed == 0 {
205 // No files were changed by the puller, so we are in sync, or we
206 // are unable to make further progress for the moment.
207 break
208 }
209 }
210
211 f.errorsMut.Lock()
212 pullErrNum := len(f.tempPullErrors)
213 if pullErrNum > 0 {
214 f.pullErrors = make([]FileError, 0, len(f.tempPullErrors))
215 for path, err := range f.tempPullErrors {
216 f.sl.WarnContext(ctx, "Failed to sync", slogutil.FilePath(path), slogutil.Error(err))
217 f.pullErrors = append(f.pullErrors, FileError{
218 Err: err,
219 Path: path,
220 })
221 }

Callers

nothing calls this directly

Calls 10

pullScannerRoutineMethod · 0.95
pullerIterationMethod · 0.95
FilePathFunction · 0.92
ErrorFunction · 0.92
addTimeUntilCancelledFunction · 0.85
setStateMethod · 0.80
UnlockMethod · 0.80
DoneMethod · 0.80
LogMethod · 0.65
ErrorsMethod · 0.65

Tested by

no test coverage detected