mirror of
https://github.com/rancher/os.git
synced 2025-08-31 22:32:14 +00:00
Support URL when using ros install -c (#2202)
This commit is contained in:
14
util/util.go
14
util/util.go
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@@ -45,6 +46,19 @@ func FileCopy(src, dest string) error {
|
||||
return WriteFileAtomic(dest, data, 0666)
|
||||
}
|
||||
|
||||
func HTTPDownloadToFile(url, dest string) error {
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return WriteFileAtomic(dest, body, 0666)
|
||||
}
|
||||
|
||||
func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error {
|
||||
dir, file := path.Split(filename)
|
||||
tempFile, err := ioutil.TempFile(dir, fmt.Sprintf(".%s", file))
|
||||
|
Reference in New Issue
Block a user