Collect children from the tree under a given path. This function traverses the TREE table to find all files and directories under the specified parent path, applying the given options for filtering. # Arguments `txn` - Transaction providing tree access `parent_path` - Path to start from (empty for root) `options` - Collection options # Returns A `TreeCollectResult` containing all matching ite
(
txn: &T,
parent_path: &str,
options: TreeCollectOptions,
)
| 781 | /// let src_result = collect_tree(&txn, "", options)?; |
| 782 | /// ``` |
| 783 | pub fn collect_tree<T: TreeTxnT + GraphTxnT>( |
| 784 | txn: &T, |
| 785 | parent_path: &str, |
| 786 | options: TreeCollectOptions, |
| 787 | ) -> Result<TreeCollectResult, PristineError> { |
| 788 | let mut result = TreeCollectResult::new(); |
| 789 | |
| 790 | // Track directories we've seen to avoid duplicates |
| 791 | let mut seen_directories: HashSet<String> = HashSet::new(); |
| 792 | |
| 793 | // Iterate over all tree entries |
| 794 | for entry in txn.iter_tree()? { |
| 795 | let (path, inode) = entry?; |
| 796 | |
| 797 | // Skip if path doesn't start with parent_path |
| 798 | if !parent_path.is_empty() && !path.starts_with(parent_path) { |
| 799 | continue; |
| 800 | } |
| 801 | |
| 802 | // Check filters |
| 803 | if !options.should_include(&path) { |
| 804 | result.record_skipped(); |
| 805 | continue; |
| 806 | } |
| 807 | |
| 808 | // Check depth |
| 809 | if options.exceeds_depth(&path) { |
| 810 | result.record_skipped(); |
| 811 | continue; |
| 812 | } |
| 813 | |
| 814 | // Collect parent directories if needed |
| 815 | if options.collect_directories { |
| 816 | let mut current = String::new(); |
| 817 | for component in path.split('/') { |
| 818 | if !current.is_empty() { |
| 819 | current.push('/'); |
| 820 | } |
| 821 | current.push_str(component); |
| 822 | |
| 823 | // Don't add the file itself as a directory |
| 824 | if current == path { |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | // Check if we should include this directory |
| 829 | if !seen_directories.contains(¤t) |
| 830 | && options.should_include(¤t) |
| 831 | && !options.exceeds_depth(¤t) |
| 832 | { |
| 833 | seen_directories.insert(current.clone()); |
| 834 | // We don't have the inode for intermediate directories |
| 835 | // In a full implementation, we'd look this up |
| 836 | result.add_directory(TreeItem::directory(¤t, Inode::ROOT)); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 |
no test coverage detected