diff options
author | Chris Peressini <cperessini@gitlab.com> | 2018-06-19 17:01:50 +0200 |
---|---|---|
committer | Chris Peressini <cperessini@gitlab.com> | 2018-06-19 17:01:50 +0200 |
commit | dbc7c5baafdb31076923d25910127cecb756aa2d (patch) | |
tree | 75bdb8cb8ebe63a606248cc1026b05757e720dcd /lib | |
parent | c79908c138e37f99dee8405e7fad8316be371418 (diff) | |
download | gitlab-ce-dbc7c5baafdb31076923d25910127cecb756aa2d.tar.gz |
Revert "Merge branch 'mk/rake-task-verify-remote-files' into 'master'"11-0-stable-prepare-rc14-revert-19501
This reverts commit c79908c138e37f99dee8405e7fad8316be371418.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/verify/batch_verifier.rb | 59 | ||||
-rw-r--r-- | lib/gitlab/verify/job_artifacts.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/verify/lfs_objects.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/verify/rake_task.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/verify/uploads.rb | 12 |
5 files changed, 16 insertions, 79 deletions
diff --git a/lib/gitlab/verify/batch_verifier.rb b/lib/gitlab/verify/batch_verifier.rb index 167ba1b3149..1ef369a4b67 100644 --- a/lib/gitlab/verify/batch_verifier.rb +++ b/lib/gitlab/verify/batch_verifier.rb @@ -7,15 +7,13 @@ module Gitlab @batch_size = batch_size @start = start @finish = finish - - fix_google_api_logger end # Yields a Range of IDs and a Hash of failed verifications (object => error) def run_batches(&blk) - all_relation.in_batches(of: batch_size, start: start, finish: finish) do |batch| # rubocop: disable Cop/InBatches - range = batch.first.id..batch.last.id - failures = run_batch_for(batch) + relation.in_batches(of: batch_size, start: start, finish: finish) do |relation| # rubocop: disable Cop/InBatches + range = relation.first.id..relation.last.id + failures = run_batch(relation) yield(range, failures) end @@ -31,56 +29,24 @@ module Gitlab private - def run_batch_for(batch) - batch.map { |upload| verify(upload) }.compact.to_h + def run_batch(relation) + relation.map { |upload| verify(upload) }.compact.to_h end def verify(object) - local?(object) ? verify_local(object) : verify_remote(object) - rescue => err - failure(object, err.inspect) - end - - def verify_local(object) expected = expected_checksum(object) actual = actual_checksum(object) - return failure(object, 'Checksum missing') unless expected.present? - return failure(object, 'Checksum mismatch') unless expected == actual - - success - end + raise 'Checksum missing' unless expected.present? + raise 'Checksum mismatch' unless expected == actual - # We don't calculate checksum for remote objects, so just check existence - def verify_remote(object) - return failure(object, 'Remote object does not exist') unless remote_object_exists?(object) - - success - end - - def success nil - end - - def failure(object, message) - [object, message] - end - - # It's already set to Logger::INFO, but acts as if it is set to - # Logger::DEBUG, and this fixes it... - def fix_google_api_logger - if Object.const_defined?('Google::Apis') - Google::Apis.logger.level = Logger::INFO - end + rescue => err + [object, err] end # This should return an ActiveRecord::Relation suitable for calling #in_batches on - def all_relation - raise NotImplementedError.new - end - - # Should return true if the object is stored locally - def local?(_object) + def relation raise NotImplementedError.new end @@ -93,11 +59,6 @@ module Gitlab def actual_checksum(_object) raise NotImplementedError.new end - - # Be sure to perform a hard check of the remote object (don't just check DB value) - def remote_object_exists?(object) - raise NotImplementedError.new - end end end end diff --git a/lib/gitlab/verify/job_artifacts.rb b/lib/gitlab/verify/job_artifacts.rb index dbadfbde9e3..03500a61074 100644 --- a/lib/gitlab/verify/job_artifacts.rb +++ b/lib/gitlab/verify/job_artifacts.rb @@ -11,14 +11,10 @@ module Gitlab private - def all_relation + def relation ::Ci::JobArtifact.all end - def local?(artifact) - artifact.local_store? - end - def expected_checksum(artifact) artifact.file_sha256 end @@ -26,10 +22,6 @@ module Gitlab def actual_checksum(artifact) Digest::SHA256.file(artifact.file.path).hexdigest end - - def remote_object_exists?(artifact) - artifact.file.file.exists? - end end end end diff --git a/lib/gitlab/verify/lfs_objects.rb b/lib/gitlab/verify/lfs_objects.rb index d3f58a73ac7..970e2a7b718 100644 --- a/lib/gitlab/verify/lfs_objects.rb +++ b/lib/gitlab/verify/lfs_objects.rb @@ -11,12 +11,8 @@ module Gitlab private - def all_relation - LfsObject.all - end - - def local?(lfs_object) - lfs_object.local_store? + def relation + LfsObject.with_files_stored_locally end def expected_checksum(lfs_object) @@ -26,10 +22,6 @@ module Gitlab def actual_checksum(lfs_object) LfsObject.calculate_oid(lfs_object.file.path) end - - def remote_object_exists?(lfs_object) - lfs_object.file.file.exists? - end end end end diff --git a/lib/gitlab/verify/rake_task.rb b/lib/gitlab/verify/rake_task.rb index e190eaddc79..dd138e6b92b 100644 --- a/lib/gitlab/verify/rake_task.rb +++ b/lib/gitlab/verify/rake_task.rb @@ -45,7 +45,7 @@ module Gitlab return unless verbose? failures.each do |object, error| - say " - #{verifier.describe(object)}: #{error}".color(:red) + say " - #{verifier.describe(object)}: #{error.inspect}".color(:red) end end end diff --git a/lib/gitlab/verify/uploads.rb b/lib/gitlab/verify/uploads.rb index 01f09ab8df7..0ffa71a6d72 100644 --- a/lib/gitlab/verify/uploads.rb +++ b/lib/gitlab/verify/uploads.rb @@ -11,12 +11,8 @@ module Gitlab private - def all_relation - Upload.all - end - - def local?(upload) - upload.local? + def relation + Upload.with_files_stored_locally end def expected_checksum(upload) @@ -26,10 +22,6 @@ module Gitlab def actual_checksum(upload) Upload.hexdigest(upload.absolute_path) end - - def remote_object_exists?(upload) - upload.build_uploader.file.exists? - end end end end |