Skip to content
Snippets Groups Projects
Verified Commit 1d63464c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Fix repository archive

parent d8b769ec
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
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
Loading
Loading
@@ -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!
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment