提交 b5f5b6dc 编写于 作者: S Shinya Maeda

Add checksum to ci_job_artifacts

上级 2e87923d
......@@ -6,6 +6,7 @@ module Ci
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
before_save :set_size, if: :file_changed?
before_save :set_checksum, if: :file_changed?
mount_uploader :file, JobArtifactUploader
......@@ -25,6 +26,10 @@ module Ci
self.size = file.size
end
def set_checksum
self.checksum = file.checksum
end
def expire_in
expire_at - Time.now if expire_at
end
......
......@@ -9,6 +9,12 @@ class JobArtifactUploader < GitlabUploader
model.size
end
def checksum
return calc_checksum if model.checksum.nil?
model.checksum
end
def store_dir
dynamic_segment
end
......@@ -21,6 +27,10 @@ class JobArtifactUploader < GitlabUploader
private
def calc_checksum
Digest::SHA256.file(file.path).hexdigest
end
def dynamic_segment
creation_date = model.created_at.utc.strftime('%Y_%m_%d')
......
class AddChecksumToCiJobArtifacts < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :ci_job_artifacts, :checksum, :string, limit: 64
end
end
......@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20180304204842) do
t.datetime_with_timezone "updated_at", null: false
t.datetime_with_timezone "expire_at"
t.string "file"
t.string "checksum", limit: 64
end
add_index "ci_job_artifacts", ["expire_at", "job_id"], name: "index_ci_job_artifacts_on_expire_at_and_job_id", using: :btree
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册