Commit c75187df authored by Travis Miller's avatar Travis Miller

Add project export API implementation

parent a4308c53
......@@ -1560,7 +1560,7 @@ class Project < ActiveRecord::Base
def export_path
return nil unless namespace.present? || hashed_storage?(:repository)
File.join(Gitlab::ImportExport.storage_path, disk_path)
Gitlab::ImportExport::Shared.new(self).archive_path
end
def export_project_path
......@@ -1578,8 +1578,7 @@ class Project < ActiveRecord::Base
end
def export_in_progress?
shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(disk_path, 'work'))
File.directory?(shared.export_path)
Gitlab::ImportExport::Shared.new(self).active_export_count > 0
end
def remove_exports
......
......@@ -2,7 +2,7 @@ module Projects
module ImportExport
class ExportService < BaseService
def execute(_options = {})
@shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.disk_path, 'work'))
@shared = Gitlab::ImportExport::Shared.new(project)
save_all
end
......
......@@ -138,6 +138,7 @@ module API
mount ::API::PagesDomains
mount ::API::Pipelines
mount ::API::PipelineSchedules
mount ::API::ProjectExport
mount ::API::ProjectImport
mount ::API::ProjectHooks
mount ::API::Projects
......
module API
class ProjectExport < Grape::API
before do
not_found! unless Gitlab::CurrentSettings.current_application_settings.project_export_enabled?
authorize_admin_project
end
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get export status' do
success Entities::ProjectExportStatus
end
get ':id/export' do
present user_project, with: Entities::ProjectExportStatus
end
desc 'Download export'
get ':id/export/download' do
path = user_project.export_project_path
render_api_error!('404 Not found or has expired', 404) unless path
present_file!(path, File.basename(path), 'application/gzip')
end
desc 'Start export'
post ':id/export' do
user_project.add_export_job(current_user: current_user)
accepted!
end
end
end
end
......@@ -9,7 +9,7 @@ module Gitlab
@archive_file = project.import_source
@current_user = project.creator
@project = project
@shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace)
@shared = Gitlab::ImportExport::Shared.new(project)
end
def execute
......
module Gitlab
module ImportExport
class Shared
attr_reader :errors, :opts
attr_reader :errors, :project
def initialize(opts)
@opts = opts
def initialize(project)
@project = project
@errors = []
end
def active_export_count
Dir[File.join(archive_path, '*')].count { |name| File.directory?(name) }
end
def export_path
@export_path ||= Gitlab::ImportExport.export_path(relative_path: relative_path)
end
......@@ -31,11 +35,15 @@ module Gitlab
private
def relative_path
File.join(opts[:relative_path], SecureRandom.hex)
File.join(relative_archive_path, SecureRandom.hex)
end
def relative_archive_path
File.join(opts[:relative_path], '..')
if @project.is_a?(Project)
@project.disk_path
else
@project[:relative_path]
end
end
def error_out(message, caller)
......
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