diff --git a/changelogs/unreleased/georgekoltsov-ignore-failed-to-download-project-export-uploads.yml b/changelogs/unreleased/georgekoltsov-ignore-failed-to-download-project-export-uploads.yml new file mode 100644 index 0000000000000000000000000000000000000000..9e51c3d9272d7d07d1441cd4c9bf441842df5d3f --- /dev/null +++ b/changelogs/unreleased/georgekoltsov-ignore-failed-to-download-project-export-uploads.yml @@ -0,0 +1,6 @@ +--- +title: Fix 'File name too long' error happening during Project Export when exporting + project uploads +merge_request: 46674 +author: +type: fixed diff --git a/lib/gitlab/import_export/uploads_manager.rb b/lib/gitlab/import_export/uploads_manager.rb index 26e7d2cf765fa185e9091f7428ce91b3e4329e24..428bcbe8dc574fc12e5372720b95b28d2ccf3341 100644 --- a/lib/gitlab/import_export/uploads_manager.rb +++ b/lib/gitlab/import_export/uploads_manager.rb @@ -86,6 +86,10 @@ def download_and_copy(upload) mkdir_p(File.join(uploads_export_path, secret)) download_or_copy_upload(upload, upload_path) + rescue Errno::ENAMETOOLONG => e + # Do not fail entire project export if downloaded file has filename that exceeds 255 characters. + # Ignore raised exception, skip such upload, log the error and keep going with the export instead. + Gitlab::ErrorTracking.log_exception(e, project_id: @project.id) end end end diff --git a/spec/lib/gitlab/import_export/uploads_manager_spec.rb b/spec/lib/gitlab/import_export/uploads_manager_spec.rb index 33ad0e12c370c3b039707ae0760eb43822eed1dc..8282ad9a0705e4528a6e1b239ace0d8087222371 100644 --- a/spec/lib/gitlab/import_export/uploads_manager_spec.rb +++ b/spec/lib/gitlab/import_export/uploads_manager_spec.rb @@ -23,13 +23,13 @@ end describe '#save' do + before do + project.uploads << upload + end + context 'when the project has uploads locally stored' do let(:upload) { create(:upload, :issuable_upload, :with_file, model: project) } - before do - project.uploads << upload - end - it 'does not cause errors' do manager.save @@ -74,6 +74,22 @@ end end end + + context 'when upload is in object storage' do + before do + stub_uploads_object_storage(FileUploader) + allow(manager).to receive(:download_or_copy_upload).and_raise(Errno::ENAMETOOLONG) + end + + it 'ignores problematic upload and logs exception' do + expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(Errno::ENAMETOOLONG), project_id: project.id) + + manager.save + + expect(shared.errors).to be_empty + expect(File).not_to exist(exported_file_path) + end + end end describe '#restore' do