From f8fdfced8f50006f0726edaae858ffc4931bfcba Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 19 May 2015 19:23:33 -0700 Subject: [PATCH] If target exists skip for both sync and cp --- cmd-cp.go | 3 --- cp-url.go | 10 ++++++++-- pkg/client/s3/s3.go | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd-cp.go b/cmd-cp.go index 8f513846..af95015d 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -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) diff --git a/cp-url.go b/cp-url.go index 3a1af67a..5721d491 100644 --- a/cp-url.go +++ b/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}} diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 96644d68..ac3d36a1 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -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,