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