update uploads saver

This commit is contained in:
James Lopez 2018-07-10 16:33:40 +02:00
parent 2c1e66d4d2
commit a27d4d9e52
No known key found for this signature in database
GPG Key ID: 756BF8E9D7C0CF39
4 changed files with 25 additions and 15 deletions

View File

@ -13,7 +13,16 @@ module Gitlab
def copy
copy_files(@from, uploads_export_path) if File.directory?(@from)
if File.file?(@from) && @relative_export_path == 'avatar'
copy_files(@from, File.join(uploads_export_path, @project.avatar.filename))
end
copy_from_object_storage
true
rescue => e
@shared.error(e)
false
end
private
@ -49,9 +58,10 @@ module Gitlab
end
def download_and_copy(upload)
mkdir_p(File.join(uploads_export_path, upload.secret))
secret = upload.try(:secret) || ''
upload_path = File.join(uploads_export_path, secret, upload.filename)
upload_path = File.join(uploads_export_path, upload.secret, upload.filename)
mkdir_p(File.join(uploads_export_path, secret))
File.open(upload_path, 'w') do |file|
IO.copy_stream(URI.parse(upload.file.url).open, file)

View File

@ -9,21 +9,14 @@ module Gitlab
end
def save
return true unless File.directory?(uploads_path)
copy_files(uploads_path, uploads_export_path)
Gitlab::ImportExport::UploadsManager.new(
project: @project,
shared: @shared,
).copy
rescue => e
@shared.error(e)
false
end
def uploads_path
FileUploader.absolute_base_dir(@project)
end
def uploads_export_path
File.join(@shared.export_path, 'uploads')
end
end
end
end

View File

@ -28,6 +28,13 @@ FactoryBot.define do
secret SecureRandom.hex
end
trait :with_file do
after(:create) do |upload|
FileUtils.mkdir_p(File.dirname(upload.absolute_path))
FileUtils.touch(upload.absolute_path)
end
end
trait :object_storage do
store ObjectStorage::Store::REMOTE
end

View File

@ -30,7 +30,7 @@ describe Gitlab::ImportExport::UploadsSaver do
it 'copies the uploads to the export path' do
saver.save
uploads = Dir.glob(File.join(saver.uploads_export_path, '**/*')).map { |file| File.basename(file) }
uploads = Dir.glob(File.join(shared.export_path, 'uploads/**/*')).map { |file| File.basename(file) }
expect(uploads).to include('banana_sample.gif')
end
@ -52,7 +52,7 @@ describe Gitlab::ImportExport::UploadsSaver do
it 'copies the uploads to the export path' do
saver.save
uploads = Dir.glob(File.join(saver.uploads_export_path, '**/*')).map { |file| File.basename(file) }
uploads = Dir.glob(File.join(shared.export_path, 'uploads/**/*')).map { |file| File.basename(file) }
expect(uploads).to include('banana_sample.gif')
end