diff options
-rw-r--r-- | app/uploaders/gitlab_uploader.rb | 10 | ||||
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 2 | ||||
-rw-r--r-- | app/uploaders/legacy_artifact_uploader.rb | 2 | ||||
-rw-r--r-- | app/uploaders/lfs_object_uploader.rb | 2 | ||||
-rw-r--r-- | spec/support/shared_examples/uploaders/gitlab_uploader_shared_examples.rb | 8 |
5 files changed, 24 insertions, 0 deletions
diff --git a/app/uploaders/gitlab_uploader.rb b/app/uploaders/gitlab_uploader.rb index 719bd6ef418..cefcd3d3f5a 100644 --- a/app/uploaders/gitlab_uploader.rb +++ b/app/uploaders/gitlab_uploader.rb @@ -63,6 +63,12 @@ class GitlabUploader < CarrierWave::Uploader::Base super || file&.filename end + def relative_path + return path if pathname.relative? + + pathname.relative_path_from(Pathname.new(root)) + end + def model_valid? !!model end @@ -115,4 +121,8 @@ class GitlabUploader < CarrierWave::Uploader::Base # the cache directory. File.join(work_dir, cache_id, version_name.to_s, for_file) end + + def pathname + @pathname ||= Pathname.new(path) + end end diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index 557b13a8bd6..400f0b3dcc6 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -9,6 +9,8 @@ class JobArtifactUploader < GitlabUploader storage_options Gitlab.config.artifacts + alias_method :upload, :model + def cached_size return model.size if model.size.present? && !model.file_changed? diff --git a/app/uploaders/legacy_artifact_uploader.rb b/app/uploaders/legacy_artifact_uploader.rb index b4d0d752016..a9afc104ed1 100644 --- a/app/uploaders/legacy_artifact_uploader.rb +++ b/app/uploaders/legacy_artifact_uploader.rb @@ -8,6 +8,8 @@ class LegacyArtifactUploader < GitlabUploader storage_options Gitlab.config.artifacts + alias_method :upload, :model + def store_dir dynamic_segment end diff --git a/app/uploaders/lfs_object_uploader.rb b/app/uploaders/lfs_object_uploader.rb index f3d32e6b39d..0a966f3d44f 100644 --- a/app/uploaders/lfs_object_uploader.rb +++ b/app/uploaders/lfs_object_uploader.rb @@ -6,6 +6,8 @@ class LfsObjectUploader < GitlabUploader storage_options Gitlab.config.lfs + alias_method :upload, :model + def filename model.oid[4..-1] end diff --git a/spec/support/shared_examples/uploaders/gitlab_uploader_shared_examples.rb b/spec/support/shared_examples/uploaders/gitlab_uploader_shared_examples.rb index 93c21a99e59..1190863d88e 100644 --- a/spec/support/shared_examples/uploaders/gitlab_uploader_shared_examples.rb +++ b/spec/support/shared_examples/uploaders/gitlab_uploader_shared_examples.rb @@ -33,6 +33,14 @@ shared_examples "builds correct paths" do |**patterns| it_behaves_like "matches the method pattern", :upload_path end + describe "#relative_path" do + it 'is relative' do + skip 'Path not set, skipping.' unless subject.path + + expect(Pathname.new(subject.relative_path)).to be_relative + end + end + describe ".absolute_path" do it_behaves_like "matches the method pattern", :absolute_path do let(:target) { subject.class } |