1
0
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:
niusmallnan
2018-01-02 17:17:43 +08:00
committed by GitHub
parent b08d29cc2c
commit 3b92e04065
2 changed files with 22 additions and 2 deletions

View File

@@ -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))