Merge pull request #655 from warpc/385-fix-link-for-tar-archive
[refs #385] Fix archive tar.gz link for project source code
This commit is contained in:
commit
3c70adba9a
|
@ -11,17 +11,17 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
format = params[:format]
|
format = params[:format]
|
||||||
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^[\w]+$/)
|
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
|
||||||
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
|
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
|
||||||
@commit = @project.repo.commits(@treeish, 1).first
|
@commit = @project.repo.commits(@treeish, 1).first
|
||||||
end
|
end
|
||||||
raise Grit::NoSuchPathError unless @commit
|
raise Grit::NoSuchPathError unless @commit
|
||||||
name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
|
name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
|
||||||
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
|
fullname = "#{name}.#{format == 'zip' ? 'zip' : 'tar.gz'}"
|
||||||
file = Tempfile.new fullname, 'tmp'
|
file = Tempfile.new fullname, 'tmp'
|
||||||
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
|
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@treeish} #{format == 'zip' ? '' : ' | gzip -9'} > #{file.path}")
|
||||||
file.close
|
file.close
|
||||||
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
|
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", :filename => fullname
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
%b.caret
|
%b.caret
|
||||||
%ul.dropdown-menu
|
%ul.dropdown-menu
|
||||||
- file_name = "#{@project.owner.uname}-#{@project.name}-#{@commit.id}"
|
- file_name = "#{@project.owner.uname}-#{@project.name}-#{@commit.id}"
|
||||||
%li=link_to "tar.gz", archive_path(project, file_name, 'tar')
|
%li=link_to "tar.gz", archive_path(project, file_name, 'tar.gz')
|
||||||
%li=link_to "zip", archive_path(project, file_name, 'zip')
|
%li=link_to "zip", archive_path(project, file_name, 'zip')
|
||||||
|
|
||||||
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true
|
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true
|
||||||
|
|
|
@ -222,7 +222,7 @@ Rosa::Application.routes.draw do
|
||||||
# Raw
|
# Raw
|
||||||
get '/raw/:treeish/*path' => "git/blobs#raw", :as => :raw, :format => false
|
get '/raw/:treeish/*path' => "git/blobs#raw", :as => :raw, :format => false
|
||||||
# Archive
|
# Archive
|
||||||
get '/archive/:treeish.:format' => "git/trees#archive", :as => :archive, :format => /zip|tar/
|
get '/archive/:treeish.:format' => "git/trees#archive", :as => :archive, :format => /zip|tar\.gz/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,13 +20,13 @@ describe Projects::Git::TreesController do
|
||||||
context 'for guest' do
|
context 'for guest' do
|
||||||
it 'should be able to perform archive action with anonymous acccess', :anonymous_access => true do
|
it 'should be able to perform archive action with anonymous acccess', :anonymous_access => true do
|
||||||
fill_project
|
fill_project
|
||||||
get :archive, @params.merge(:format => 'tar')
|
get :archive, @params.merge(:format => 'tar.gz')
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform archive action without anonymous acccess', :anonymous_access => false do
|
it 'should not be able to perform archive action without anonymous acccess', :anonymous_access => false do
|
||||||
fill_project
|
fill_project
|
||||||
get :archive, @params.merge(:format => 'tar')
|
get :archive, @params.merge(:format => 'tar.gz')
|
||||||
response.code.should == '401'
|
response.code.should == '401'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,14 +35,14 @@ describe Projects::Git::TreesController do
|
||||||
it 'should not be able to archive empty project' do
|
it 'should not be able to archive empty project' do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActionController::RoutingError)
|
expect { get :archive, @params.merge(:format => 'tar.gz') }.to raise_error(ActionController::RoutingError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to injection code with format' do
|
it 'should not be able to injection code with format' do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
fill_project
|
fill_project
|
||||||
expect { get :archive, @params.merge(:format => "tar master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError)
|
expect { get :archive, @params.merge(:format => "tar.gz master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to injection code with treeish' do
|
it 'should not be able to injection code with treeish' do
|
||||||
|
@ -56,7 +56,7 @@ describe Projects::Git::TreesController do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
fill_project
|
fill_project
|
||||||
get :archive, @params.merge(:format => 'tar')
|
get :archive, @params.merge(:format => 'tar.gz')
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue