upload/koji: extract processXMLRPCResponse method
Fedora 33 ships kolo/xmlrpc with a different API. This commit extracts the affected code so we can use build flags in the future allowing us to use both API versions.
This commit is contained in:
parent
2db4938a57
commit
d32345104c
3 changed files with 33 additions and 7 deletions
|
|
@ -315,19 +315,14 @@ func (k *Koji) uploadChunk(chunk []byte, filepath, filename string, offset uint6
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := xmlrpc.NewResponse(body)
|
|
||||||
if resp.Failed() {
|
|
||||||
return resp.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
var reply struct {
|
var reply struct {
|
||||||
Size int `xmlrpc:"size"`
|
Size int `xmlrpc:"size"`
|
||||||
HexDigest string `xmlrpc:"hexdigest"`
|
HexDigest string `xmlrpc:"hexdigest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = resp.Unmarshal(&reply)
|
err = processXMLRPCResponse(body, &reply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot unmarshal the xmlrpc response: %v", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if reply.Size != len(chunk) {
|
if reply.Size != len(chunk) {
|
||||||
|
|
|
||||||
31
internal/upload/koji/xmlrpc-response-oldapi.go
Normal file
31
internal/upload/koji/xmlrpc-response-oldapi.go
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
// This files provides a wrapper around kolo/xmlrpc response handling.
|
||||||
|
//
|
||||||
|
// Commit e3ad6d89 of the xmlrpc library changed the API of response handling.
|
||||||
|
// This means that different APIs are available in Fedora 32 and 33 (it does
|
||||||
|
// not matter for RHEL as uses vendored libraries).
|
||||||
|
// This wrapper allows us to use both xmlrpc's APIs using buildflags.
|
||||||
|
//
|
||||||
|
// This file is a wrapper for xmlrpc older than e3ad6d89.
|
||||||
|
|
||||||
|
package koji
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kolo/xmlrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// processXMLRPCResponse is a wrapper around kolo/xmlrpc
|
||||||
|
func processXMLRPCResponse(body []byte, reply interface{}) error {
|
||||||
|
resp := xmlrpc.NewResponse(body)
|
||||||
|
if resp.Failed() {
|
||||||
|
return fmt.Errorf("xmlrpc server returned an error: %v", resp.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
err := resp.Unmarshal(reply)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot unmarshal the xmlrpc response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
0
internal/upload/koji/xmlrpc-response.go
Normal file
0
internal/upload/koji/xmlrpc-response.go
Normal file
Loading…
Add table
Add a link
Reference in a new issue