diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/uploaders/object_storage.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/uploaders/object_storage.rb')
-rw-r--r-- | app/uploaders/object_storage.rb | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/app/uploaders/object_storage.rb b/app/uploaders/object_storage.rb index ac1f022c63f..d4c74ce277f 100644 --- a/app/uploaders/object_storage.rb +++ b/app/uploaders/object_storage.rb @@ -30,6 +30,8 @@ module ObjectStorage REMOTE = 2 end + SUPPORTED_STORES = [Store::LOCAL, Store::REMOTE].freeze + module Extension # this extension is the glue between the ObjectStorage::Concern and RecordsUploads::Concern module RecordsUploads @@ -178,10 +180,14 @@ module ObjectStorage end def workhorse_authorize(has_length:, maximum_size: nil) - if self.object_store_enabled? && self.direct_upload_enabled? - { RemoteObject: workhorse_remote_upload_options(has_length: has_length, maximum_size: maximum_size) } - else - { TempPath: workhorse_local_upload_path } + {}.tap do |hash| + if self.object_store_enabled? && self.direct_upload_enabled? + hash[:RemoteObject] = workhorse_remote_upload_options(has_length: has_length, maximum_size: maximum_size) + else + hash[:TempPath] = workhorse_local_upload_path + end + + hash[:MaximumSize] = maximum_size if maximum_size.present? end end @@ -206,6 +212,20 @@ module ObjectStorage end end + class OpenFile + extend Forwardable + + # Explicitly exclude :path, because rubyzip uses that to detect "real" files. + def_delegators :@file, *(Zip::File::IO_METHODS - [:path]) + + # Even though :size is not in IO_METHODS, we do need it. + def_delegators :@file, :size + + def initialize(file) + @file = file + end + end + # allow to configure and overwrite the filename def filename @filename || super || file&.filename # rubocop:disable Gitlab/ModuleWithInstanceVariables @@ -255,6 +275,24 @@ module ObjectStorage end end + def use_open_file(&blk) + Tempfile.open(path) do |file| + file.unlink + file.binmode + + if file_storage? + IO.copy_stream(path, file) + else + streamer = lambda { |chunk, _, _| file.write(chunk) } + Excon.get(url, response_block: streamer) + end + + file.seek(0, IO::SEEK_SET) + + yield OpenFile.new(file) + end + end + # # Move the file to another store # |