From ad89878dd80596a01b06a32ec017f627ded65a96 Mon Sep 17 00:00:00 2001 From: Will Rowe Date: Wed, 8 Jan 2025 16:13:44 -0500 Subject: [PATCH 1/3] Add failing test --- tests/Filesystem/FilesystemManagerTest.php | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Filesystem/FilesystemManagerTest.php b/tests/Filesystem/FilesystemManagerTest.php index 8850c5557a06..4bc8e0545a73 100644 --- a/tests/Filesystem/FilesystemManagerTest.php +++ b/tests/Filesystem/FilesystemManagerTest.php @@ -99,6 +99,38 @@ public function testCanBuildScopedDisks() } } + public function testCanBuildScopedDiskFromScopedDisk() + { + try { + $filesystem = new FilesystemManager(tap(new Application, function ($app) { + $app['config'] = [ + 'filesystems.disks.local' => [ + 'driver' => 'local', + 'root' => 'root-to-be-scoped', + ], + 'filesystems.disks.scoped-from-root' => [ + 'driver' => 'scoped', + 'disk' => 'local', + 'prefix' => 'scoped-from-root-prefix', + ], + ]; + })); + + $root = $filesystem->disk('local'); + $nestedScoped = $filesystem->build([ + 'driver' => 'scoped', + 'disk' => 'scoped-from-root', + 'prefix' => 'nested-scoped-prefix', + ]); + + $nestedScoped->put('dirname/filename.txt', 'file content'); + $this->assertEquals('file content', $root->get('scoped-from-root-prefix/nested-scoped-prefix/dirname/filename.txt')); + $root->deleteDirectory('scoped-from-root-prefix'); + } finally { + rmdir(__DIR__.'/../../root-to-be-scoped'); + } + } + #[RequiresOperatingSystem('Linux|Darwin')] public function testCanBuildScopedDisksWithVisibility() { From 247f130e629f87b656bea68006f6de0affc2f242 Mon Sep 17 00:00:00 2001 From: Will Rowe Date: Wed, 8 Jan 2025 16:14:37 -0500 Subject: [PATCH 2/3] If the parent config has a prefix append the prefix to it --- src/Illuminate/Filesystem/FilesystemManager.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Filesystem/FilesystemManager.php b/src/Illuminate/Filesystem/FilesystemManager.php index dfdab7c6e7f8..3be44532c31f 100644 --- a/src/Illuminate/Filesystem/FilesystemManager.php +++ b/src/Illuminate/Filesystem/FilesystemManager.php @@ -298,7 +298,15 @@ public function createScopedDriver(array $config) return $this->build(tap( is_string($config['disk']) ? $this->getConfig($config['disk']) : $config['disk'], function (&$parent) use ($config) { - $parent['prefix'] = $config['prefix']; + if (empty($parent['prefix'])) { + $parent['prefix'] = $config['prefix']; + } else { + $separator = $parent['directory_separator'] ?? DIRECTORY_SEPARATOR; + $parentPrefix = rtrim($parent['prefix'], $separator); + $scopedPrefix = ltrim($config['prefix'], $separator); + + $parent['prefix'] = "{$parentPrefix}{$separator}{$scopedPrefix}"; + } if (isset($config['visibility'])) { $parent['visibility'] = $config['visibility']; From c8ec78efe1c70cfa0be668a737b4776f900005ff Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 9 Jan 2025 12:02:12 -0800 Subject: [PATCH 3/3] Update FilesystemManager.php --- src/Illuminate/Filesystem/FilesystemManager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Filesystem/FilesystemManager.php b/src/Illuminate/Filesystem/FilesystemManager.php index 3be44532c31f..d4d4be8e8136 100644 --- a/src/Illuminate/Filesystem/FilesystemManager.php +++ b/src/Illuminate/Filesystem/FilesystemManager.php @@ -302,6 +302,7 @@ function (&$parent) use ($config) { $parent['prefix'] = $config['prefix']; } else { $separator = $parent['directory_separator'] ?? DIRECTORY_SEPARATOR; + $parentPrefix = rtrim($parent['prefix'], $separator); $scopedPrefix = ltrim($config['prefix'], $separator);