summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-04-03 18:54:42 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-04-05 10:21:51 +0200
commit10d0f438d823418a4a4f4e4f52e8f35ed10f2a05 (patch)
tree326e78434084e6ad547dbe4a727ba4e1c571944c
parent79cb4d99c0e47bfd988788ff38871e668367dfbf (diff)
downloadgitlab-ce-10d0f438d823418a4a4f4e4f52e8f35ed10f2a05.tar.gz
Download LFS-files from object storage for exports
Downloading the stream directly to the archive. In order to avoid conflicts with the cache.
-rw-r--r--changelogs/unreleased/bvl-export-import-lfs.yml5
-rw-r--r--lib/gitlab/import_export/lfs_saver.rb11
-rw-r--r--spec/lib/gitlab/import_export/lfs_saver_spec.rb24
3 files changed, 38 insertions, 2 deletions
diff --git a/changelogs/unreleased/bvl-export-import-lfs.yml b/changelogs/unreleased/bvl-export-import-lfs.yml
new file mode 100644
index 00000000000..dd1f499c3a3
--- /dev/null
+++ b/changelogs/unreleased/bvl-export-import-lfs.yml
@@ -0,0 +1,5 @@
+---
+title: Support LFS objects when importing/exporting GitLab project archives
+merge_request: 18115
+author:
+type: added
diff --git a/lib/gitlab/import_export/lfs_saver.rb b/lib/gitlab/import_export/lfs_saver.rb
index d796440902b..2e3b9ea200d 100644
--- a/lib/gitlab/import_export/lfs_saver.rb
+++ b/lib/gitlab/import_export/lfs_saver.rb
@@ -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
diff --git a/spec/lib/gitlab/import_export/lfs_saver_spec.rb b/spec/lib/gitlab/import_export/lfs_saver_spec.rb
index e62afac1c48..9b0e21deb2e 100644
--- a/spec/lib/gitlab/import_export/lfs_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/lfs_saver_spec.rb
@@ -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