diff --git a/app/services/groups/import_export/export_service.rb b/app/services/groups/import_export/export_service.rb index abac0ffc5d94bf876b8ac4a370c531601aead5d8..b45deda6855abde556e266547f4dad6925ce30f9 100644 --- a/app/services/groups/import_export/export_service.rb +++ b/app/services/groups/import_export/export_service.rb @@ -22,7 +22,7 @@ def execute save! ensure - remove_base_tmp_dir + remove_archive_tmp_dir end private @@ -81,8 +81,8 @@ def file_saver Gitlab::ImportExport::Saver.new(exportable: @group, shared: @shared) end - def remove_base_tmp_dir - FileUtils.rm_rf(shared.base_path) if shared&.base_path + def remove_archive_tmp_dir + FileUtils.rm_rf(shared.archive_path) if shared&.archive_path end def notify_error! diff --git a/changelogs/unreleased/georgekoltsov-update-project-export-temp-folder-cleanup.yml b/changelogs/unreleased/georgekoltsov-update-project-export-temp-folder-cleanup.yml new file mode 100644 index 0000000000000000000000000000000000000000..71cab10b58db314a02fcaee34088a2963b679ff4 --- /dev/null +++ b/changelogs/unreleased/georgekoltsov-update-project-export-temp-folder-cleanup.yml @@ -0,0 +1,5 @@ +--- +title: Update Project/Group Exporter temp folder cleanup +merge_request: 51969 +author: +type: fixed diff --git a/lib/gitlab/import_export/saver.rb b/lib/gitlab/import_export/saver.rb index 045ba2495bf6b111fad5e21923ea762b2ac8e724..bb2bbda4bd6dbb05cef248f9466b276d1fc45392 100644 --- a/lib/gitlab/import_export/saver.rb +++ b/lib/gitlab/import_export/saver.rb @@ -31,7 +31,7 @@ def save @shared.error(e) false ensure - remove_base_tmp_dir + remove_archive_tmp_dir end private @@ -40,8 +40,8 @@ def compress_and_save tar_czf(archive: archive_file, dir: @shared.export_path) end - def remove_base_tmp_dir - FileUtils.rm_rf(@shared.base_path) + def remove_archive_tmp_dir + FileUtils.rm_rf(@shared.archive_path) end def archive_file diff --git a/spec/lib/gitlab/import_export/saver_spec.rb b/spec/lib/gitlab/import_export/saver_spec.rb index 865c7e57b5a9a68e65e17150df763687127edab9..877474dd862cfead0cf0552051f80abf88397050 100644 --- a/spec/lib/gitlab/import_export/saver_spec.rb +++ b/spec/lib/gitlab/import_export/saver_spec.rb @@ -6,7 +6,8 @@ RSpec.describe Gitlab::ImportExport::Saver do let!(:project) { create(:project, :public, name: 'project') } let(:base_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } - let(:export_path) { "#{base_path}/project_tree_saver_spec/export" } + let(:archive_path) { "#{base_path}/archive" } + let(:export_path) { "#{archive_path}/export" } let(:shared) { project.import_export_shared } subject { described_class.new(exportable: project, shared: shared) } @@ -35,10 +36,13 @@ .to match(%r[\/uploads\/-\/system\/import_export_upload\/export_file.*]) end - it 'removes tmp files' do + it 'removes archive path and keeps base path untouched' do + allow(shared).to receive(:archive_path).and_return(archive_path) + subject.save - expect(FileUtils).to have_received(:rm_rf).with(base_path) - expect(Dir.exist?(base_path)).to eq(false) + expect(FileUtils).not_to have_received(:rm_rf).with(base_path) + expect(FileUtils).to have_received(:rm_rf).with(archive_path) + expect(Dir.exist?(archive_path)).to eq(false) end end diff --git a/spec/services/groups/import_export/export_service_spec.rb b/spec/services/groups/import_export/export_service_spec.rb index 690bcb945566651f73bef78009fbbdcf6bc1b1ac..6b78822de04fd55b9e93252e596c16995b2b0baf 100644 --- a/spec/services/groups/import_export/export_service_spec.rb +++ b/spec/services/groups/import_export/export_service_spec.rb @@ -134,7 +134,7 @@ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) expect(group.import_export_upload).to be_nil - expect(Dir.exist?(shared.base_path)).to eq(false) + expect(Dir.exist?(shared.archive_path)).to eq(false) end it 'notifies the user about failed group export' do @@ -159,7 +159,7 @@ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) expect(group.import_export_upload).to be_nil - expect(Dir.exist?(shared.base_path)).to eq(false) + expect(Dir.exist?(shared.archive_path)).to eq(false) end it 'notifies logger' do