gcsfs icon indicating copy to clipboard operation
gcsfs copied to clipboard

Implement rmdir method for HNS buckets

Open Mahalaxmibejugam opened this issue 3 weeks ago • 6 comments

rmdir method provides an implementation for deletion of empty directories for Hierarchical Namespace (HNS) enabled buckets.

  • HNS-Aware Deletion: For HNS-enabled buckets, it uses the delete_folder API to perform an atomic deletion of the specified empty folder.
  • Fallback Mechanism: If a bucket is not HNS-enabled or if the path refers to the bucket itself (with no folder specified), it reverts to the GCSFileSystem _rmdir implementation.
  • Error Handling: It translates GCS-specific API exceptions into standard Python errors for fsspec compatibility
    1. NotFound is raised as FileNotFoundError. NotFound would be thrown by the API if the path is a file or if it doesn't exist.
    2. FailedPrecondition (for non-empty directories) is raised as OSError.
  • Cache Invalidation: On successful deletion, it invalidates the cache for the deleted path and its parent to ensure the filesystem view remains consistent.
  • Testing:Tests are added to validate the new rmdir logic, covering successful deletions on HNS buckets, correct error handling for non-empty or non-existent directories, and ensuring the method properly falls back to the standard behavior for non-HNS buckets

Mahalaxmibejugam avatar Dec 19 '25 17:12 Mahalaxmibejugam