fn load_children(
        &self,
        ctx: &mut BuildContext,
        bootstrap_ctx: &mut BootstrapContext,
        parent: &mut Node,
        layer_idx: u16,
    ) -> Result<Vec<Tree>> {
        let mut result = Vec::new();
        if !parent.is_dir() {
            return Ok(result);
        }

        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 mut child = Node::new(
                ctx.fs_version,
                ctx.source_path.clone(),
                path.clone(),
                Overlay::UpperAddition,
                ctx.chunk_size,
                parent.explicit_uidgid,
                true,
            )
            .with_context(|| format!("failed to create node {:?}", path))?;
            child.layer_idx = layer_idx;

            // as per OCI spec, whiteout file should not be present within final image
            // or filesystem, only existed in layers.
            if !bootstrap_ctx.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, layer_idx)?;
            result.push(child);
        }

        Ok(result)
    }
/// 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,
        layer_idx: u16,
    ) -> Result<Vec<Tree>> {
        let mut result = Vec::new();
        if !parent.is_dir() {
            return Ok(result);
        }
        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 mut child = Node::new(
                ctx.fs_version,
                ctx.source_path.clone(),
                path.clone(),
                Overlay::UpperAddition,
                ctx.chunk_size,
                parent.explicit_uidgid,
                true,
            )
            .with_context(|| format!("failed to create node {:?}", path))?;
            child.layer_idx = layer_idx;
            // as per OCI spec, whiteout file should not be present within final image
            // or filesystem, only existed in layers.
            if !bootstrap_ctx.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, layer_idx)?;
            result.push(child);
        }
        Ok(result)
    }
fn load_children ( & self , ctx : & mut BuildContext , bootstrap_ctx : & mut BootstrapContext , parent : & mut Node , layer_idx : u16 , ) -> Result < Vec < Tree > > { let mut result = Vec :: new ( ) ; if ! parent . is_dir ( ) { return Ok ( result ) ; } 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 mut child = Node :: new ( ctx . fs_version , ctx . source_path . clone ( ) , path . clone ( ) , Overlay :: UpperAddition , ctx . chunk_size , parent . explicit_uidgid , true , ) . with_context ( | | format ! ( " " path ) ) ? ; child . layer_idx = layer_idx ; // as per OCI spec, whiteout file should not be present within final image // or filesystem, only existed in layers. if ! bootstrap_ctx . 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 , layer_idx ) ? ; 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
layer_idx
u16
&self
ctx
&mut BuildContext
bootstrap_ctx
&mut BootstrapContext
parent
&mut Node
layer_idx
u16