public static void checkFileAccessWithImpersonation(final FileSystem fs, final FileStatus stat, final FsAction action,
      final String user) throws Exception {
    UserGroupInformation proxyUser = null;
    try {
      proxyUser = getProxyUser(user);
      FileSystem fsAsUser = FileUtils.getFsAsUser(fs, proxyUser);
      checkFileAccessWithImpersonation(fs, stat, action, user, null, fsAsUser);
    } finally {
      closeFs(proxyUser);
    }
  }
Find the parent of path that exists, if path does not exist

@param fs
         file system
@param path
@return FileStatus for argument path if it exists or the first ancestor in the path that exists
@throws IOException
common/src/java/org/apache/hadoop/hive/common/FileUtils.java