Created
May 17, 2012 09:28
-
-
Save demelziraptor/2717730 to your computer and use it in GitHub Desktop.
Dirty hack to get gitlab archive download to use zip rather than tar.gz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def archive | |
unless can?(current_user, :download_code, @project) | |
render_404 and return | |
end | |
ref = params[:ref] || @project.root_ref | |
commit = @project.commit(ref) | |
render_404 and return unless commit | |
# Build file path | |
file_name = @project.code + "-" + commit.id.to_s + ".zip" | |
storage_path = File.join(Rails.root, "tmp", "repositories", @project.code) | |
file_path = File.join(storage_path, file_name) | |
# Create file if not exists | |
unless File.exists?(file_path) | |
FileUtils.mkdir_p storage_path | |
cmd = "git --git-dir='#{@project.path_to_repo}' archive --format=zip -o #{file_path} #{ref}" | |
render_404 and return unless system(cmd) | |
end | |
# Send file to user | |
send_file file_path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although this is like 2 years old, but there is an even quicker hack (as of GitLab 4.0.1) by editing archive_repo() in app/roles/repository.rb:
Change:
file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
To:
file_name = self.path + "-" + commit.id.to_s + ".zip"
And change:
file = self.repo.archive_to_file(ref, prefix, file_path)
To:
file = self.repo.archive_to_file(ref, prefix, file_path, "zip", "cat")