Skip to content

Commit f988b15

Browse files
authored
chore(Storage Control) Relocate storage control sample (#14094)
* - Relocated hierarchical-namespace/delete_empty_folder.py to be under storagecontrol/. - Fixed bad indent. - Tested script. * Added note to README. * Added type hints, because linter is complaining. * Adressing linting issues. * Restored delete folder. * Restored moved readme. * Restored readme text. * more restoration
1 parent a8651b2 commit f988b15

2 files changed

Lines changed: 426 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# GCS HNS Folder Management Scripts
2+
3+
This directory contains scripts for managing folders in Google Cloud Storage
4+
(GCS) Hierarchical Namespace (HNS) enabled buckets.
5+
6+
## Scripts
7+
8+
### `delete_empty_folders.py`
9+
10+
This script recursively deletes empty folders within a specified GCS bucket and
11+
(optional) prefix.
12+
13+
**Features:**
14+
15+
* **Recursive Deletion:** Traverses and deletes nested empty folders.
16+
* **Depth-First Deletion:** Deletes the deepest folders first to ensure parent
17+
folders are empty before deletion attempts.
18+
* **Parallel Execution:** Uses a thread pool to delete folders concurrently
19+
for improved performance.
20+
* **Configurable:** Allows setting the target bucket, folder prefix, and
21+
number of workers.
22+
* **Error Handling:** Retries on transient errors and logs failures.
23+
* **Progress Reporting:** Periodically logs deletion statistics.
24+
25+
**Usage:**
26+
27+
1. **Authenticate:** `bash gcloud auth application-default login`
28+
2. **Configure:** Update the variables at the top of the script:
29+
* `BUCKET_NAME`: The name of your GCS HNS bucket.
30+
* `FOLDER_PREFIX`: (Optional) The prefix to limit deletion scope (e.g.,
31+
`archive/`). Leave empty to scan the whole bucket. Must end with `/` if
32+
specified.
33+
* `MAX_WORKERS`: Number of concurrent deletion threads.
34+
3. **Run:** `bash python3 delete_empty_folders.py`
35+
36+
**Note:** This script *only* deletes folders. Folders containing any objects
37+
will not be deleted, and a "Failed Precondition" warning will be logged. Creating empty folders
38+
through the web interface will result in folders that are not truly empty, with a hidden 0 byte
39+
file. Use CLI instead.

0 commit comments

Comments
 (0)