def builder()

in antlir/compiler/items/remove_path.py [0:0]


        def builder(subvol: Subvol):
            protected_paths = protected_path_set(subvol)
            # Reverse-lexicographic order deletes inner paths before
            # deleting the outer paths, thus minimizing conflicts between
            # `remove_paths` items.
            for item in sorted(items, reverse=True):
                if is_path_protected(item.path, protected_paths):
                    # For META_DIR, this is never reached because of
                    # make_path_normal_relative's check, but for other
                    # protected paths, this is required.
                    raise AssertionError(
                        f"Cannot remove protected {item}: {protected_paths}"
                    )
                # This ensures that there are no symlinks in item.path that
                # might take us outside of the subvolume.  Since recursive
                # `rm` does not follow symlinks, it is OK if the inode at
                # `item.path` is a symlink (or one of its sub-paths).
                path = subvol.path(item.path, no_dereference_leaf=True)
                if not os.path.lexists(path):
                    if not item.must_exist:
                        continue
                    raise AssertionError(f"Path does not exist: {item}")

                if os.path.isdir(path) and not os.path.islink(path):
                    shutil.rmtree(path)
                else:
                    os.remove(path)