diff --git a/src/Filesystem/FlysystemAdapter.php b/src/Filesystem/FlysystemAdapter.php index 19b9f8c43dc..7253de14c43 100644 --- a/src/Filesystem/FlysystemAdapter.php +++ b/src/Filesystem/FlysystemAdapter.php @@ -56,6 +56,14 @@ public function exists($path) return parent::exists($path); } + public function put($path, $contents) + { + // Flysystem creates any missing parent directories as part of the write. Making + // the directory first is another request per write on a remote disk, and on + // object stores it leaves an empty "directory" object behind each time. + return $this->filesystem->put($this->normalizePath($path), $contents); + } + public function getFiles($path, $recursive = false) { return $this->collection( diff --git a/tests/Filesystem/FlysystemAdapterTest.php b/tests/Filesystem/FlysystemAdapterTest.php index b7f45a04687..47f438155e8 100644 --- a/tests/Filesystem/FlysystemAdapterTest.php +++ b/tests/Filesystem/FlysystemAdapterTest.php @@ -93,4 +93,14 @@ public function it_throws_an_exception_when_requesting_absolute_paths() $this->adapter->withAbsolutePaths(); } + + #[Test] + public function putting_a_file_does_not_make_the_directory_first() + { + $filesystem = \Mockery::mock(\Illuminate\Filesystem\FilesystemAdapter::class); + $filesystem->shouldReceive('put')->with('sub/dir/filename.txt', 'Hello World')->once()->andReturnTrue(); + $filesystem->shouldNotReceive('makeDirectory'); + + $this->assertTrue((new FlysystemAdapter($filesystem))->put('sub/dir/filename.txt', 'Hello World')); + } }