@@ -1896,8 +1896,18 @@ func (d *noStopDownloader) Close() error {
1896
1896
// copyURLFunc is called from CopyURLFn
1897
1897
type copyURLFunc func (ctx context.Context , dstFileName string , in io.ReadCloser , size int64 , modTime time.Time ) (err error )
1898
1898
1899
+ // copyURLFuncEx is called from CopyURLFn
1900
+ type copyURLFuncEx func (ctx context.Context , dstFileName string , in io.ReadCloser , size int64 , modTime time.Time , resp * http.Response ) (err error )
1901
+
1899
1902
// copyURLFn copies the data from the url to the function supplied
1900
1903
func copyURLFn (ctx context.Context , dstFileName string , url string , autoFilename , dstFileNameFromHeader bool , fn copyURLFunc ) (err error ) {
1904
+ return copyURLFnEx (ctx , dstFileName , url , autoFilename , dstFileNameFromHeader , func (ctx context.Context , dstFileName string , in io.ReadCloser , size int64 , modTime time.Time , resp * http.Response ) (err error ) {
1905
+ return fn (ctx , dstFileName , in , size , modTime )
1906
+ })
1907
+ }
1908
+
1909
+ // copyURLFn copies the data from the url to the function supplied
1910
+ func copyURLFnEx (ctx context.Context , dstFileName string , url string , autoFilename , dstFileNameFromHeader bool , fn copyURLFuncEx ) (err error ) {
1901
1911
client := fshttp .NewClient (ctx )
1902
1912
resp , err := client .Get (url )
1903
1913
if err != nil {
@@ -1921,7 +1931,7 @@ func copyURLFn(ctx context.Context, dstFileName string, url string, autoFilename
1921
1931
return fmt .Errorf ("CopyURL failed: filename not found in the Content-Disposition header" )
1922
1932
}
1923
1933
fs .Debugf (headerFilename , "filename found in Content-Disposition header." )
1924
- return fn (ctx , headerFilename , resp .Body , resp .ContentLength , modTime )
1934
+ return fn (ctx , headerFilename , resp .Body , resp .ContentLength , modTime , resp )
1925
1935
}
1926
1936
1927
1937
dstFileName = path .Base (resp .Request .URL .Path )
@@ -1930,7 +1940,7 @@ func copyURLFn(ctx context.Context, dstFileName string, url string, autoFilename
1930
1940
}
1931
1941
fs .Debugf (dstFileName , "File name found in url" )
1932
1942
}
1933
- return fn (ctx , dstFileName , d , resp .ContentLength , modTime )
1943
+ return fn (ctx , dstFileName , d , resp .ContentLength , modTime , resp )
1934
1944
}
1935
1945
1936
1946
// CopyURL copies the data from the url to (fdst, dstFileName)
@@ -1949,6 +1959,22 @@ func CopyURL(ctx context.Context, fdst fs.Fs, dstFileName string, url string, au
1949
1959
return dst , err
1950
1960
}
1951
1961
1962
+ // CopyURL copies the data from the url to (fdst, dstFileName)
1963
+ func CopyURLEx (ctx context.Context , fdst fs.Fs , dstFileName string , url string , autoFilename , dstFileNameFromHeader bool , noClobber bool ) (dst fs.Object , rawResp * http.Response , err error ) {
1964
+ err = copyURLFnEx (ctx , dstFileName , url , autoFilename , dstFileNameFromHeader , func (ctx context.Context , dstFileName string , in io.ReadCloser , size int64 , modTime time.Time , resp * http.Response ) (err error ) {
1965
+ if noClobber {
1966
+ _ , err = fdst .NewObject (ctx , dstFileName )
1967
+ if err == nil {
1968
+ return errors .New ("CopyURL failed: file already exist" )
1969
+ }
1970
+ }
1971
+ dst , err = RcatSize (ctx , fdst , dstFileName , in , size , modTime , nil )
1972
+ rawResp = resp
1973
+ return err
1974
+ })
1975
+ return dst , rawResp , err
1976
+ }
1977
+
1952
1978
// CopyURLToWriter copies the data from the url to the io.Writer supplied
1953
1979
func CopyURLToWriter (ctx context.Context , url string , out io.Writer ) (err error ) {
1954
1980
return copyURLFn (ctx , "" , url , false , false , func (ctx context.Context , dstFileName string , in io.ReadCloser , size int64 , modTime time.Time ) (err error ) {
0 commit comments