apache/hadoop · error · PathIOException

Cannot delete root path

Error message

Cannot delete root path

What it means

OBSCommonUtils.rejectRootDirectoryDelete(bucket, isEmptyDir, recursive) implements delete(obs://bucket/, ...) policy: if the root directory is empty it returns true (nothing to do); if recursive=true it returns false (proceed to recursive delete); otherwise it throws PathIOException(bucket, 'Cannot delete root path'). So this error means: non-recursive delete() was invoked on a NON-EMPTY bucket root — the connector refuses a shallow delete that would need to remove uncounted children.

Source

Thrown at hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSCommonUtils.java:696

   * @param bucket     bucket name
   * @param isEmptyDir flag indicating if the directory is empty
   * @param recursive  recursive flag from command
   * @return a return code for the operation
   * @throws PathIOException if the operation was explicitly rejected.
   */
  static boolean rejectRootDirectoryDelete(final String bucket,
      final boolean isEmptyDir,
      final boolean recursive)
      throws IOException {
    LOG.info("obs delete the {} root directory of {}", bucket, recursive);
    if (isEmptyDir) {
      return true;
    }
    if (recursive) {
      return false;
    } else {
      // reject
      throw new PathIOException(bucket, "Cannot delete root path");
    }
  }

  /**
   * Make the given path and all non-existent parents into directories.
   *
   * @param owner the owner OBSFileSystem instance
   * @param path  path to create
   * @return true if a directory was created
   * @throws FileAlreadyExistsException there is a file at the path specified
   * @throws IOException                other IO problems
   * @throws ObsException               on failures inside the OBS SDK
   */
  static boolean innerMkdirs(final OBSFileSystem owner, final Path path)
      throws IOException, FileAlreadyExistsException, ObsException {
    LOG.debug("Making directory: {}", path);
    FileStatus fileStatus;
    try {

View on GitHub (pinned to 2add963021)

Solutions

  1. If clearing the bucket is intended: call fs.delete(root, true) — recursive=true is allowed and empties the bucket (still does not delete the bucket itself).
  2. If not intended: fix the path so it points at the intended subdirectory, not the bucket root; assert path.isRoot() is false before delete.
  3. Catch PathIOException around cleanup code and treat 'Cannot delete root path' as a configuration bug alert rather than retrying.
  4. For HDFS-compatible behavior, pre-check listStatus(root).length or use a marker subdirectory as the logical root of your data.

Example fix

// before
fs.delete(new Path("obs://mybucket/"), false); // non-empty root -> PathIOException

// after
Path root = new Path("obs://mybucket/");
if (shouldWipeBucket) {
  fs.delete(root, true);      // recursive clear allowed
} else {
  fs.delete(new Path(root, "staging/"), true); // target a subdir, never root
}
Defensive patterns

Strategy: validation

Validate before calling

static void requireNonRootDelete(OBSFileSystem fs, Path p, boolean recursive) throws IOException {
  if (p.isRoot() || "/".equals(p.toUri().getPath())) {
    if (!recursive) throw new IllegalArgumentException("use recursive=true to clear bucket root");
  }
}

Try / catch

try {
  fs.delete(rootPath, false);
} catch (PathIOException e) {
  if ("Cannot delete root path".equals(e.getMessage())) {
    throw new ConfigException("Cleanup targeted bucket root; fix base-dir config", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: fs.delete(new Path("obs://bucket/"), false) (or new Path("obs://bucket")) when the bucket contains any objects or directory markers; code paths that call delete(path, false) on a path that resolves to root; cleanup routines that mirror HDFS semantics where deleting a non-empty dir non-recursively throws DirectoryNotEmptyException.

Common situations: Automated cleanup scripts deleting configured 'base dir' set to the bucket root; tools ported from HDFS that call delete(dir,false) expecting ENOENT-style failure; mistyped path config dropping the subdirectory component so the effective path is root.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/d02db079e8b186d8. Report an issue: GitHub.