Migrated fixup_permissions to OCaml