Skip to content

Commit

Permalink
Only delete the single temporary file. Don't interfere with uploads i…
Browse files Browse the repository at this point in the history
…n other requests.
  • Loading branch information
jasonvarga committed Jan 6, 2023
1 parent 7317217 commit b8d3574
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/Assets/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -23,7 +20,7 @@ public function upload(UploadedFile $file)

$this->write($source, $path = $this->uploadPath($file));

$this->deleteTemporaryFiles();
app('files')->delete($source);

return $path;
}
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b8d3574

Please sign in to comment.