From 235f172b9c13f75a74e78a262ad9d5c67bc57e4c Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 20 Jun 2022 18:35:45 +0200 Subject: [PATCH] FIX: Didn't delete upload stub when a new upload is created Reuse `Discourse.store` to prevent creation of multiple new store objects within `UploadCreator#create_for`. --- lib/upload_creator.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb index 55f690c635e..5aa02520a20 100644 --- a/lib/upload_creator.rb +++ b/lib/upload_creator.rb @@ -196,21 +196,24 @@ class UploadCreator Upload.generate_digest(@file) != sha1_before_changes end - if @opts[:existing_external_upload_key] && Discourse.store.external? + store = Discourse.store + + if @opts[:existing_external_upload_key] && store.external? should_move = external_upload_too_big || !upload_changed end if should_move # move the file in the store instead of reuploading - url = Discourse.store.move_existing_stored_upload( + url = store.move_existing_stored_upload( existing_external_upload_key: @opts[:existing_external_upload_key], upload: @upload ) else # store the file and update its url File.open(@file.path) do |f| - url = Discourse.store.store_upload(f, @upload) + url = store.store_upload(f, @upload) end + store.delete_file(@opts[:existing_external_upload_key]) if @opts[:existing_external_upload_key] end if url.present?