Commit 1d63464c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix repository archive

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent d8b769ec
...@@ -14,11 +14,7 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -14,11 +14,7 @@ class Projects::RepositoriesController < Projects::ApplicationController
render_404 and return render_404 and return
end end
storage_path = Gitlab.config.gitlab.repository_downloads_path file_path = ArchiveRepositoryService.new.execute(@project, params[:ref], params[:format])
@repository.clean_old_archives
file_path = @repository.archive_repo(params[:ref], storage_path, params[:format].downcase)
if file_path if file_path
# Send file to user # Send file to user
......
class ArchiveRepositoryService
def execute(project, ref, format)
storage_path = Gitlab.config.gitlab.repository_downloads_path
unless File.directory?(storage_path)
FileUtils.mkdir_p(storage_path)
end
format ||= 'tar.gz'
repository = project.repository
repository.clean_old_archives
repository.archive_repo(ref, storage_path, format.downcase)
end
end
...@@ -115,21 +115,13 @@ module API ...@@ -115,21 +115,13 @@ module API
# GET /projects/:id/repository/archive # GET /projects/:id/repository/archive
get ":id/repository/archive", requirements: { format: Gitlab::Regex.archive_formats_regex } do get ":id/repository/archive", requirements: { format: Gitlab::Regex.archive_formats_regex } do
authorize! :download_code, user_project authorize! :download_code, user_project
repo = user_project.repository file_path = ArchiveRepositoryService.new.execute(user_project, params[:sha], params[:format])
ref = params[:sha]
format = params[:format]
storage_path = Gitlab.config.gitlab.repository_downloads_path
file_path = repo.archive_repo(ref, storage_path, format)
if file_path && File.exists?(file_path) if file_path && File.exists?(file_path)
data = File.open(file_path, 'rb').read data = File.open(file_path, 'rb').read
header["Content-Disposition"] = "attachment; filename=\"#{File.basename(file_path)}\"" header["Content-Disposition"] = "attachment; filename=\"#{File.basename(file_path)}\""
content_type MIME::Types.type_for(file_path).first.content_type content_type MIME::Types.type_for(file_path).first.content_type
env['api.format'] = :binary env['api.format'] = :binary
present data present data
else else
not_found! not_found!
......
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