Skip to content

Commit 3adfd3c

Browse files
hansnnstayallive
andauthored
fix: Avoid manipulating config when resolving disks (#901)
* fix: Avoid manipulating config when resolving disks This commit updates the storage integration such that it does not manipulate the filesystems config when a disk is resolved. This fixes an issue when using scoped disks where the disk's prefix property was injected into the parent disk's config, making the parent disk unusable from that point forward. * Change approach * Fix phpstan * CS --------- Co-authored-by: Alex Bouma <[email protected]>
1 parent b34c6ec commit 3adfd3c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Sentry/Laravel/Features/Storage/Integration.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ function (Application $application, array $config) use ($filesystemManager): Fil
4848

4949
$diskResolver = (function (string $disk, array $config) {
5050
// This is a "hack" to make sure that the original driver is resolved by the FilesystemManager
51+
$oldConfig = config("filesystems.disks.{$disk}");
52+
5153
config(["filesystems.disks.{$disk}" => $config]);
5254

5355
/** @var FilesystemManager $this */
54-
return $this->resolve($disk);
56+
$resolved = $this->resolve($disk);
57+
58+
config(["filesystems.disks.{$disk}" => $oldConfig]);
59+
60+
return $resolved;
5561
})->bindTo($filesystemManager, FilesystemManager::class);
5662

5763
/** @var Filesystem $originalFilesystem */

test/Sentry/Features/StorageIntegrationTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ public function testDriverWorksWhenDisabled(): void
159159
$this->expectNotToPerformAssertions();
160160
}
161161

162+
public function testResolvingDiskDoesNotModifyConfig(): void
163+
{
164+
$this->resetApplicationWithConfig([
165+
'filesystems.disks' => Integration::configureDisks(config('filesystems.disks')),
166+
]);
167+
168+
$originalConfig = config('filesystems.disks.local');
169+
170+
Storage::disk('local');
171+
172+
$this->assertEquals($originalConfig, config('filesystems.disks.local'));
173+
}
174+
162175
public function testThrowsIfDiskConfigurationDoesntSpecifyDiskName(): void
163176
{
164177
$this->resetApplicationWithConfig([

0 commit comments

Comments
 (0)