mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Ensure that multisite s3 uploads are tombstoned correctly (#6769)
* FIX: Ensure that multisite uploads are tombstoned into the correct paths * Move multisite specs to spec/multisite/s3_store_spec.rb
This commit is contained in:
@@ -12,7 +12,9 @@ module FileStore
|
||||
attr_reader :s3_helper
|
||||
|
||||
def initialize(s3_helper = nil)
|
||||
@s3_helper = s3_helper || S3Helper.new(s3_bucket, TOMBSTONE_PREFIX)
|
||||
@s3_helper = s3_helper || S3Helper.new(s3_bucket,
|
||||
Rails.configuration.multisite ? multisite_tombstone_prefix : TOMBSTONE_PREFIX
|
||||
)
|
||||
end
|
||||
|
||||
def store_upload(file, upload, content_type = nil)
|
||||
@@ -87,6 +89,10 @@ module FileStore
|
||||
@s3_helper.update_tombstone_lifecycle(grace_period)
|
||||
end
|
||||
|
||||
def multisite_tombstone_prefix
|
||||
File.join("uploads", "tombstone", RailsMultisite::ConnectionManagement.current_db, "/")
|
||||
end
|
||||
|
||||
def path_for(upload)
|
||||
url = upload.try(:url)
|
||||
FileStore::LocalStore.new.path_for(upload) if url && url[/^\/[^\/]/]
|
||||
|
||||
@@ -39,14 +39,27 @@ class S3Helper
|
||||
end
|
||||
|
||||
# delete the file
|
||||
s3_filename.prepend(multisite_upload_path) if Rails.configuration.multisite
|
||||
s3_bucket.object(get_path_for_s3_upload(s3_filename)).delete
|
||||
rescue Aws::S3::Errors::NoSuchKey
|
||||
end
|
||||
|
||||
def copy(source, destination, options: {})
|
||||
if !Rails.configuration.multisite
|
||||
options[:copy_source] = File.join(@s3_bucket_name, source)
|
||||
else
|
||||
if @s3_bucket_folder_path
|
||||
bucket_folder, filename = begin
|
||||
source.split("/".freeze, 2)
|
||||
end
|
||||
options[:copy_source] = File.join(@s3_bucket_name, bucket_folder, multisite_upload_path, filename)
|
||||
else
|
||||
options[:copy_source] = File.join(@s3_bucket_name, multisite_upload_path, source)
|
||||
end
|
||||
end
|
||||
s3_bucket
|
||||
.object(destination)
|
||||
.copy_from(options.merge(copy_source: File.join(@s3_bucket_name, source)))
|
||||
.copy_from(options)
|
||||
end
|
||||
|
||||
# make sure we have a cors config for assets
|
||||
@@ -194,6 +207,10 @@ class S3Helper
|
||||
path
|
||||
end
|
||||
|
||||
def multisite_upload_path
|
||||
File.join("uploads", RailsMultisite::ConnectionManagement.current_db, "/")
|
||||
end
|
||||
|
||||
def s3_resource
|
||||
Aws::S3::Resource.new(@s3_options)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user