summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/fetcher.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-11 02:57:49 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-11 02:57:49 (GMT)
commit2367ba3dab31b1d6de0e6432e5b6640797b13808 (patch)
tree962202c109a388ab743421f04443727c877f3d02 /src/helsinki.at/rhimport/fetcher.go
parent2426db0f7625668434fbcc1722cc13a1bdf67e1b (diff)
curl based importer
Diffstat (limited to 'src/helsinki.at/rhimport/fetcher.go')
-rw-r--r--src/helsinki.at/rhimport/fetcher.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go
index ccbca43..05074b1 100644
--- a/src/helsinki.at/rhimport/fetcher.go
+++ b/src/helsinki.at/rhimport/fetcher.go
@@ -35,14 +35,14 @@ import (
"strings"
)
-type CurlCBData struct {
+type FetcherCurlCBData struct {
basepath string
filename string
remotename string
*os.File
}
-func (self *CurlCBData) Cleanup() {
+func (self *FetcherCurlCBData) Cleanup() {
if self.File != nil {
self.File.Close()
}
@@ -50,7 +50,7 @@ func (self *CurlCBData) Cleanup() {
func curlHeaderCallback(ptr []byte, userdata interface{}) bool {
hdr := fmt.Sprintf("%s", ptr)
- data := userdata.(*CurlCBData)
+ data := userdata.(*FetcherCurlCBData)
if strings.HasPrefix(hdr, "Content-Disposition:") {
if mediatype, params, err := mime.ParseMediaType(strings.TrimPrefix(hdr, "Content-Disposition:")); err == nil {
@@ -63,7 +63,7 @@ func curlHeaderCallback(ptr []byte, userdata interface{}) bool {
}
func curlWriteCallback(ptr []byte, userdata interface{}) bool {
- data := userdata.(*CurlCBData)
+ data := userdata.(*FetcherCurlCBData)
if data.File == nil {
if data.filename == "" {
data.filename = data.basepath + "/" + data.remotename
@@ -86,14 +86,13 @@ func FetchFileCurl(ctx *ImportContext, uri *url.URL) (err error) {
rhl.Printf("curl-based fetcher called for '%s'", ctx.SourceUri)
easy := curl.EasyInit()
- defer easy.Cleanup()
-
if easy != nil {
+ defer easy.Cleanup()
easy.Setopt(curl.OPT_FOLLOWLOCATION, true)
easy.Setopt(curl.OPT_URL, ctx.SourceUri)
- cbdata := &CurlCBData{remotename: path.Base(uri.Path)}
+ cbdata := &FetcherCurlCBData{remotename: path.Base(uri.Path)}
defer cbdata.Cleanup()
if cbdata.basepath, err = ioutil.TempDir(ctx.Config.TempDir, "rhimportd-"); err != nil {
return
@@ -118,12 +117,14 @@ func FetchFileCurl(ctx *ImportContext, uri *url.URL) (err error) {
if err = easy.Perform(); err != nil {
return
}
- fmt.Printf("\n")
ctx.SourceFile = cbdata.filename
ctx.DeleteSourceFile = true
ctx.DeleteSourceDir = true
+ } else {
+ err = fmt.Errorf("Error initializing libcurl")
}
+
return
}