gcsfs
gcsfs copied to clipboard
Implement rmdir method for HNS buckets
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
- NotFound is raised as FileNotFoundError. NotFound would be thrown by the API if the path is a file or if it doesn't exist.
- 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