(basePath string, oldState map[string]*remote.Change, newState map[string]*remote.Change, stream remote.Downstream_ChangesServer, throttle time.Duration)
| 431 | } |
| 432 | |
| 433 | func streamChanges(basePath string, oldState map[string]*remote.Change, newState map[string]*remote.Change, stream remote.Downstream_ChangesServer, throttle time.Duration) (int64, error) { |
| 434 | changeAmount := int64(0) |
| 435 | if oldState == nil { |
| 436 | oldState = make(map[string]*remote.Change) |
| 437 | } |
| 438 | |
| 439 | // Compare new -> old |
| 440 | changes := make([]*remote.Change, 0, 64) |
| 441 | counter := int64(0) |
| 442 | for _, newFile := range newState { |
| 443 | counter++ |
| 444 | if throttle != 0 && counter%2000 == 0 { |
| 445 | time.Sleep(throttle) |
| 446 | } |
| 447 | |
| 448 | if oldFile, ok := oldState[newFile.Path]; ok { |
| 449 | if oldFile.IsDir != newFile.IsDir || oldFile.Size != newFile.Size || oldFile.MtimeUnix != newFile.MtimeUnix || oldFile.MtimeUnixNano != newFile.MtimeUnixNano { |
| 450 | if stream != nil { |
| 451 | changes = append(changes, &remote.Change{ |
| 452 | ChangeType: remote.ChangeType_CHANGE, |
| 453 | Path: newFile.Path[len(basePath):], |
| 454 | MtimeUnix: newFile.MtimeUnix, |
| 455 | MtimeUnixNano: newFile.MtimeUnixNano, |
| 456 | Size: newFile.Size, |
| 457 | Mode: newFile.Mode, |
| 458 | IsDir: newFile.IsDir, |
| 459 | }) |
| 460 | } |
| 461 | |
| 462 | changeAmount++ |
| 463 | } |
| 464 | } else { |
| 465 | if stream != nil { |
| 466 | changes = append(changes, &remote.Change{ |
| 467 | ChangeType: remote.ChangeType_CHANGE, |
| 468 | Path: newFile.Path[len(basePath):], |
| 469 | MtimeUnix: newFile.MtimeUnix, |
| 470 | MtimeUnixNano: newFile.MtimeUnixNano, |
| 471 | Size: newFile.Size, |
| 472 | Mode: newFile.Mode, |
| 473 | IsDir: newFile.IsDir, |
| 474 | }) |
| 475 | } |
| 476 | |
| 477 | changeAmount++ |
| 478 | } |
| 479 | |
| 480 | if len(changes) >= 64 && stream != nil { |
| 481 | err := stream.Send(&remote.ChangeChunk{Changes: changes}) |
| 482 | if err != nil { |
| 483 | return 0, errors.Wrap(err, "send changes") |
| 484 | } |
| 485 | |
| 486 | changes = make([]*remote.Change, 0, 64) |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | // Compare old -> new |
no test coverage detected