( mixedEntityMappings: Record<string, MixedEntity>, skipSizeLargerThan: number, conflictAction: ConflictActionType, syncDirection: SyncDirectionType, profiler: Profiler | undefined, settings: RemotelySavePluginSettings, triggerSource: SyncTriggerSourceType, configDir: string )
| 539 | * Also deal with syncDirection which makes it more complicated |
| 540 | */ |
| 541 | const getSyncPlanInplace = async ( |
| 542 | mixedEntityMappings: Record<string, MixedEntity>, |
| 543 | skipSizeLargerThan: number, |
| 544 | conflictAction: ConflictActionType, |
| 545 | syncDirection: SyncDirectionType, |
| 546 | profiler: Profiler | undefined, |
| 547 | settings: RemotelySavePluginSettings, |
| 548 | triggerSource: SyncTriggerSourceType, |
| 549 | configDir: string |
| 550 | ) => { |
| 551 | profiler?.addIndent(); |
| 552 | profiler?.insert("getSyncPlanInplace: enter"); |
| 553 | // from long(deep) to short(shadow), descending |
| 554 | const sortedKeys = Object.keys(mixedEntityMappings).sort( |
| 555 | (k1, k2) => k2.length - k1.length |
| 556 | ); |
| 557 | profiler?.insert("getSyncPlanInplace: finish sorting"); |
| 558 | profiler?.insertSize("sizeof sortedKeys", sortedKeys); |
| 559 | |
| 560 | const keptFolder = new Set<string>(); |
| 561 | |
| 562 | for (let i = 0; i < sortedKeys.length; ++i) { |
| 563 | if (i % 100 === 0) { |
| 564 | profiler?.insertSize( |
| 565 | `sizeof sortedKeys in the beginning of i=${i}`, |
| 566 | mixedEntityMappings |
| 567 | ); |
| 568 | } |
| 569 | const key = sortedKeys[i]; |
| 570 | const mixedEntry = mixedEntityMappings[key]; |
| 571 | const { local, prevSync, remote } = mixedEntry; |
| 572 | |
| 573 | // console.debug(`getSyncPlanInplace: key=${key}`) |
| 574 | |
| 575 | if (key.endsWith("/")) { |
| 576 | // folder |
| 577 | // folder doesn't worry about mtime and size, only check their existences |
| 578 | if (keptFolder.has(key)) { |
| 579 | // parent should also be kept |
| 580 | // console.debug(`${key} in keptFolder`) |
| 581 | keptFolder.add(getParentFolder(key)); |
| 582 | // should fill the missing part |
| 583 | if (local !== undefined && remote !== undefined) { |
| 584 | mixedEntry.decisionBranch = 101; |
| 585 | mixedEntry.decision = "folder_existed_both_then_do_nothing"; |
| 586 | mixedEntry.change = false; |
| 587 | } else if (local !== undefined && remote === undefined) { |
| 588 | if ( |
| 589 | syncDirection === "incremental_pull_only" || |
| 590 | syncDirection === "incremental_pull_and_delete_only" |
| 591 | ) { |
| 592 | mixedEntry.decisionBranch = 107; |
| 593 | mixedEntry.decision = "folder_to_skip"; |
| 594 | mixedEntry.change = false; |
| 595 | } else { |
| 596 | mixedEntry.decisionBranch = 102; |
| 597 | mixedEntry.decision = |
| 598 | "folder_existed_local_then_also_create_remote"; |
no test coverage detected