diff options
Diffstat (limited to 'src/helsinki.at/rhimport/fetcher.go')
-rw-r--r-- | src/helsinki.at/rhimport/fetcher.go | 17 |
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 } |