fn load_children(&self, parent: &mut Node, overlay: bool) -> Result<Vec<Tree>> {
        let mut result = Vec::new();

        if !parent.is_dir() {
            return Ok(result);
        }

        // Ignore children of the directory including OCISPEC_WHITEOUT_OPAQUE file
        if overlay && parent.path.join(OCISPEC_WHITEOUT_OPAQUE).exists() {
            parent.overlay = Overlay::UpperOpaque;
        }

        let children = fs::read_dir(&parent.path)?;
        let children = children.collect::<Result<Vec<DirEntry>>>()?;

        for child in children {
            let path = child.path();
            let child = Node::new(
                self.root_path.clone(),
                path.clone(),
                Overlay::UpperAddition,
                parent.explicit_uidgid,
            )?;

            // Ignore special file
            if child.file_type() == "" {
                continue;
            }

            let mut child_tree = Tree::new(child);
            let name = child_tree.node.name();

            // Add overlay flag to node
            if overlay {
                // Ignore OCISPEC_WHITEOUT_OPAQUE file
                if name == OCISPEC_WHITEOUT_OPAQUE {
                    continue;
                }
                // Handle whiteout file
                if let Some(n) = name.to_str() {
                    if n.starts_with(OCISPEC_WHITEOUT_PREFIX) {
                        child_tree.node.path =
                            parent.path.join(&n[OCISPEC_WHITEOUT_PREFIX.len()..]);
                        child_tree.node.overlay = Overlay::UpperRemoval;
                        result.insert(0, child_tree);
                        continue;
                    }
                }
            }

            child_tree.children = self.load_children(&mut child_tree.node, overlay)?;

            let child_overlay = &child_tree.node.overlay;
            if overlay
                && (child_overlay == &Overlay::UpperRemoval
                    || child_overlay == &Overlay::UpperOpaque)
            {
                // Put the whiteout file of upper layer in the front,
                // so that it can be applied to the node tree of lower layer first than other files of upper layer.
                result.insert(0, child_tree);
            } else {
                result.push(child_tree);
            }
        }

        Ok(result)
    }
/// Walk directory to build node tree by DFS,
/// support overlay defined in OCI image layer spec (https://github.com/opencontainers/image-spec/blob/master/layer.md)
Walk directory to build node tree by DFS,
support overlay defined in OCI image layer spec
Walk directory to build node tree by DFS support overlay defined in OCI image layer spec
fn load_children(&self, parent: &mut Node, overlay: bool) -> Result<Vec<Tree>> {
        let mut result = Vec::new();
        if !parent.is_dir() {
            return Ok(result);
        }
        // Ignore children of the directory including OCISPEC_WHITEOUT_OPAQUE file
        if overlay && parent.path.join(OCISPEC_WHITEOUT_OPAQUE).exists() {
            parent.overlay = Overlay::UpperOpaque;
        }
        let children = fs::read_dir(&parent.path)?;
        let children = children.collect::<Result<Vec<DirEntry>>>()?;
        for child in children {
            let path = child.path();
            let child = Node::new(
                self.root_path.clone(),
                path.clone(),
                Overlay::UpperAddition,
                parent.explicit_uidgid,
            )?;
            // Ignore special file
            if child.file_type() == "" {
                continue;
            }
            let mut child_tree = Tree::new(child);
            let name = child_tree.node.name();
            // Add overlay flag to node
            if overlay {
                // Ignore OCISPEC_WHITEOUT_OPAQUE file
                if name == OCISPEC_WHITEOUT_OPAQUE {
                    continue;
                }
                // Handle whiteout file
                if let Some(n) = name.to_str() {
                    if n.starts_with(OCISPEC_WHITEOUT_PREFIX) {
                        child_tree.node.path =
                            parent.path.join(&n[OCISPEC_WHITEOUT_PREFIX.len()..]);
                        child_tree.node.overlay = Overlay::UpperRemoval;
                        result.insert(0, child_tree);
                        continue;
                    }
                }
            }
            child_tree.children = self.load_children(&mut child_tree.node, overlay)?;
            let child_overlay = &child_tree.node.overlay;
            if overlay
                && (child_overlay == &Overlay::UpperRemoval
                    || child_overlay == &Overlay::UpperOpaque)
            {
                // Put the whiteout file of upper layer in the front,
                // so that it can be applied to the node tree of lower layer first than other files of upper layer.
                result.insert(0, child_tree);
            } else {
                result.push(child_tree);
            }
        }
        Ok(result)
    }
fn load_children ( & self , parent : & mut Node , overlay : bool ) -> Result < Vec < Tree > > { let mut result = Vec :: new ( ) ; if ! parent . is_dir ( ) { return Ok ( result ) ; } // Ignore children of the directory including OCISPEC_WHITEOUT_OPAQUE file if overlay && parent . path . join ( OCISPEC_WHITEOUT_OPAQUE ) . exists ( ) { parent . overlay = Overlay :: UpperOpaque ; } let children = fs :: read_dir ( & parent . path ) ? ; let children = children . collect :: < Result < Vec < DirEntry > > > ( ) ? ; for child in children { let path = child . path ( ) ; let child = Node :: new ( self . root_path . clone ( ) , path . clone ( ) , Overlay :: UpperAddition , parent . explicit_uidgid , ) ? ; // Ignore special file if child . file_type ( ) == " " { continue ; } let mut child_tree = Tree :: new ( child ) ; let name = child_tree . node . name ( ) ; // Add overlay flag to node if overlay { // Ignore OCISPEC_WHITEOUT_OPAQUE file if name == OCISPEC_WHITEOUT_OPAQUE { continue ; } // Handle whiteout file if let Some ( n ) = name . to_str ( ) { if n . starts_with ( OCISPEC_WHITEOUT_PREFIX ) { child_tree . node . path = parent . path . join ( & n [ OCISPEC_WHITEOUT_PREFIX . len ( ) .. ] ) ; child_tree . node . overlay = Overlay :: UpperRemoval ; result . insert ( 0 , child_tree ) ; continue ; } } } child_tree . children = self . load_children ( & mut child_tree . node , overlay ) ? ; let child_overlay = & child_tree . node . overlay ; if overlay && ( child_overlay == & Overlay :: UpperRemoval || child_overlay == & Overlay :: UpperOpaque ) { // Put the whiteout file of upper layer in the front, // so that it can be applied to the node tree of lower layer first than other files of upper layer. result . insert ( 0 , child_tree ) ; } else { result . push ( child_tree ) ; } } Ok ( result ) }
Walk directory to build node tree by DFS,
support overlay defined in OCI image layer spec (https://github.com/opencontainers/image-spec/blob/master/layer.md)
Walk directory to build node tree by DFS support overlay defined in OCI image layer spec ( https : // github . com / opencontainers / image - spec / blob / master / layer . md )
&self
parent
&mut Node
overlay
bool
&self
parent
&mut Node
overlay
bool