Skip to content

Commit

Permalink
[api] detect and handle local links on maintenance_release correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Jan 11, 2012
1 parent 5db72cc commit f9e702b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
58 changes: 35 additions & 23 deletions src/api/app/helpers/maintenance_helper.rb
Expand Up @@ -112,24 +112,36 @@ def release_package(sourcePackage, targetProjectName, targetPackageName, revisio
updateinfoId = mi.getUpdateinfoId( id_template )
end

# copy sources
# backend copy of current sources as full copy
# that means the xsrcmd5 is different, but we keep the incident project anyway.
cp_params = {
:cmd => "copy",
:user => @http_user.login,
:oproject => sourcePackage.db_project.name,
:opackage => sourcePackage.name,
:comment => "Release from #{sourcePackage.db_project.name} / #{sourcePackage.name}",
:expand => "1",
:withvrev => "1",
:noservice => "1",
}
cp_params[:comment] += ", setting updateinfo to #{updateinfoId}" if updateinfoId
cp_params[:requestid] = request.id if request
cp_path = "/source/#{CGI.escape(targetProject.name)}/#{CGI.escape(targetPackageName)}"
cp_path << build_query_from_hash(cp_params, [:cmd, :user, :oproject, :opackage, :comment, :requestid, :expand, :withvrev, :noservice])
Suse::Backend.post cp_path, nil
# detect local links
link = nil
begin
link = Suse::Backend.get "/source/#{URI.escape(sourcePackage.db_project.name)}/#{URI.escape(sourcePackage.name)}/_link"
rescue Suse::Backend::HTTPError
end
if link and ret = ActiveXML::XMLNode.new(link.body) and (ret.project.nil? or ret.project == sourcePackage.db_project.name)
ret.delete_attribute('project') # its a local link, project name not needed
ret.set_attribute('package', ret.package.gsub(/\..*/,'') + targetPackageName.gsub(/.*\./, '.')) # adapt link target with suffix
answer = Suse::Backend.put "/source/#{targetProject.name}/#{targetPackageName}/_link?user=#{CGI.escape(@http_user.login)}", ret.dump_xml
else
# copy sources
# backend copy of current sources as full copy
# that means the xsrcmd5 is different, but we keep the incident project anyway.
cp_params = {
:cmd => "copy",
:user => @http_user.login,
:oproject => sourcePackage.db_project.name,
:opackage => sourcePackage.name,
:comment => "Release from #{sourcePackage.db_project.name} / #{sourcePackage.name}",
:expand => "1",
:withvrev => "1",
:noservice => "1",
}
cp_params[:comment] += ", setting updateinfo to #{updateinfoId}" if updateinfoId
cp_params[:requestid] = request.id if request
cp_path = "/source/#{CGI.escape(targetProject.name)}/#{CGI.escape(targetPackageName)}"
cp_path << build_query_from_hash(cp_params, [:cmd, :user, :oproject, :opackage, :comment, :requestid, :expand, :withvrev, :noservice])
Suse::Backend.post cp_path, nil
end

# copy binaries
sourcePackage.db_project.repositories.each do |sourceRepo|
Expand All @@ -146,7 +158,7 @@ def release_package(sourcePackage, targetProjectName, targetPackageName, revisio
:resign => "1",
}
cp_params[:setupdateinfoid] = updateinfoId if updateinfoId
cp_path = "/build/#{CGI.escape(releasetarget.target_repository.db_project.name)}/#{CGI.escape(releasetarget.target_repository.name)}/#{CGI.escape(arch.name)}/#{CGI.escape(targetPackageName)}"
cp_path = "/build/#{CGI.escape(releasetarget.target_repository.db_project.name)}/#{URI.escape(releasetarget.target_repository.name)}/#{URI.escape(arch.name)}/#{URI.escape(targetPackageName)}"
cp_path << build_query_from_hash(cp_params, [:cmd, :oproject, :opackage, :orepository, :setupdateinfoid, :resign])
Suse::Backend.post cp_path, nil
end
Expand All @@ -162,7 +174,7 @@ def release_package(sourcePackage, targetProjectName, targetPackageName, revisio

# create or update main package linking to incident package
basePackageName = targetPackageName.gsub(/\..*/, '')
answer = Suse::Backend.get "/source/#{CGI.escape(targetProject.name)}/#{CGI.escape(targetPackageName)}"
answer = Suse::Backend.get "/source/#{URI.escape(targetProject.name)}/#{URI.escape(targetPackageName)}"
xml = REXML::Document.new(answer.body.to_s)
unless xml.elements["/directory/entry/@name='_patchinfo'"]
# only if package does not contain a _patchinfo file
Expand All @@ -177,16 +189,16 @@ def release_package(sourcePackage, targetProjectName, targetPackageName, revisio
:comment => "Set link to #{targetPackageName} via maintenance_release request",
}
upload_params[:comment] += ", for updateinfo ID #{updateinfoId}" if updateinfoId
upload_path = "/source/#{CGI.escape(targetProject.name)}/#{CGI.escape(basePackageName)}/_link"
upload_path = "/source/#{URI.escape(targetProject.name)}/#{URI.escape(basePackageName)}/_link"
upload_path << build_query_from_hash(upload_params, [:user, :rev])
link = "<link package='#{CGI.escape(targetPackageName)}' cicount='copy' />\n"
link = "<link package='#{targetPackageName}' cicount='copy' />\n"
md5 = Digest::MD5.hexdigest(link)
answer = Suse::Backend.put upload_path, link
# commit
upload_params[:cmd] = 'commitfilelist'
upload_params[:noservice] = '1'
upload_params[:requestid] = request.id if request
upload_path = "/source/#{CGI.escape(targetProject.name)}/#{CGI.escape(basePackageName)}"
upload_path = "/source/#{URI.escape(targetProject.name)}/#{URI.escape(basePackageName)}"
upload_path << build_query_from_hash(upload_params, [:user, :comment, :cmd, :noservice, :requestid])
answer = Suse::Backend.post upload_path, "<directory> <entry name=\"_link\" md5=\"#{md5}\" /> </directory>"
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/script/start_test_backend
Expand Up @@ -189,7 +189,7 @@ Suse::Backend.post( '/source/BaseDistro2.0/pack2?cmd=commitfilelist&vrev=2.3&ver
Suse::Backend.put( '/source/BaseDistro2.0/pack2/myfile', "DummyContent of BaseDistro2.0/pack2")
Suse::Backend.put( '/source/BaseDistro2.0/pack2/package.spec',File.open("#{RAILS_ROOT}/test/fixtures/backend/binary/package.spec").read())
Suse::Backend.put( '/source/BaseDistro2.0/pack2_linked/_meta', DbPackage.find_by_id('10100').to_axml)
Suse::Backend.put( '/source/BaseDistro2.0/pack2_linked/_link', "<link package=\"pack2\" />")
Suse::Backend.put( '/source/BaseDistro2.0/pack2_linked/_link', "<link package=\"pack2\" cicount='copy' />")
Suse::Backend.put( '/source/BaseDistro2.0:LinkedUpdateProject/_meta', DbProject.find_by_name('BaseDistro2.0:LinkedUpdateProject').to_axml)
Suse::Backend.put( '/source/BaseDistro3/_meta', DbProject.find_by_name('BaseDistro3').to_axml)
Suse::Backend.put( '/source/BaseDistro3/_config', "Type: spec" )
Expand Down
3 changes: 3 additions & 0 deletions src/api/test/functional/maintenance_test.rb
Expand Up @@ -642,6 +642,9 @@ def test_create_maintenance_project_and_release_packages
assert_tag( :tag => "directory", :attributes => { :vrev => "2.9" } )
get "/source/BaseDistro2.0:LinkedUpdateProject/pack2.#{incidentID}/_link"
assert_response 404
get "/source/BaseDistro2.0:LinkedUpdateProject/pack2_linked.#{incidentID}/_link"
assert_response :success
assert_tag :tag => "link", :attributes => { :project => nil, :package => "pack2.#{incidentID}", :cicount => "copy" }
get "/source/BaseDistro2.0:LinkedUpdateProject/patchinfo"
assert_response 404
get "/source/BaseDistro2.0:LinkedUpdateProject/patchinfo.#{incidentID}"
Expand Down

0 comments on commit f9e702b

Please sign in to comment.