@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Intended, dir privilege all-around bug")
  public static boolean isActionPermittedForFileHierarchy(FileSystem fs, FileStatus fileStatus,
      String userName, FsAction action, boolean recurse, FileSystem fsAsUser) throws Exception {
    boolean isDir = fileStatus.isDirectory();

    // for dirs user needs execute privileges as well
    FsAction dirActionNeeded = (isDir) ? action.and(FsAction.EXECUTE) : action;

    List<FileStatus> subDirsToCheck = null;
    if (isDir && recurse) {
      subDirsToCheck = new ArrayList<FileStatus>();
    }

    try {
      checkFileAccessWithImpersonation(fs, fileStatus, action, userName, subDirsToCheck, fsAsUser);
    } catch (AccessControlException err) {
      // Action not permitted for user
      LOG.warn("Action " + action + " denied on " + fileStatus.getPath() + " for user " + userName);
      return false;
    }

    if (subDirsToCheck == null || subDirsToCheck.isEmpty()) {
      // no sub dirs to be checked
      return true;
    }

    // check all children
    for (FileStatus childStatus : subDirsToCheck) {
      // check children recursively - recurse is true if we're here.
      if (!isActionPermittedForFileHierarchy(fs, childStatus, userName, action, true, fsAsUser)) {
        return false;
      }
    }
    return true;
  }
Check if user userName has permissions to perform the given FsAction action
on all files under the file whose FileStatus fileStatus is provided

@param fs
@param fileStatus
@param userName
@param action
@return
@throws IOException
common/src/java/org/apache/hadoop/hive/common/FileUtils.java