BigW Consortium Gitlab

Commit 10d0f438 by Bob Van Landuyt

Download LFS-files from object storage for exports

Downloading the stream directly to the archive. In order to avoid conflicts with the cache.
parent 79cb4d99
---
title: Support LFS objects when importing/exporting GitLab project archives
merge_request: 18115
author:
type: added
......@@ -28,7 +28,16 @@ module Gitlab
if lfs_object.local_store?
copy_file_for_lfs_object(lfs_object)
else
raise NotImplementedError.new "Exporting files from object storage is not yet supported"
download_file_for_lfs_object(lfs_object)
end
end
def download_file_for_lfs_object(lfs_object)
destination = destination_path_for_object(lfs_object)
mkdir_p(File.dirname(destination))
File.open(destination, 'w') do |file|
IO.copy_stream(URI.parse(lfs_object.file.url).open, file)
end
end
......
......@@ -17,7 +17,7 @@ describe Gitlab::ImportExport::LfsSaver do
end
describe '#save' do
context 'when the project has LFS objects' do
context 'when the project has LFS objects locally stored' do
let(:lfs_object) { create(:lfs_object, :with_file) }
before do
......@@ -36,5 +36,27 @@ describe Gitlab::ImportExport::LfsSaver do
expect(File).to exist("#{shared.export_path}/lfs-objects/#{lfs_object.oid}")
end
end
context 'when the LFS objects are stored in object storage' do
let(:lfs_object) { create(:lfs_object, :object_storage) }
before do
allow(LfsObjectUploader).to receive(:object_store_enabled?).and_return(true)
allow(lfs_object.file).to receive(:url).and_return('http://my-object-storage.local')
project.lfs_objects << lfs_object
end
it 'downloads the file to include in an archive' do
fake_uri = double
exported_file_path = "#{shared.export_path}/lfs-objects/#{lfs_object.oid}"
expect(fake_uri).to receive(:open).and_return(StringIO.new('LFS file content'))
expect(URI).to receive(:parse).with('http://my-object-storage.local').and_return(fake_uri)
saver.save
expect(File.read(exported_file_path)).to eq('LFS file content')
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment