1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-06 02:23:24 +00:00

copyurl: factor code into operations and write test

This commit is contained in:
Nick Craig-Wood
2018-11-02 17:29:57 +00:00
parent fc2afcbcbd
commit 46c2f55545
3 changed files with 36 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net/http"
"path"
"sort"
"strconv"
@@ -1359,6 +1360,16 @@ func RcatSize(fdst fs.Fs, dstFileName string, in io.ReadCloser, size int64, modT
return obj, nil
}
// CopyURL copies the data from the url to (fdst, dstFileName)
func CopyURL(fdst fs.Fs, dstFileName string, url string) (dst fs.Object, err error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer fs.CheckClose(resp.Body, &err)
return RcatSize(fdst, dstFileName, resp.Body, resp.ContentLength, time.Now())
}
// moveOrCopyFile moves or copies a single file possibly to a new name
func moveOrCopyFile(fdst fs.Fs, fsrc fs.Fs, dstFileName string, srcFileName string, cp bool) (err error) {
dstFilePath := path.Join(fdst.Root(), dstFileName)