/// Walk directory to build node tree by DFS
Walk directory to build node tree by DFS
Walk directory to build node tree by DFS
fn load_children(
        &self,
        ctx: &mut BuildContext,
        bootstrap_ctx: &mut BootstrapContext,
        parent: &mut Node,
    ) -> Result<Vec<Tree>> {
        let mut result = Vec::new();
        if !parent.is_dir() {
            return Ok(result);
        }
        let layered = bootstrap_ctx.f_parent_bootstrap.is_some();
        let children = fs::read_dir(parent.path())
            .with_context(|| format!("failed to read dir {:?}", parent.path()))?;
        let children = children.collect::<Result<Vec<DirEntry>, std::io::Error>>()?;
        event_tracer!("load_from_directory", +children.len());
        for child in children {
            let path = child.path();
            let child = Node::new(
                ctx.fs_version,
                ctx.source_path.clone(),
                path.clone(),
                Overlay::UpperAddition,
                ctx.chunk_size,
                parent.explicit_uidgid,
            )
            .with_context(|| format!("failed to create node {:?}", path))?;
            // as per OCI spec, whiteout file should not be present within final image
            // or filesystem, only existed in layers.
            if !layered
                && child.whiteout_type(ctx.whiteout_spec).is_some()
                && !child.is_overlayfs_opaque(ctx.whiteout_spec)
            {
                continue;
            }
            let mut child = Tree::new(child);
            child.children = self.load_children(ctx, bootstrap_ctx, &mut child.node)?;
            result.push(child);
        }
        Ok(result)
    }
fn load_children ( & self , ctx : & mut BuildContext , bootstrap_ctx : & mut BootstrapContext , parent : & mut Node , ) -> Result < Vec < Tree > > { let mut result = Vec :: new ( ) ; if ! parent . is_dir ( ) { return Ok ( result ) ; } let layered = bootstrap_ctx . f_parent_bootstrap . is_some ( ) ; let children = fs :: read_dir ( parent . path ( ) ) . with_context ( | | format ! ( " " parent path ( ) ) ) ? ; let children = children . collect :: < Result < Vec < DirEntry > , std :: io :: Error > > ( ) ? ; event_tracer ! ( " " children len ( ) ) ; for child in children { let path = child . path ( ) ; let child = Node :: new ( ctx . fs_version , ctx . source_path . clone ( ) , path . clone ( ) , Overlay :: UpperAddition , ctx . chunk_size , parent . explicit_uidgid , ) . with_context ( | | format ! ( " " path ) ) ? ; // as per OCI spec, whiteout file should not be present within final image // or filesystem, only existed in layers. if ! layered && child . whiteout_type ( ctx . whiteout_spec ) . is_some ( ) && ! child . is_overlayfs_opaque ( ctx . whiteout_spec ) { continue ; } let mut child = Tree :: new ( child ) ; child . children = self . load_children ( ctx , bootstrap_ctx , & mut child . node ) ? ; result . push ( child ) ; } Ok ( result ) }
Walk directory to build node tree by DFS
Walk directory to build node tree by DFS
&self
ctx
&mut BuildContext
bootstrap_ctx
&mut BootstrapContext
parent
&mut Node