FileUtils.isActionPermittedForFileHierarchy checks if user has permissions for given action. The checks are made by impersonating the user.
However, the listing of child dirs are done as the hiveserver2 user. If the hive user doesn't have permissions on the filesystem, it gives incorrect error that the user doesn't have permissions to perform the action.
Impersonating the end user for all file operations in that function is also logically correct thing to do.