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
|
// doCopy - Copy a singe file from source to destination
|
||||||
func doCopy(sourceURL string, sourceConfig *hostConfig, targetURL string, targetConfig *hostConfig, bar *barSend) error {
|
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)
|
reader, length, err := getSource(sourceURL, sourceConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
|
|||||||
10
cp-url.go
10
cp-url.go
@@ -19,6 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -192,8 +193,13 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs {
|
|||||||
if !targetContent.Type.IsRegular() { // Target is not a regular file
|
if !targetContent.Type.IsRegular() { // Target is not a regular file
|
||||||
return &cpURLs{Error: iodine.New(errInvalidTarget{path: targetURL}, nil)}
|
return &cpURLs{Error: iodine.New(errInvalidTarget{path: targetURL}, nil)}
|
||||||
}
|
}
|
||||||
// Target exists but, we can may overwrite. Let the copy function decide.
|
// if target is same Name, Size and Type as source return error and skip
|
||||||
} // Target does not exist. We can create a new target file | object here.
|
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
|
// All OK.. We can proceed. Type A
|
||||||
return &cpURLs{SourceContent: sourceContent, TargetContent: &client.Content{Name: targetURL}}
|
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.Name = c.hostURL.String()
|
||||||
objectMetadata.Time = metadata.LastModified
|
objectMetadata.Time = metadata.LastModified
|
||||||
objectMetadata.Size = metadata.Size
|
objectMetadata.Size = metadata.Size
|
||||||
objectMetadata.Type = 0
|
objectMetadata.Type = os.FileMode(0664)
|
||||||
return objectMetadata, nil
|
return objectMetadata, nil
|
||||||
}
|
}
|
||||||
err := c.api.StatBucket(bucket)
|
err := c.api.StatBucket(bucket)
|
||||||
@@ -232,7 +232,7 @@ func (c *s3Client) listInGoRoutine(contentCh chan client.ContentOnChannel) {
|
|||||||
content.Name = metadata.Key
|
content.Name = metadata.Key
|
||||||
content.Time = metadata.LastModified
|
content.Time = metadata.LastModified
|
||||||
content.Size = metadata.Size
|
content.Size = metadata.Size
|
||||||
content.Type = 0
|
content.Type = os.FileMode(0664)
|
||||||
contentCh <- client.ContentOnChannel{
|
contentCh <- client.ContentOnChannel{
|
||||||
Content: content,
|
Content: content,
|
||||||
Err: nil,
|
Err: nil,
|
||||||
@@ -255,7 +255,7 @@ func (c *s3Client) listInGoRoutine(contentCh chan client.ContentOnChannel) {
|
|||||||
default:
|
default:
|
||||||
content.Size = object.Data.Size
|
content.Size = object.Data.Size
|
||||||
content.Time = object.Data.LastModified
|
content.Time = object.Data.LastModified
|
||||||
content.Type = 0
|
content.Type = os.FileMode(0664)
|
||||||
}
|
}
|
||||||
contentCh <- client.ContentOnChannel{
|
contentCh <- client.ContentOnChannel{
|
||||||
Content: content,
|
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.Name = strings.TrimSuffix(c.hostURL.String(), "/") + "/" + object.Data.Key
|
||||||
content.Size = object.Data.Size
|
content.Size = object.Data.Size
|
||||||
content.Time = object.Data.LastModified
|
content.Time = object.Data.LastModified
|
||||||
content.Type = 0
|
content.Type = os.FileMode(0664)
|
||||||
contentCh <- client.ContentOnChannel{
|
contentCh <- client.ContentOnChannel{
|
||||||
Content: content,
|
Content: content,
|
||||||
Err: nil,
|
Err: nil,
|
||||||
|
|||||||
Reference in New Issue
Block a user