Skip to content

inode

CLASS DESCRIPTION
DirNode
DirNode(path: Path, children: dict[str, Inode] = dict())
METHOD DESCRIPTION
add_file

Add a file to the inode tree at the given path.

add_file(path: Path) -> None

Add a file to the inode tree at the given path.

Source code in nava/platform/util/files/inode.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def add_file(self, path: Path) -> None:
    """Add a file to the inode tree at the given path."""
    if len(path.parts) < 1:
        return

    node = self
    for i, part in enumerate(path.parts[:-1]):
        if part not in node.children:
            subpath = Path(*path.parts[: i + 1])
            node.children[part] = DirNode(subpath)
        child = node.children[part]
        if not isinstance(child, DirNode):
            raise ValueError(
                f"Cannot add path {path}. {node.children[part].path} is not a directory"
            )
        node = child
    part = path.parts[-1]
    node.children[part] = FileNode(path)