static boolean checkDirectoryOwnership(FileSystem fs,
                                         FileStatus fStatus,
                                         String userName,
                                         boolean recurse) throws IOException {
    if (fStatus == null) {
      // Non-existent file returns true.
      return true;
    }

    Path path = fStatus.getPath();
    boolean result = true;

    // Ignore non-directory files
    boolean isDir = fStatus.isDirectory();
    if (isDir) {
      if (userName != null && !userName.equals(fStatus.getOwner())) {
        return false;
      }

      if (recurse) {
        for (FileStatus subFile : fs.listStatus(path)) {
          if (!checkDirectoryOwnership(fs, subFile, userName, recurse)) {
            return false;
          }
        }
      }
    }

    return result;
  }
Recursively check the file owner and permissions, setting them to the passed in values
if the owner/perms of the file do not match.
@param fs
@param fStatus
@param userName  Owner of the file to compare/set. Null to skip this check.
@param groupName Group of the file to compare/set. Null to skip this check.
@param dirPerms  Permissions to compare/set, if the file is a directory. Null to skip this check.
@param filePerms Permissions to compare/set, if the file is a file. Null to skip this check.
@param dryRun    Dry run - check but do not actually set
@param recurse   Whether to recursively check/set the contents of a directory
@throws IOException
ql/src/java/org/apache/hadoop/hive/ql/util/HiveStrictManagedMigration.java