Commit a27d4d9e authored by James Lopez's avatar James Lopez

update uploads saver

parent 2c1e66d4
...@@ -13,7 +13,16 @@ module Gitlab ...@@ -13,7 +13,16 @@ module Gitlab
def copy def copy
copy_files(@from, uploads_export_path) if File.directory?(@from) 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 copy_from_object_storage
true
rescue => e
@shared.error(e)
false
end end
private private
...@@ -49,9 +58,10 @@ module Gitlab ...@@ -49,9 +58,10 @@ module Gitlab
end end
def download_and_copy(upload) 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| File.open(upload_path, 'w') do |file|
IO.copy_stream(URI.parse(upload.file.url).open, file) IO.copy_stream(URI.parse(upload.file.url).open, file)
......
...@@ -9,21 +9,14 @@ module Gitlab ...@@ -9,21 +9,14 @@ module Gitlab
end end
def save def save
return true unless File.directory?(uploads_path) Gitlab::ImportExport::UploadsManager.new(
project: @project,
copy_files(uploads_path, uploads_export_path) shared: @shared,
).copy
rescue => e rescue => e
@shared.error(e) @shared.error(e)
false false
end end
def uploads_path
FileUploader.absolute_base_dir(@project)
end
def uploads_export_path
File.join(@shared.export_path, 'uploads')
end
end end
end end
end end
...@@ -28,6 +28,13 @@ FactoryBot.define do ...@@ -28,6 +28,13 @@ FactoryBot.define do
secret SecureRandom.hex secret SecureRandom.hex
end 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 trait :object_storage do
store ObjectStorage::Store::REMOTE store ObjectStorage::Store::REMOTE
end end
......
...@@ -30,7 +30,7 @@ describe Gitlab::ImportExport::UploadsSaver do ...@@ -30,7 +30,7 @@ describe Gitlab::ImportExport::UploadsSaver do
it 'copies the uploads to the export path' do it 'copies the uploads to the export path' do
saver.save 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') expect(uploads).to include('banana_sample.gif')
end end
...@@ -52,7 +52,7 @@ describe Gitlab::ImportExport::UploadsSaver do ...@@ -52,7 +52,7 @@ describe Gitlab::ImportExport::UploadsSaver do
it 'copies the uploads to the export path' do it 'copies the uploads to the export path' do
saver.save 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') expect(uploads).to include('banana_sample.gif')
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