()
| 628 | } |
| 629 | |
| 630 | async function listFiles() { |
| 631 | const localTree = await getLocalTree({ localForage, branch, folder, extension, depth }); |
| 632 | if (localTree) { |
| 633 | const branch = await getDefaultBranch(); |
| 634 | // if the branch was forced pushed the local tree sha can be removed from the remote tree |
| 635 | const localTreeInBranch = await isShaExistsInBranch(branch.name, localTree.head); |
| 636 | if (!localTreeInBranch) { |
| 637 | console.log( |
| 638 | `Can't find local tree head '${localTree.head}' in branch '${branch.name}', rebuilding local tree`, |
| 639 | ); |
| 640 | return listAllFilesAndPersist(); |
| 641 | } |
| 642 | const diff = await getDiffFromLocalTree({ |
| 643 | branch, |
| 644 | localTree, |
| 645 | folder, |
| 646 | extension, |
| 647 | depth, |
| 648 | getDifferences, |
| 649 | getFileId, |
| 650 | filterFile, |
| 651 | }).catch(e => { |
| 652 | console.log('Failed getting diff from local tree:', e); |
| 653 | return null; |
| 654 | }); |
| 655 | |
| 656 | if (!diff) { |
| 657 | console.log(`Diff is null, rebuilding local tree`); |
| 658 | return listAllFilesAndPersist(); |
| 659 | } |
| 660 | |
| 661 | if (diff.length === 0) { |
| 662 | // return local copy |
| 663 | return localTree.files; |
| 664 | } else { |
| 665 | const deleted = diff.reduce((acc, d) => { |
| 666 | acc[d.path] = d.deleted; |
| 667 | return acc; |
| 668 | }, {} as Record<string, boolean>); |
| 669 | const newCopy = sortBy( |
| 670 | unionBy( |
| 671 | diff.filter(d => !deleted[d.path]), |
| 672 | localTree.files.filter(f => !deleted[f.path]), |
| 673 | file => file.path, |
| 674 | ), |
| 675 | file => file.path, |
| 676 | ); |
| 677 | |
| 678 | await persistLocalTree({ |
| 679 | localForage, |
| 680 | localTree: { head: branch.sha, files: newCopy }, |
| 681 | branch: branch.name, |
| 682 | depth, |
| 683 | extension, |
| 684 | folder, |
| 685 | }); |
| 686 | |
| 687 | return newCopy; |
no test coverage detected