mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Support nested folders when performing a http download into a file (#1206)
This commit is contained in:
parent
190a4708a2
commit
4835fbffab
@ -1,11 +1,11 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
//Downloader ...
|
||||
@ -26,7 +26,12 @@ func (c *Client) DownloadRequest(method, url, filename string, header http.Heade
|
||||
return errors.Wrapf(err, "HTTP %v request to %v failed with error", method, url)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
parent := filepath.Dir(filename)
|
||||
if len(parent) > 0 {
|
||||
if err = os.MkdirAll(parent, 0775); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fileHandler, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to create file %v", filename)
|
||||
|
@ -30,7 +30,7 @@ func TestDownloadRequest(t *testing.T) {
|
||||
}
|
||||
// clean up tmp dir
|
||||
defer os.RemoveAll(workingDir)
|
||||
targetFile := filepath.Join(workingDir, "abc.xml")
|
||||
targetFile := filepath.Join(workingDir, "abc/123/abc.xml")
|
||||
|
||||
// function under test
|
||||
err = client.DownloadFile(server.URL, targetFile, nil, nil)
|
||||
|
Loading…
Reference in New Issue
Block a user