mirror of
https://github.com/minio/mc.git
synced 2025-11-12 01:02:26 +03:00
If target exists skip for both sync and cp
This commit is contained in:
@@ -27,9 +27,6 @@ import (
|
||||
|
||||
// doCopy - Copy a singe file from source to destination
|
||||
func doCopy(sourceURL string, sourceConfig *hostConfig, targetURL string, targetConfig *hostConfig, bar *barSend) error {
|
||||
if sourceURL == targetURL {
|
||||
return iodine.New(errSameURLs{source: sourceURL, target: targetURL}, nil)
|
||||
}
|
||||
reader, length, err := getSource(sourceURL, sourceConfig)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
|
||||
10
cp-url.go
10
cp-url.go
@@ -19,6 +19,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -192,8 +193,13 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs {
|
||||
if !targetContent.Type.IsRegular() { // Target is not a regular file
|
||||
return &cpURLs{Error: iodine.New(errInvalidTarget{path: targetURL}, nil)}
|
||||
}
|
||||
// Target exists but, we can may overwrite. Let the copy function decide.
|
||||
} // Target does not exist. We can create a new target file | object here.
|
||||
// if target is same Name, Size and Type as source return error and skip
|
||||
u, _ := url.Parse(targetContent.Name)
|
||||
if (targetContent.Size == sourceContent.Size) && (filepath.Base(u.Path) == sourceContent.Name) {
|
||||
// Target exists, don't overwrite. Let the copy function decide return error here
|
||||
return &cpURLs{Error: iodine.New(errSameURLs{source: sourceURL, target: targetURL}, nil)}
|
||||
}
|
||||
}
|
||||
|
||||
// All OK.. We can proceed. Type A
|
||||
return &cpURLs{SourceContent: sourceContent, TargetContent: &client.Content{Name: targetURL}}
|
||||
|
||||
@@ -155,7 +155,7 @@ func (c *s3Client) Stat() (*client.Content, error) {
|
||||
objectMetadata.Name = c.hostURL.String()
|
||||
objectMetadata.Time = metadata.LastModified
|
||||
objectMetadata.Size = metadata.Size
|
||||
objectMetadata.Type = 0
|
||||
objectMetadata.Type = os.FileMode(0664)
|
||||
return objectMetadata, nil
|
||||
}
|
||||
err := c.api.StatBucket(bucket)
|
||||
@@ -232,7 +232,7 @@ func (c *s3Client) listInGoRoutine(contentCh chan client.ContentOnChannel) {
|
||||
content.Name = metadata.Key
|
||||
content.Time = metadata.LastModified
|
||||
content.Size = metadata.Size
|
||||
content.Type = 0
|
||||
content.Type = os.FileMode(0664)
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
@@ -255,7 +255,7 @@ func (c *s3Client) listInGoRoutine(contentCh chan client.ContentOnChannel) {
|
||||
default:
|
||||
content.Size = object.Data.Size
|
||||
content.Time = object.Data.LastModified
|
||||
content.Type = 0
|
||||
content.Type = os.FileMode(0664)
|
||||
}
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
@@ -281,7 +281,7 @@ func (c *s3Client) listRecursiveInGoRoutine(contentCh chan client.ContentOnChann
|
||||
content.Name = strings.TrimSuffix(c.hostURL.String(), "/") + "/" + object.Data.Key
|
||||
content.Size = object.Data.Size
|
||||
content.Time = object.Data.LastModified
|
||||
content.Type = 0
|
||||
content.Type = os.FileMode(0664)
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
|
||||
Reference in New Issue
Block a user