Add FileStore::S3Store#copy_file.

This commit is contained in:
Guo Xiang Tan
2018-08-08 11:30:34 +08:00
parent 3f6ad65aec
commit aafff740d2
3 changed files with 53 additions and 14 deletions
+16 -9
View File
@@ -30,20 +30,25 @@ class S3Helper
end
def remove(s3_filename, copy_to_tombstone = false)
bucket = s3_bucket
# copy the file in tombstone
if copy_to_tombstone && @tombstone_prefix.present?
bucket
.object(File.join(@tombstone_prefix, s3_filename))
.copy_from(copy_source: File.join(@s3_bucket_name, get_path_for_s3_upload(s3_filename)))
self.copy(
File.join(@tombstone_prefix, s3_filename),
get_path_for_s3_upload(s3_filename)
)
end
# delete the file
bucket.object(get_path_for_s3_upload(s3_filename)).delete
s3_bucket.object(get_path_for_s3_upload(s3_filename)).delete
rescue Aws::S3::Errors::NoSuchKey
end
def copy(source, destination)
s3_bucket
.object(source)
.copy_from(copy_source: File.join(@s3_bucket_name, destination))
end
# make sure we have a cors config for assets
# otherwise we will have no fonts
def ensure_cors!
@@ -186,9 +191,11 @@ class S3Helper
end
def s3_bucket
bucket = s3_resource.bucket(@s3_bucket_name)
bucket.create unless bucket.exists?
bucket
@s3_bucket ||= begin
bucket = s3_resource.bucket(@s3_bucket_name)
bucket.create unless bucket.exists?
bucket
end
end
def check_missing_site_options