Skip to content

Commit cb047a6

Browse files
authored
[12.x] Stop double prefixing S3 filesystem paths (#57534)
* default to unix slash * style
1 parent 320c5d7 commit cb047a6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Illuminate/Filesystem/AwsS3V3Adapter.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Support\Traits\Conditionable;
77
use League\Flysystem\FilesystemAdapter as FlysystemAdapter;
88
use League\Flysystem\FilesystemOperator;
9-
use League\Flysystem\PathPrefixer;
109

1110
class AwsS3V3Adapter extends FilesystemAdapter
1211
{
@@ -29,13 +28,11 @@ class AwsS3V3Adapter extends FilesystemAdapter
2928
*/
3029
public function __construct(FilesystemOperator $driver, FlysystemAdapter $adapter, array $config, S3Client $client)
3130
{
31+
$config['directory_separator'] = '/';
32+
3233
parent::__construct($driver, $adapter, $config);
3334

3435
$this->client = $client;
35-
36-
$this->prefixer = isset($config['prefix'])
37-
? new PathPrefixer($this->prefixer->prefixPath($config['prefix']), '/')
38-
: new PathPrefixer($config['root'] ?? '', '/');
3936
}
4037

4138
/**

tests/Filesystem/FilesystemAdapterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,4 +752,19 @@ public function testGetChecksum()
752752
$this->assertEquals('730bed78bccf58c2cfe44c29b71e5e6b', $filesystemAdapter->checksum('path.txt'));
753753
$this->assertEquals('a5c3556d', $filesystemAdapter->checksum('path.txt', ['checksum_algo' => 'crc32']));
754754
}
755+
756+
public function testUsesRightSeperatorForS3AdapterWithoutDoublePrefixing()
757+
{
758+
$filesystem = new FilesystemManager(new Application);
759+
$filesystemAdapter = $filesystem->createS3Driver([
760+
'region' => 'us-west-1',
761+
'bucket' => 'laravel',
762+
'root' => 'my-root',
763+
'prefix' => 'someprefix',
764+
'directory_separator' => '\\',
765+
]);
766+
767+
$path = $filesystemAdapter->path('different');
768+
$this->assertEquals('my-root/someprefix/different', $path);
769+
}
755770
}

0 commit comments

Comments
 (0)