public static void ensurePathIsWritable(Path rootHDFSDirPath, HiveConf conf) throws IOException {
    FsPermission writableHDFSDirPermission = new FsPermission((short)00733);
    FileSystem fs = rootHDFSDirPath.getFileSystem(conf);

    if (!fs.exists(rootHDFSDirPath)) {
      synchronized (ROOT_HDFS_DIR_LOCK) {
        if (!fs.exists(rootHDFSDirPath)) {
          Utilities.createDirsWithPermission(conf, rootHDFSDirPath, writableHDFSDirPermission, true);
        }
      }
    }
    FsPermission currentHDFSDirPermission = fs.getFileStatus(rootHDFSDirPath).getPermission();
    if (rootHDFSDirPath.toUri() != null) {
      String schema = rootHDFSDirPath.toUri().getScheme();
      LOG.debug("HDFS dir: " + rootHDFSDirPath + " with schema " + schema + ", permission: " +
          currentHDFSDirPermission);
    } else {
      LOG.debug(
        "HDFS dir: " + rootHDFSDirPath + ", permission: " + currentHDFSDirPermission);
    }
    // If the root HDFS scratch dir already exists, make sure it is writeable.
    if (!isWritable(currentHDFSDirPermission, writableHDFSDirPermission) &&
        !attemptMakePathWritable(fs, rootHDFSDirPath,
            FsPermission.createImmutable((short) (currentHDFSDirPermission.toShort() | writableHDFSDirPermission.toShort())))) {
      throw new RuntimeException(
          "The dir: " + rootHDFSDirPath + " should be writable. Current permissions are: " + currentHDFSDirPermission);
    }
  }
Checks if path passed in exists and has writable permissions.
The path will be created if it does not exist.
@param rootHDFSDirPath
@param conf
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java