{"record":{"id":"0f5d401d66936bf5","repo":"apache/hadoop","slug":"no-such-file-or-directory-0f5d40","errorCode":null,"errorMessage":"No such file or directory: {}","messagePattern":"No such file or directory: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSCommonUtils.java","lineNumber":980,"sourceCode":"          LOG.debug(\"Summary: {} {}\", summary.getObjectKey(),\n              summary.getMetadata().getContentLength());\n        }\n        for (String prefix : objects.getCommonPrefixes()) {\n          LOG.debug(\"Prefix: {}\", prefix);\n        }\n      }\n      LOG.debug(\"Found non-empty directory {}\", obsKey);\n      return false;\n    } else if (obsKey.isEmpty()) {\n      LOG.debug(\"Found root directory\");\n      return true;\n    } else if (owner.isFsBucket()) {\n      LOG.debug(\"Found empty directory {}\", obsKey);\n      return true;\n    }\n\n    LOG.debug(\"Not Found: {}\", obsKey);\n    throw new FileNotFoundException(\"No such file or directory: \" + obsKey);\n  }\n\n  /**\n   * Build a {@link LocatedFileStatus} from a {@link FileStatus} instance.\n   *\n   * @param owner  the owner OBSFileSystem instance\n   * @param status file status\n   * @return a located status with block locations set up from this FS.\n   * @throws IOException IO Problems.\n   */\n  static LocatedFileStatus toLocatedFileStatus(final OBSFileSystem owner,\n      final FileStatus status) throws IOException {\n    return new LocatedFileStatus(\n        status, status.isFile() ? owner.getFileBlockLocations(status, 0,\n        status.getLen()) : null);\n  }\n\n  /**","sourceCodeStart":962,"sourceCodeEnd":998,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSCommonUtils.java#L962-L998","documentation":"In OBSCommonUtils' directory-emptiness check, after listing finds no children and the key is neither root nor an fs(POSIX)-bucket folder marker, the method concludes the directory does not exist and throws FileNotFoundException('No such file or directory: <obsKey>') where obsKey is the raw object key (not a user-facing path). For object-layout buckets, an 'empty directory' cannot be distinguished from a missing one, so absence is surfaced as FNFE during operations (e.g. delete of an empty dir) that expected the directory to exist.","triggerScenarios":"delete('obs://b/emptydir', false) or similar when 'emptydir' was never created (no 0-byte dir marker in an object bucket); racing writers where a sibling removes the marker between list and check; operations on POSIX buckets that failed to create the folder marker; keys with trailing-slash confusion where the marker was written under a slightly different name.","commonSituations":"Idempotent cleanup code deleting dirs that may not exist; POSIX vs object bucket behavior differences (fs buckets keep real folder markers, object buckets infer dirs from children); eventual-consistency windows after concurrent deletes; encoded characters producing different marker keys.","solutions":["Pre-check existence with fs.exists(path)/fs.getFileStatus(path) before operations that require the directory, and treat 'missing' as already-done for idempotent deletes.","When creating directories you will later manage, ensure the connector actually materializes markers: use fs (POSIX) buckets or write explicit 0-byte markers for object buckets.","Catch FileNotFoundException (and FileNotFound subclasses) around cleanup and convert to a no-op success when absence equals the desired end state.","Audit for trailing-slash or encoding mismatches between the creating and deleting code paths."],"exampleFix":"// before\nfs.delete(new Path(\"obs://b/staging/\"), false);\n// -> FileNotFoundException: No such file or directory: staging/\n\n// after\nPath p = new Path(\"obs://b/staging\");\ntry {\n  fs.delete(p, false);\n} catch (FileNotFoundException e) {\n  LOG.info(\"{} already absent; treating delete as success\", p);\n}","handlingStrategy":"try-catch","validationCode":"static void deleteDirIfPresent(FileSystem fs, Path p) throws IOException {\n  if (!fs.exists(p)) { LOG.debug(\"{} already absent\", p); return; }\n  fs.delete(p, false);\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.delete(dirPath, false);\n} catch (FileNotFoundException e) {\n  LOG.info(\"{} vanished before delete (race or never created) — treating as success\", dirPath);\n}","preventionTips":["Make deletes idempotent: exists() check or catch FNFE and treat as success.","Prefer fs (POSIX) buckets when your logic depends on real empty-directory markers.","Avoid trailing-slash variants of the same path across producers and consumers; pick one canonical form."],"tags":["obs","huaweicloud","file-not-found","directory-marker","idempotency"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}