FIX: Do not prefix temp/ S3 keys with s3_bucket_folder_path in S3Helper (#14145)

This is unnecessary, as when the temporary key is created
in S3Store we already include the s3_bucket_folder_path, and
the key will always start with temp/ to assist with lifecycle
rules for multipart uploads.

This was affecting Discourse.store.object_from_path,
Discourse.store.signed_url_for_path, and possibly others.

See also: e0102a5
This commit is contained in:
Martin Brennan
2021-08-26 08:50:49 +10:00
committed by GitHub
parent 167fcb5eef
commit 841e054907
3 changed files with 30 additions and 3 deletions

View File

@ -264,7 +264,12 @@ class S3Helper
end
def get_path_for_s3_upload(path)
path = File.join(@s3_bucket_folder_path, path) if @s3_bucket_folder_path && path !~ /^#{@s3_bucket_folder_path}\//
if @s3_bucket_folder_path &&
!path.starts_with?(@s3_bucket_folder_path) &&
!path.starts_with?(File.join(FileStore::BaseStore::TEMPORARY_UPLOAD_PREFIX, @s3_bucket_folder_path))
return File.join(@s3_bucket_folder_path, path)
end
path
end