Commit 27442862 authored by James Lopez's avatar James Lopez

refactor code based on feedback

parent a2aa5058
...@@ -191,8 +191,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -191,8 +191,8 @@ class ProjectsController < Projects::ApplicationController
end end
def download_export def download_export
if @project.export_project_object_exists? if @project.export_project_exists?
send_upload(@project.import_export_upload.export_file) send_upload(@project.export_file)
else else
redirect_to( redirect_to(
edit_project_path(@project, anchor: 'js-export-project'), edit_project_path(@project, anchor: 'js-export-project'),
......
...@@ -1738,7 +1738,7 @@ class Project < ActiveRecord::Base ...@@ -1738,7 +1738,7 @@ class Project < ActiveRecord::Base
:started :started
elsif after_export_in_progress? elsif after_export_in_progress?
:after_export_action :after_export_action
elsif export_project_object_exists? elsif export_project_exists?
:finished :finished
else else
:none :none
...@@ -1754,14 +1754,18 @@ class Project < ActiveRecord::Base ...@@ -1754,14 +1754,18 @@ class Project < ActiveRecord::Base
end end
def remove_exports def remove_exports
return unless export_project_object_exists? return unless export_project_exists?
import_export_upload.remove_export_file! import_export_upload.remove_export_file!
import_export_upload.save import_export_upload.save
end end
def export_project_object_exists? def export_project_exists?
import_export_upload&.export_file&.file export_file&.file
end
def export_file
import_export_upload&.export_file
end end
def full_path_slug def full_path_slug
......
...@@ -21,8 +21,8 @@ module API ...@@ -21,8 +21,8 @@ module API
detail 'This feature was introduced in GitLab 10.6.' detail 'This feature was introduced in GitLab 10.6.'
end end
get ':id/export/download' do get ':id/export/download' do
if user_project.export_project_object_exists? if user_project.export_project_exists?
present_carrierwave_file!(user_project.import_export_upload.export_file) present_carrierwave_file!(user_ project.export_file)
else else
render_api_error!('404 Not found or has expired', 404) render_api_error!('404 Not found or has expired', 404)
end end
......
...@@ -84,7 +84,7 @@ module Gitlab ...@@ -84,7 +84,7 @@ module Gitlab
end end
def object_storage? def object_storage?
project.export_project_object_exists? project.export_project_exists?
end end
end end
end end
......
...@@ -44,7 +44,7 @@ module Gitlab ...@@ -44,7 +44,7 @@ module Gitlab
end end
def export_file def export_file
project.import_export_upload.export_file.open project.export_file.open
end end
def send_file_options def send_file_options
...@@ -59,7 +59,7 @@ module Gitlab ...@@ -59,7 +59,7 @@ module Gitlab
end end
def export_size def export_size
project.import_export_upload.export_file.file.size project.export_file.file.size
end end
end end
end end
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
Rails.logger.info("Saved project export #{archive_file}") Rails.logger.info("Saved project export #{archive_file}")
save_on_object_storage save_upload
else else
@shared.error(Gitlab::ImportExport::Error.new(error_message)) @shared.error(Gitlab::ImportExport::Error.new(error_message))
false false
...@@ -49,7 +49,7 @@ module Gitlab ...@@ -49,7 +49,7 @@ module Gitlab
@archive_file ||= File.join(@shared.archive_path, Gitlab::ImportExport.export_filename(project: @project)) @archive_file ||= File.join(@shared.archive_path, Gitlab::ImportExport.export_filename(project: @project))
end end
def save_on_object_storage def save_upload
upload = ImportExportUpload.find_or_initialize_by(project: @project) upload = ImportExportUpload.find_or_initialize_by(project: @project)
File.open(archive_file) { |file| upload.export_file = file } File.open(archive_file) { |file| upload.export_file = file }
......
...@@ -54,7 +54,7 @@ namespace :gitlab do ...@@ -54,7 +54,7 @@ namespace :gitlab do
end end
Projects::ImportExport::ExportService.new(project, admin).execute Projects::ImportExport::ExportService.new(project, admin).execute
download_or_copy_upload(project.import_export_upload.export_file, template.archive_path) download_or_copy_upload( project.export_file, template.archive_path)
Projects::DestroyService.new(admin, project).execute Projects::DestroyService.new(admin, project).execute
puts "Exported #{template.name}".green puts "Exported #{template.name}".green
end end
......
...@@ -12,7 +12,7 @@ describe Gitlab::ImportExport::AfterExportStrategies::BaseAfterExportStrategy do ...@@ -12,7 +12,7 @@ describe Gitlab::ImportExport::AfterExportStrategies::BaseAfterExportStrategy do
end end
it 'returns if project exported file is not found' do it 'returns if project exported file is not found' do
allow(project).to receive(:export_project_object_exists?).and_return(false) allow(project).to receive(:export_project_exists?).and_return(false)
expect(service).not_to receive(:strategy_execute) expect(service).not_to receive(:strategy_execute)
......
...@@ -2859,7 +2859,7 @@ describe Project do ...@@ -2859,7 +2859,7 @@ describe Project do
it 'removes the export' do it 'removes the export' do
project.remove_exports project.remove_exports
expect(project.export_project_object_exists?).to be_falsey expect(project.export_project_exists?).to be_falsey
end end
end end
......
...@@ -189,7 +189,7 @@ describe API::ProjectExport do ...@@ -189,7 +189,7 @@ describe API::ProjectExport do
end end
it 'has removed the export' do it 'has removed the export' do
expect(project_after_export.export_project_object_exists?).to be_falsey expect(project_after_export.export_project_exists?).to be_falsey
end end
it_behaves_like '404 response' do it_behaves_like '404 response' do
......
...@@ -52,7 +52,7 @@ module ExportFileHelper ...@@ -52,7 +52,7 @@ module ExportFileHelper
# Expands the compressed file for an exported project into +tmpdir+ # Expands the compressed file for an exported project into +tmpdir+
def in_directory_with_expanded_export(project) def in_directory_with_expanded_export(project)
Dir.mktmpdir do |tmpdir| Dir.mktmpdir do |tmpdir|
export_file = project.import_export_upload.export_file.path export_file = project.export_file.path
_output, exit_status = Gitlab::Popen.popen(%W{tar -zxf #{export_file} -C #{tmpdir}}) _output, exit_status = Gitlab::Popen.popen(%W{tar -zxf #{export_file} -C #{tmpdir}})
yield(exit_status, tmpdir) yield(exit_status, tmpdir)
......
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