def _add_path()

in antlir/btrfs_diff/inode_id.py [0:0]


    def _add_path(self, entry: _PathEntry, path: bytes) -> None:
        self.inner._assert_mine(entry.id)

        # Block an ID from being added as both a file and a directory, ban
        # directory hardlinks.
        for prev_path in self.inner.gen_paths(entry.id):
            prev_entry = self._get_entry(prev_path)
            if (entry.name_to_child, prev_entry.name_to_child) != (None, None):
                raise RuntimeError(
                    f"Tried to add non-file hardlink for {entry.id}"
                )
            break  # It's enough to check 1 entry

        parts = _norm_split_path(path)
        (parent,) = tail(1, self._gen_entries(parts[:-1]))
        if parent is None:
            raise RuntimeError(f"Missing ancestor for {path}")
        if parent.name_to_child is None:
            raise RuntimeError(f"The parent of {path} is a file")

        old = parent.name_to_child.get(parts[-1])
        if old is not None:
            raise RuntimeError(
                f"Adding #{entry.id.id} to {path} which has #{old.id.id}"
            )

        reverse_parent = self.inner.id_to_reverse_entries.get(parent.id.id)
        assert isinstance(reverse_parent, set) and len(reverse_parent) == 1

        parent.name_to_child[parts[-1]] = entry
        self.inner.id_to_reverse_entries[entry.id.id].add(
            _ReversePathEntry(name=parts[-1], parent_int_id=parent.id.id)
        )