fn build_tree(
    node: &mut FileTreeNode,
    path_parts: &[String],
    details: &FileDetails,
    depth: usize,
) -> (u64, u64) {
    let mut dirs: u64 = 0;
    let mut files: u64 = 0;
    if depth < path_parts.len() {
        let item = &path_parts[depth];

        if item.is_empty() {
            return (dirs, files);
        }

        let mut node = match node.find_child(item) {
            Some(n) => n,
            None => {
                let (fs_type, d, di, fi) = match details["type"].as_str() {
                    "inode/directory" => (FileTreeNodeType::Directory, details, 1, 0),
                    "inode/symlink" => {
                        let target_type = details["symlink_target_type"].as_str();
                        let (dir, fil) = if target_type == "dir" { (1, 0) } else { (0, 1) };
                        (FileTreeNodeType::Symlink, details, dir, fil)
                    }
                    _ => (FileTreeNodeType::File, details, 0, 1),
                };

                dirs += di;
                files += fi;
                let n = FileTreeNode::new(item, fs_type, d.clone());
                node.add_child(n);
                // Very gross, but it works.
                // if this can be done in a better way,
                // please show me. We just need to return the node
                // that was added via add_child().  I tried modifying
                // add_child() to return it instead of &self, but couldn't
                // get it to work.  Also, using `n` does not work.

                match node.find_child(item) {
                    Some(n2) => n2,
                    None => panic!("But that's impossible!"),
                }
            }
        };
        let (di, fi) = build_tree(&mut node, path_parts, details, depth + 1);
        dirs += di;
        files += fi;
    }
    (dirs, files)
}
// Builds a file-system tree (hierarchy) from a single file path, split into its parts.
// May be called multiple times to expand the tree.
Builds a file-system tree (hierarchy) from a single file path, split into its parts.
May be called multiple times to expand the tree.
Builds a file - system tree ( hierarchy ) from a single file path split into its parts . May be called multiple times to expand the tree .
fn build_tree(
    node: &mut FileTreeNode,
    path_parts: &[String],
    details: &FileDetails,
    depth: usize,
) -> (u64, u64) {
    let mut dirs: u64 = 0;
    let mut files: u64 = 0;
    if depth < path_parts.len() {
        let item = &path_parts[depth];
        if item.is_empty() {
            return (dirs, files);
        }
        let mut node = match node.find_child(item) {
            Some(n) => n,
            None => {
                let (fs_type, d, di, fi) = match details["type"].as_str() {
                    "inode/directory" => (FileTreeNodeType::Directory, details, 1, 0),
                    "inode/symlink" => {
                        let target_type = details["symlink_target_type"].as_str();
                        let (dir, fil) = if target_type == "dir" { (1, 0) } else { (0, 1) };
                        (FileTreeNodeType::Symlink, details, dir, fil)
                    }
                    _ => (FileTreeNodeType::File, details, 0, 1),
                };
                dirs += di;
                files += fi;
                let n = FileTreeNode::new(item, fs_type, d.clone());
                node.add_child(n);
                // Very gross, but it works.
                // if this can be done in a better way,
                // please show me. We just need to return the node
                // that was added via add_child().  I tried modifying
                // add_child() to return it instead of &self, but couldn't
                // get it to work.  Also, using `n` does not work.
                match node.find_child(item) {
                    Some(n2) => n2,
                    None => panic!("But that's impossible!"),
                }
            }
        };
        let (di, fi) = build_tree(&mut node, path_parts, details, depth + 1);
        dirs += di;
        files += fi;
    }
    (dirs, files)
}
fn build_tree ( node : & mut FileTreeNode , path_parts : & [ String ] , details : & FileDetails , depth : usize , ) -> ( u64 , u64 ) { let mut dirs : u64 = 0 ; let mut files : u64 = 0 ; if depth < path_parts . len ( ) { let item = & path_parts [ depth ] ; if item . is_empty ( ) { return ( dirs , files ) ; } let mut node = match node . find_child ( item ) { Some ( n ) => n , None => { let ( fs_type , d , di , fi ) = match details [ " " ] . as_str ( ) { " " => ( FileTreeNodeType :: Directory , details , 1 , 0 ) , " " => { let target_type = details [ " " ] . as_str ( ) ; let ( dir , fil ) = if target_type == " " { ( 1 , 0 ) } else { ( 0 , 1 ) } ; ( FileTreeNodeType :: Symlink , details , dir , fil ) } _ => ( FileTreeNodeType :: File , details , 0 , 1 ) , } ; dirs += di ; files += fi ; let n = FileTreeNode :: new ( item , fs_type , d . clone ( ) ) ; node . add_child ( n ) ; // Very gross, but it works. // if this can be done in a better way, // please show me. We just need to return the node // that was added via add_child().  I tried modifying // add_child() to return it instead of &self, but couldn't // get it to work.  Also, using `n` does not work. match node . find_child ( item ) { Some ( n2 ) => n2 , None => panic ! ( " " ) , } } } ; let ( di , fi ) = build_tree ( & mut node , path_parts , details , depth + 1 ) ; dirs += di ; files += fi ; } ( dirs , files ) }
Builds a file-system tree (hierarchy) from a single file path, split into its parts.
Builds a file - system tree ( hierarchy ) from a single file path split into its parts .
node
&mut FileTreeNode
path_parts
&[String]
details
&FileDetails
depth
usize
node
&mut FileTreeNode
path_parts
&[String]
details
&FileDetails
depth
usize