Rename a folder in cloud storage of google cloud (volume mount) [PHP] . #174218
Why are you starting this discussion?Question What GitHub Actions topic or product is this about?Workflow Deployment Discussion DetailsHi, I have : It work fine in my local machine, how can i fix it in cloud storage (volume mount) of CLOUD RUN app ? Doker file : |
Replies: 3 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Here are solid ways to fix it (pick one): 1) If the directory is small: let FUSE do it (set a limit)Cloud Run now lets you pass FUSE mount options. Set a safe cap so FUSE will only attempt directory renames when the folder has ≤ N descendants: gcloud beta run services update YOUR_SERVICE \
--execution-environment gen2 \
--add-volume name=GCS,type=cloud-storage,bucket=YOUR_BUCKET,mount-options="rename-dir-limit=500" \
--add-volume-mount volume=GCS,mount-path=/mnt/gcs
2) The robust way today (works on any bucket): move-by-prefix in PHPDo a server-side copy → delete of all objects under use Google\Cloud\Storage\StorageClient;
$bucketName = 'YOUR_BUCKET';
$srcPrefix = 'A/'; // trailing slash
$dstPrefix = 'B/';
$storage = new StorageClient(); // ADC on Cloud Run
$bucket = $storage->bucket($bucketName);
// Stream all objects under A/
foreach ($bucket->objects(['prefix' => $srcPrefix]) as $obj) {
$src = $obj->name(); // e.g. A/foo/bar.txt
$dst = $dstPrefix . substr($src, strlen($srcPrefix)); // B/foo/bar.txt
// Server-side copy, then delete source
$bucket->object($src)->rewrite($bucket->object($dst));
$bucket->object($src)->delete();
}
// optional: remove the placeholder "A/" object if present
$placeholder = $bucket->object($srcPrefix);
if ($placeholder->exists()) $placeholder->delete();This mirrors what 3) The best UX going forward: use an HNS bucket (true folders)If you create your bucket with Hierarchical Namespace (HNS) enabled, you can rename/move folders as a single atomic metadata operation via the Example (HNS bucket): # rename folder inside the same bucket
gcloud storage mv gs://YOUR_BUCKET/A gs://YOUR_BUCKET/BOr call the JSON API Why your
|
|
Someone hack someone fuck off my life |
rename()on a Cloud Storage FUSE mount (Cloud Run volume) won’t reliably rename a directory. It often explodes with “Too many open files” because FUSE has to touch a ton of objects to simulate a folder rename. Cloud Storage isn’t a POSIX FS; “folders” are just prefixes. ([Google Cloud]1)Here are solid ways to fix it (pick one):
1) If the directory is small: let FUSE do it (set a limit)
Cloud Run now lets you pass FUSE mount options. Set a safe cap so FUSE will only attempt directory renames when the folder has ≤ N descendants:
gcloud beta run services update YOUR_SERVICE \ --execution-environment gen2 \ --add-volume name=GCS,type=cloud-storage,bucket=YOUR_BUCKET,mount-options="rename…