mirror of
https://github.com/rclone/rclone.git
synced 2025-06-01 09:02:22 +08:00
copyurl: add no-clobber flag - fixes #3950
This commit is contained in:
@ -1718,8 +1718,15 @@ func copyURLFn(ctx context.Context, dstFileName string, url string, dstFileNameF
|
||||
}
|
||||
|
||||
// CopyURL copies the data from the url to (fdst, dstFileName)
|
||||
func CopyURL(ctx context.Context, fdst fs.Fs, dstFileName string, url string, dstFileNameFromURL bool) (dst fs.Object, err error) {
|
||||
func CopyURL(ctx context.Context, fdst fs.Fs, dstFileName string, url string, dstFileNameFromURL bool, noClobber bool) (dst fs.Object, err error) {
|
||||
|
||||
err = copyURLFn(ctx, dstFileName, url, dstFileNameFromURL, func(ctx context.Context, dstFileName string, in io.ReadCloser, size int64, modTime time.Time) (err error) {
|
||||
if noClobber {
|
||||
_, err = fdst.NewObject(ctx, dstFileName)
|
||||
if err == nil {
|
||||
return errors.New("CopyURL failed: file already exist")
|
||||
}
|
||||
}
|
||||
dst, err = RcatSize(ctx, fdst, dstFileName, in, size, modTime)
|
||||
return err
|
||||
})
|
||||
|
Reference in New Issue
Block a user