update uploads saver
This commit is contained in:
parent
2c1e66d4d2
commit
a27d4d9e52
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue