feat(storage): add deleteFolderRecursive sample - #14305
Conversation
This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket. Fixes: b/521168740 [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request introduces a new script delete_folder_recursive.py that implements recursive folder deletion using the Google Cloud Storage Control API, along with corresponding integration tests in snippets_test.py. The feedback recommends moving the inline import of delete_folder_recursive in the test file to the top of the file to adhere to PEP 8 guidelines.
| def test_delete_folder_recursive( | ||
| capsys: pytest.LogCaptureFixture, hns_enabled_bucket: storage.Bucket, uuid_name: str | ||
| ) -> None: | ||
| import delete_folder_recursive |
There was a problem hiding this comment.
According to PEP 8, imports should always be placed at the top of the file, just after any module comments and docstrings, and before module globals and constants.
Please move import delete_folder_recursive to the top of the file, grouping it alphabetically with the other local imports (e.g., right after import delete_folder on line 20).
References
- PEP 8 specifies that imports should always be put at the top of the file, grouped and ordered. (link)
[Generated-by: AI]
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| delete_folder_recursive(bucket_name=sys.argv[1], folder_name=sys.argv[2]) |
There was a problem hiding this comment.
what if user doesn't provide 2nd argument ? (which might happen due to many reasons) ,
What is the behavior of storage_control_client.delete_folder_recursive
There was a problem hiding this comment.
Firstly, if user doesn't provide the folder_name, the program will throw an Index error.
Regarding the behavior of storage_control_client.delete_folder_recursive: the folder resource path is constructed as projects/_/buckets/{bucket_name}/folders/{folder_name}. If the folder name is empty, the API call fails with a validation error on the resource path and does not perform any deletion. If the bucket doesn't support hierarchical namespaces or if the folder does not exist, the API will fail with a 404 Not Found or 400 Bad Request error.
Co-authored by AI Agent
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
feat(python): add deleteFolderRecursive sample
This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.
Fixes: b/521168740
[Generated-by: AI]