Skip to content

Instantly share code, notes, and snippets.

@demelziraptor
Created May 17, 2012 09:28
Show Gist options
  • Save demelziraptor/2717730 to your computer and use it in GitHub Desktop.
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
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
@demelziraptor
Copy link
Author

Replace archive function in app/controllers/repositories_controller.rb with this one.

@Xiphe
Copy link

Xiphe commented Jul 23, 2012

Hi,
I tryed this out but sadly it does not work with my current version (2.7.0).
Got the following error: Cannot spawn application '/opt/gitlabhq': The spawn server has exited unexpectedly.
I installed gitlab by following this tutorial: http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/

Which version of gitlab are you using? Or do you know any better workarounds for zip downloads in gitlab?

Greetings, Xiphe.

@demelziraptor
Copy link
Author

Ah, thanks for letting me know. I'm on 2.6.2 right now. I haven't seen any better workarounds yet, although I'm sure there should be some.
Will test on 2.7 when I upgrade in a few weeks.

@Xiphe
Copy link

Xiphe commented Jul 23, 2012

Cool, i'd love to know when you got that to work :)
I've been looking for other solutions the last 3 days and have not found anything but yours.
Sadly i have absolutely no experience with ruby so it'm not able to debug it or make any suggestions :(

@aspoon
Copy link

aspoon commented Jan 24, 2014

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment