(ctx context.Context)
| 383 | } |
| 384 | |
| 385 | func (f *folder) pull(ctx context.Context) (success bool, err error) { |
| 386 | f.pullFailTimer.Stop() |
| 387 | select { |
| 388 | case <-f.pullFailTimer.C: |
| 389 | default: |
| 390 | } |
| 391 | |
| 392 | select { |
| 393 | case <-f.initialScanFinished: |
| 394 | default: |
| 395 | // Once the initial scan finished, a pull will be scheduled |
| 396 | return true, nil |
| 397 | } |
| 398 | |
| 399 | defer func() { |
| 400 | if success { |
| 401 | // We're good, reset the pause interval. |
| 402 | f.pullPause = f.pullBasePause() |
| 403 | } |
| 404 | }() |
| 405 | |
| 406 | // If there is nothing to do, don't even enter sync-waiting state. |
| 407 | needCount, err := f.db.CountNeed(f.folderID, protocol.LocalDeviceID) |
| 408 | if err != nil { |
| 409 | return false, err |
| 410 | } |
| 411 | if needCount.TotalItems() == 0 { |
| 412 | // Clears pull failures on items that were needed before, but aren't anymore. |
| 413 | f.errorsMut.Lock() |
| 414 | f.pullErrors = nil |
| 415 | f.errorsMut.Unlock() |
| 416 | return true, nil |
| 417 | } |
| 418 | |
| 419 | // Abort early (before acquiring a token) if there's a folder error |
| 420 | err = f.getHealthErrorWithoutIgnores() |
| 421 | if err != nil { |
| 422 | f.sl.DebugContext(ctx, "Skipping pull due to folder error", slogutil.Error(err)) |
| 423 | return false, err |
| 424 | } |
| 425 | |
| 426 | // Send only folder doesn't do any io, it only checks for out-of-sync |
| 427 | // items that differ in metadata and updates those. |
| 428 | if f.Type != config.FolderTypeSendOnly { |
| 429 | f.setState(FolderSyncWaiting) |
| 430 | |
| 431 | if err := f.ioLimiter.TakeWithContext(ctx, 1); err != nil { |
| 432 | return true, err |
| 433 | } |
| 434 | defer f.ioLimiter.Give(1) |
| 435 | } |
| 436 | |
| 437 | startTime := time.Now() |
| 438 | |
| 439 | // Check if the ignore patterns changed. |
| 440 | oldHash := f.ignores.Hash() |
| 441 | defer func() { |
| 442 | if f.ignores.Hash() != oldHash { |
no test coverage detected