summaryrefslogtreecommitdiff
path: root/app/uploaders
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-05-04 23:02:51 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2017-06-01 14:39:48 +0200
commite61f38d79eb85a7c601bd146d5b8e48a8b4418e5 (patch)
tree08abc6cb3f4ef57de157167fca8189a162298ae1 /app/uploaders
parentc72abcefe79dd906cbbf0088b442a8979e9fc746 (diff)
downloadgitlab-ce-e61f38d79eb85a7c601bd146d5b8e48a8b4418e5.tar.gz
Fix data inconsistency issue for old artifacts by moving them to a currently used path
Diffstat (limited to 'app/uploaders')
-rw-r--r--app/uploaders/artifact_uploader.rb28
-rw-r--r--app/uploaders/gitlab_uploader.rb12
-rw-r--r--app/uploaders/records_uploads.rb4
3 files changed, 25 insertions, 19 deletions
diff --git a/app/uploaders/artifact_uploader.rb b/app/uploaders/artifact_uploader.rb
index 3e36ec91205..668b6b8e048 100644
--- a/app/uploaders/artifact_uploader.rb
+++ b/app/uploaders/artifact_uploader.rb
@@ -1,33 +1,31 @@
class ArtifactUploader < GitlabUploader
storage :file
- attr_accessor :build, :field
+ attr_reader :job, :field
- def self.artifacts_path
+ def self.local_artifacts_store
Gitlab.config.artifacts.path
end
- def self.artifacts_upload_path
- File.join(self.artifacts_path, 'tmp/uploads/')
+ def initialize(job, field)
+ @job, @field = job, field
end
- def self.artifacts_cache_path
- File.join(self.artifacts_path, 'tmp/cache/')
+ def store_dir
+ default_local_path
end
- def initialize(build, field)
- @build, @field = build, field
+ def cache_dir
+ File.join(self.class.local_artifacts_store, 'tmp/cache')
end
- def store_dir
- File.join(self.class.artifacts_path, @build.artifacts_path)
- end
+ private
- def cache_dir
- File.join(self.class.artifacts_cache_path, @build.artifacts_path)
+ def default_local_path
+ File.join(self.class.local_artifacts_store, default_path)
end
- def filename
- file.try(:filename)
+ def default_path
+ File.join(job.created_at.utc.strftime('%Y_%m'), job.project_id.to_s, job.id.to_s)
end
end
diff --git a/app/uploaders/gitlab_uploader.rb b/app/uploaders/gitlab_uploader.rb
index e0a6c9b4067..c1d9007dc71 100644
--- a/app/uploaders/gitlab_uploader.rb
+++ b/app/uploaders/gitlab_uploader.rb
@@ -9,8 +9,16 @@ class GitlabUploader < CarrierWave::Uploader::Base
delegate :base_dir, to: :class
- def file_storage?
- self.class.storage == CarrierWave::Storage::File
+ def local_file?
+ local_storage? && file&.is_a?(CarrierWave::SanitizedFile)
+ end
+
+ def local_storage?
+ storage.is_a?(CarrierWave::Storage::File)
+ end
+
+ def local_cache_storage?
+ cache_storage.is_a?(CarrierWave::Storage::File)
end
# Reduce disk IO
diff --git a/app/uploaders/records_uploads.rb b/app/uploaders/records_uploads.rb
index 4c127f29250..be3a2caa60c 100644
--- a/app/uploaders/records_uploads.rb
+++ b/app/uploaders/records_uploads.rb
@@ -16,7 +16,7 @@ module RecordsUploads
#
# Called `after :store`
def record_upload(_tempfile)
- return unless file_storage?
+ return unless local_file?
return unless file.exists?
Upload.record(self)
@@ -26,7 +26,7 @@ module RecordsUploads
#
# Called `before :remove`
def destroy_upload(*args)
- return unless file_storage?
+ return unless local_file?
return unless file
Upload.remove_path(relative_path)