Skip to content

Commit

Permalink
[webui] basic fixes for dealing with remote urls when adding source f…
Browse files Browse the repository at this point in the history
…iles

- git support is back
- filename handling fixed
  • Loading branch information
adrianschroeter committed Jul 22, 2014
1 parent c19b7b7 commit 38115dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/package_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def save_file
end
elsif file_url.present?
# we have a remote file uri
return unless add_file_url(file_url)
return unless add_file_url(file_url, filename)
else
return unless add_file_filename(filename)
end
Expand Down Expand Up @@ -650,12 +650,12 @@ def add_file_filename(filename)
true
end

def add_file_url(file_url)
def add_file_url(file_url, filename=nil)
@services = Service.find(project: @project, package: @package.name)
unless @services
@services = Service.new(project: @project, package: @package.name)
end
@services.addDownloadURL(file_url)
@services.addDownloadURL(file_url, filename) # detects automatically git://, src.rpm formats
unless @services.save
flash[:error] = "Failed to add file from URL '#{file_url}'. -> #{e.class}"
redirect_back_or_to :action => 'add_file', :project => params[:project], :package => params[:package]
Expand Down
14 changes: 13 additions & 1 deletion src/api/app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ def self.make_stub(opt)
"<services/>"
end

def addDownloadURL(url)
def addDownloadURL(url, filename=nil)
begin
uri = URI.parse(url)
rescue
return false
end

# default for download_url and download_src_package
p = []
p << {:name => "host", :value => uri.host}
p << {:name => "protocol", :value => uri.scheme}
Expand All @@ -23,8 +24,19 @@ def addDownloadURL(url)
if uri.path =~ /.src.rpm$/ or uri.path =~ /.spm$/
# download and extract source package
addService("download_src_package", -1, p)
elsif uri.scheme == "git"
p = []
p << {:name => "scm", :value => "git"}
p << {:name => "url", :value => url}
addService("tar_scm", -1, p)
p = []
p << {:name => "compression", :value => "xz"}
p << {:name => "file", :value => "*.tar"}
addService("recompress", -1, p)
addService("set_version")
else
# just download
p << {:name => "filename", :value => filename} unless filename.blank?
addService("download_url", -1, p)
end
return true
Expand Down
1 change: 1 addition & 0 deletions src/api/app/views/webui/package/add_file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<h3>Add File to <%= @package.name %> (Project <%= @project.name %>)</h3>

<p>The filename is taken from the uploaded file if none is provided. Alternatively, if only a filename is provided, a new empty file is created (i.e. touched).</p>
<p>You may also specify remote URLs to src.rpm files which will get extracted. URLs to git repositories willbe stored in a tar ball.</p>

<%= form_tag({:action => :save_file, :project => @project, :package => @package}, {:multipart => true}) do %>
<p>
Expand Down

0 comments on commit 38115dc

Please sign in to comment.