public static FileStatus getPathOrParentThatExists(FileSystem fs, Path path) throws IOException {
    FileStatus stat = FileUtils.getFileStatusOrNull(fs, path);
    if (stat != null) {
      return stat;
    }
    Path parentPath = path.getParent();
    return getPathOrParentThatExists(fs, parentPath);
  }
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