Class: GitlabUploader
Direct Known Subclasses
AttachmentUploader, AvatarUploader, Ci::PipelineArtifactUploader, Ci::SecureFileUploader, DeletedObjectUploader, DependencyProxy::FileUploader, DesignManagement::DesignV432x230Uploader, ExternalDiffUploader, FileUploader, JobArtifactUploader, LfsObjectUploader, MetricImageUploader, Packages::Debian::ComponentFileUploader, Packages::Debian::DistributionReleaseFileUploader, Packages::Npm::MetadataCacheUploader, Packages::Nuget::SymbolUploader, Packages::PackageFileUploader, Packages::Rpm::RepositoryFileUploader, Pages::DeploymentUploader, Terraform::StateUploader, VirtualRegistries::CachedResponseUploader
Constant Summary
collapse
- PROTECTED_METHODS =
%i[filename cache_dir work_dir store_dir].freeze
- ObjectNotReadyError =
Class.new(StandardError)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(model, mounted_as = nil, **uploader_context) ⇒ GitlabUploader
Returns a new instance of GitlabUploader.
55
56
57
|
# File 'app/uploaders/gitlab_uploader.rb', line 55
def initialize(model, mounted_as = nil, **uploader_context)
super(model, mounted_as)
end
|
Class Method Details
.absolute_path(upload_record) ⇒ Object
36
37
38
|
# File 'app/uploaders/gitlab_uploader.rb', line 36
def absolute_path(upload_record)
File.join(root, upload_record.path)
end
|
.base_dir ⇒ Object
represent the directory namespacing at the class level
28
29
30
|
# File 'app/uploaders/gitlab_uploader.rb', line 28
def base_dir
options.fetch('base_dir', '')
end
|
.file_storage? ⇒ Boolean
32
33
34
|
# File 'app/uploaders/gitlab_uploader.rb', line 32
def file_storage?
storage == CarrierWave::Storage::File
end
|
.options ⇒ Object
19
20
21
|
# File 'app/uploaders/gitlab_uploader.rb', line 19
def options
ObjectStorage::Config::LOCATIONS.fetch(storage_location_identifier)
end
|
.root ⇒ Object
23
24
25
|
# File 'app/uploaders/gitlab_uploader.rb', line 23
def root
options.storage_path
end
|
.storage_location(location) ⇒ Object
14
15
16
17
|
# File 'app/uploaders/gitlab_uploader.rb', line 14
def storage_location(location)
self.storage_location_identifier = location
_ = options end
|
.version(*args, **kwargs, &block) ⇒ Object
40
41
42
43
44
45
46
|
# File 'app/uploaders/gitlab_uploader.rb', line 40
def version(*args, **kwargs, &block)
raise "using CarrierWave alternate file version is not supported"
end
|
Instance Method Details
#cache_dir ⇒ Object
83
84
85
|
# File 'app/uploaders/gitlab_uploader.rb', line 83
def cache_dir
File.join(root, base_dir, 'tmp/cache')
end
|
#cached_size ⇒ Object
109
110
111
|
# File 'app/uploaders/gitlab_uploader.rb', line 109
def cached_size
size
end
|
#check_remote_file_existence_on_upload? ⇒ Boolean
159
160
161
|
# File 'app/uploaders/gitlab_uploader.rb', line 159
def check_remote_file_existence_on_upload?
true
end
|
#empty_size? ⇒ Boolean
79
80
81
|
# File 'app/uploaders/gitlab_uploader.rb', line 79
def empty_size?
size == 0
end
|
#exists? ⇒ Boolean
75
76
77
|
# File 'app/uploaders/gitlab_uploader.rb', line 75
def exists?
file.present?
end
|
#file_cache_storage? ⇒ Boolean
63
64
65
|
# File 'app/uploaders/gitlab_uploader.rb', line 63
def file_cache_storage?
cache_storage.is_a?(CarrierWave::Storage::File)
end
|
#filename ⇒ Object
91
92
93
|
# File 'app/uploaders/gitlab_uploader.rb', line 91
def filename
super || file&.filename
end
|
#local_url ⇒ Object
105
106
107
|
# File 'app/uploaders/gitlab_uploader.rb', line 105
def local_url
File.join('/', self.class.base_dir, dynamic_segment, filename)
end
|
#model_valid? ⇒ Boolean
101
102
103
|
# File 'app/uploaders/gitlab_uploader.rb', line 101
def model_valid?
!!model
end
|
#move_to_cache ⇒ Object
67
68
69
|
# File 'app/uploaders/gitlab_uploader.rb', line 67
def move_to_cache
file_storage?
end
|
#move_to_store ⇒ Object
71
72
73
|
# File 'app/uploaders/gitlab_uploader.rb', line 71
def move_to_store
file_storage?
end
|
#multi_read(offsets) ⇒ Object
131
132
133
134
135
136
137
138
|
# File 'app/uploaders/gitlab_uploader.rb', line 131
def multi_read(offsets)
open do |stream|
offsets.map do |start_offset, end_offset|
stream.seek(start_offset)
stream.read(end_offset - start_offset + 1)
end
end
end
|
#open ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'app/uploaders/gitlab_uploader.rb', line 113
def open
stream =
if file_storage?
File.open(path, "rb") if path
elsif url
::Gitlab::HttpIO.new(url, cached_size)
end
return unless stream
return stream unless block_given?
begin
yield(stream)
ensure
stream.close
end
end
|
#options ⇒ Object
59
60
61
|
# File 'app/uploaders/gitlab_uploader.rb', line 59
def options
self.class.options
end
|
#relative_path ⇒ Object
95
96
97
98
99
|
# File 'app/uploaders/gitlab_uploader.rb', line 95
def relative_path
return path if pathname.relative?
pathname.relative_path_from(Pathname.new(root))
end
|
#replace_file_without_saving!(file) ⇒ Object
Used to replace an existing upload with another file
without modifying stored metadata Use this method only to repair/replace an existing upload, or to upload to a Geo secondary node
145
146
147
148
149
|
# File 'app/uploaders/gitlab_uploader.rb', line 145
def replace_file_without_saving!(file)
raise ArgumentError, 'should be a CarrierWave::SanitizedFile' unless file.is_a? CarrierWave::SanitizedFile
storage.store!(file)
end
|
#sync_model_object_store? ⇒ Boolean
163
164
165
|
# File 'app/uploaders/gitlab_uploader.rb', line 163
def sync_model_object_store?
false
end
|
#url_or_file_path(url_options = {}) ⇒ Object
151
152
153
154
155
156
157
|
# File 'app/uploaders/gitlab_uploader.rb', line 151
def url_or_file_path(url_options = {})
if file_storage?
'file://' + path
else
url(url_options)
end
end
|
#work_dir ⇒ Object
87
88
89
|
# File 'app/uploaders/gitlab_uploader.rb', line 87
def work_dir
File.join(root, base_dir, 'tmp/work')
end
|