I have two disks defined in my filesystems.php
config file:
'd1' => [
'driver' => 'local',
'root' => storage_path('app/d1'),
],
'd2' => [
'driver' => 'local',
'root' => storage_path('app/d2'),
],
These disk could also be Amazon S3 buckets, and there could be combination of S3 bucket and a local disk.
Let's say I have a file as app/d1/myfile.txt
which I want to move to app/d2/myfile.txt
.
What I'm doing now is
$f = 'myfile.txt';
$file = Storage::disk('d1')->get($f);
Storage::disk('d2')->put($f, $file);
and leaving the original file on d1 as it doesn't bother me (I periodically delete files from d1).
My questions are:
Is the code below atomic, how would I check if it was, and if not how would I make it atomic (for the scenarios when the files are 1GB or something similar in size):
$f = 'myfile.txt';
$file = Storage::disk('d1')->get($f);
Storage::disk('d2')->put($f, $file);
Storage::disk('d1')->delete($f);
Is there a simple way to move files from one disk to another using the Storage
facade. At the moment I need it to work from one local disk to another but in the future I might need to move them from one S3 bucket to the same one, from one S3 bucket to another one, or from local disk to a S3 bucket.
Thanks