summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2018-06-06 13:00:52 -0700
committerMichael Kozono <mkozono@gmail.com>2018-06-12 13:58:01 -0700
commitb3ecfb68c8f0acd849e576e9bd7b2fb613d9a231 (patch)
tree560baffefa888d3c30d4fce58817b4ec3c2624fd
parentd4ad92cd06fd0367f93bcb908cf50261d013fe43 (diff)
downloadgitlab-ce-b3ecfb68c8f0acd849e576e9bd7b2fb613d9a231.tar.gz
Support verifying remote LFS objects
-rw-r--r--lib/gitlab/verify/batch_verifier.rb7
-rw-r--r--lib/gitlab/verify/lfs_objects.rb6
-rw-r--r--lib/gitlab/verify/uploads.rb4
-rw-r--r--spec/lib/gitlab/verify/lfs_objects_spec.rb16
4 files changed, 25 insertions, 8 deletions
diff --git a/lib/gitlab/verify/batch_verifier.rb b/lib/gitlab/verify/batch_verifier.rb
index fd01602c256..d5327890d07 100644
--- a/lib/gitlab/verify/batch_verifier.rb
+++ b/lib/gitlab/verify/batch_verifier.rb
@@ -55,7 +55,7 @@ module Gitlab
# We don't calculate checksum for remote objects, so just check existence
def verify_remote(object)
- raise 'Remote object does not exist' unless object.build_uploader.exists?
+ raise 'Remote object does not exist' unless remote_object_exists?(object)
end
# This should return an ActiveRecord::Relation suitable for calling #in_batches on
@@ -77,6 +77,11 @@ module Gitlab
def actual_checksum(_object)
raise NotImplementedError.new
end
+
+ # Should return true if the remote object exists
+ def remote_object_exists?(object)
+ raise NotImplementedError.new
+ end
end
end
end
diff --git a/lib/gitlab/verify/lfs_objects.rb b/lib/gitlab/verify/lfs_objects.rb
index bfda339f129..835f3a1486d 100644
--- a/lib/gitlab/verify/lfs_objects.rb
+++ b/lib/gitlab/verify/lfs_objects.rb
@@ -12,7 +12,7 @@ module Gitlab
private
def relation
- LfsObject.with_files_stored_locally
+ LfsObject.all
end
def local?(lfs_object)
@@ -26,6 +26,10 @@ module Gitlab
def actual_checksum(lfs_object)
LfsObject.calculate_oid(lfs_object.file.path)
end
+
+ def remote_object_exists?(lfs_object)
+ lfs_object.file && lfs_object.file.exists?
+ end
end
end
end
diff --git a/lib/gitlab/verify/uploads.rb b/lib/gitlab/verify/uploads.rb
index 70916aeed4f..031d62f0fd3 100644
--- a/lib/gitlab/verify/uploads.rb
+++ b/lib/gitlab/verify/uploads.rb
@@ -26,6 +26,10 @@ module Gitlab
def actual_checksum(upload)
Upload.hexdigest(upload.absolute_path)
end
+
+ def remote_object_exists?(upload)
+ upload.build_uploader.exists?
+ end
end
end
end
diff --git a/spec/lib/gitlab/verify/lfs_objects_spec.rb b/spec/lib/gitlab/verify/lfs_objects_spec.rb
index 0f890e2c7ce..65d8b38c955 100644
--- a/spec/lib/gitlab/verify/lfs_objects_spec.rb
+++ b/spec/lib/gitlab/verify/lfs_objects_spec.rb
@@ -35,16 +35,20 @@ describe Gitlab::Verify::LfsObjects do
context 'with remote files' do
before do
stub_lfs_object_storage
+ lfs_object.update!(file_store: ObjectStorage::Store::REMOTE)
end
- it 'skips LFS objects in object storage' do
- local_failure = create(:lfs_object)
- create(:lfs_object, :object_storage)
+ it 'passes LFS objects in object storage that exist' do
+ expect_any_instance_of(LfsObjectUploader).to receive(:exists?).and_return(true)
- failures = {}
- described_class.new(batch_size: 10).run_batches { |_, failed| failures.merge!(failed) }
+ expect(failures).to eq({})
+ end
+
+ it 'fails LFS objects in object storage that do not exist' do
+ expect_any_instance_of(LfsObjectUploader).to receive(:exists?).and_return(false)
- expect(failures.keys).to contain_exactly(local_failure)
+ expect(failures.keys).to contain_exactly(lfs_object)
+ expect(failure.to_s).to include('Remote object does not exist')
end
end
end