From b8d357402595cbedf04d11e7d0ff6084cbd4193a Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 6 Jan 2023 12:20:47 -0500 Subject: [PATCH] Only delete the single temporary file. Don't interfere with uploads in other requests. --- src/Assets/Uploader.php | 12 +----------- tests/Assets/AssetTest.php | 3 ++- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Assets/Uploader.php b/src/Assets/Uploader.php index d740a8ae40..9493d6a4c3 100644 --- a/src/Assets/Uploader.php +++ b/src/Assets/Uploader.php @@ -2,18 +2,15 @@ namespace Statamic\Assets; -use Illuminate\Filesystem\Filesystem; use Statamic\Facades\Glide; use Symfony\Component\HttpFoundation\File\UploadedFile; abstract class Uploader { - private $files; private $glideTmpPath; public function __construct() { - $this->files = app(Filesystem::class); $this->glideTmpPath = storage_path('statamic/glide/tmp'); } @@ -23,7 +20,7 @@ public function upload(UploadedFile $file) $this->write($source, $path = $this->uploadPath($file)); - $this->deleteTemporaryFiles(); + app('files')->delete($source); return $path; } @@ -59,13 +56,6 @@ private function write($sourcePath, $destinationPath) } } - private function deleteTemporaryFiles() - { - if ($this->files->exists($this->glideTmpPath)) { - $this->files->deleteDirectory($this->glideTmpPath); - } - } - abstract protected function uploadPath(UploadedFile $file); protected function uploadPathPrefix() diff --git a/tests/Assets/AssetTest.php b/tests/Assets/AssetTest.php index 04a828e7fb..460585708f 100644 --- a/tests/Assets/AssetTest.php +++ b/tests/Assets/AssetTest.php @@ -1628,7 +1628,8 @@ public function it_can_upload_an_image_into_a_container_with_glide_config() $return = $asset->upload(UploadedFile::fake()->image('asset.jpg', 20, 30)); $this->assertEquals($asset, $return); - $this->assertDirectoryNotExists(storage_path('statamic/glide/tmp')); + $this->assertDirectoryExists($glideDir = storage_path('statamic/glide/tmp')); + $this->assertEmpty(app('files')->allFiles($glideDir)); // no temp files Storage::disk('test')->assertExists('path/to/asset.jpg'); $this->assertEquals('path/to/asset.jpg', $asset->path()); Event::assertDispatched(AssetUploaded::class, function ($event) use ($asset) {