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
render_404 and return
end
storage_path = Gitlab.config.gitlab.repository_downloads_path
@repository.clean_old_archives
file_path = @repository.archive_repo(params[:ref], storage_path, params[:format].downcase)
file_path = ArchiveRepositoryService.new.execute(@project, params[:ref], params[:format])
if file_path
# 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
# GET /projects/:id/repository/archive
get ":id/repository/archive", requirements: { format: Gitlab::Regex.archive_formats_regex } do
authorize! :download_code, user_project
repo = user_project.repository
ref = params[:sha]
format = params[:format]
storage_path = Gitlab.config.gitlab.repository_downloads_path
file_path = ArchiveRepositoryService.new.execute(user_project, params[:sha], params[:format])
file_path = repo.archive_repo(ref, storage_path, format)
if file_path && File.exists?(file_path)
data = File.open(file_path, 'rb').read
header["Content-Disposition"] = "attachment; filename=\"#{File.basename(file_path)}\""
content_type MIME::Types.type_for(file_path).first.content_type
env['api.format'] = :binary
present data
else
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