Skip to content

Conversation

@Mahalaxmibejugam
Copy link
Contributor

@Mahalaxmibejugam Mahalaxmibejugam commented Dec 19, 2025

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

@martindurant
Copy link
Member

Question: since HNS buckets have a true folder structure, it should be possible to ammend the directory listings cache rather than simply invalidate it when deleting, no? That could avoid unnecessary listings later on.

@ankitaluthra1
Copy link
Collaborator

/gcbrun

@Mahalaxmibejugam
Copy link
Contributor Author

Question: since HNS buckets have a true folder structure, it should be possible to ammend the directory listings cache rather than simply invalidate it when deleting, no? That could avoid unnecessary listings later on.

@martindurant Invalidating the cache for a specific path was also invalidating the cache for all parent directories in the hierarchy. I have updated the logic to remove the cache entry only for the deleted directory and to update its immediate parent to remove the deleted directory's entry.

@Mahalaxmibejugam Mahalaxmibejugam force-pushed the hns-rmdir branch 2 times, most recently from 4dd06cd to 1a3bf7b Compare December 24, 2025 14:37
@ankitaluthra1
Copy link
Collaborator

/gcbrun

1 similar comment
@ankitaluthra1
Copy link
Collaborator

/gcbrun

@ankitaluthra1
Copy link
Collaborator

/gcbrun

@Mahalaxmibejugam
Copy link
Contributor Author

Question: since HNS buckets have a true folder structure, it should be possible to ammend the directory listings cache rather than simply invalidate it when deleting, no? That could avoid unnecessary listings later on.

@martindurant Invalidating the cache for a specific path was also invalidating the cache for all parent directories in the hierarchy. I have updated the logic to remove the cache entry only for the deleted directory and to update its immediate parent to remove the deleted directory's entry.

@martindurant Can you please review the latest changes following the cache update logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants