Remove unncessary stat() checks for TypeC in cp and cast - fixes #803

This commit is contained in:
Harshavardhana
2015-07-22 20:53:21 -07:00
parent 964fdf7565
commit 71ed556dd0
4 changed files with 1 additions and 99 deletions
+1 -46
View File
@@ -126,19 +126,8 @@ func checkCastSyntax(ctx *cli.Context) {
if srcContent.Type.IsRegular() { // Ellipses is supported only for directories.
console.Fatalf("Source ‘%s’ is not a directory. %s\n", stripRecursiveURL(srcURL), iodine.New(err, nil))
}
// All targets should be a valid folder.
for _, tgtURL := range tgtURLs {
_, tgtContent, err := url2Stat(tgtURL)
// Target exist?
if err != nil {
console.Fatalf("Unable to stat target directory ‘%s’. %s\n", tgtURL, iodine.New(err, nil))
}
if !tgtContent.Type.IsDir() {
console.Fatalf("Target ‘%s’ is not a directory.\n", tgtURL)
}
}
default:
console.Fatalln("Invalid arguments. Unanle to determine how to cast.")
console.Fatalln("Invalid arguments. Unable to determine how to cast. Please report this issue at https://github.com/minio/mc/issues")
}
}
@@ -178,23 +167,6 @@ func prepareSingleCastURLsTypeA(sourceURL string, targetURL string) castURLs {
return castURLs{Error: NewIodine(iodine.New(errInvalidSource{URL: sourceURL}, nil))}
}
/* // Too expensive. Lets ignore it for now.
targetClient, err := target2Client(targetURL)
if err != nil {
return castURLs{Error: NewIodine(iodine.New(err, nil))}
}
// Target exists?
targetContent, err := targetClient.Stat()
if err == nil { // Target exists.
if !targetContent.Type.IsRegular() { // Target is not a regular file
return castURLs{Error: NewIodine(iodine.New(errInvalidTarget{URL: targetURL}, nil))}
}
var targetContents []*client.Content
targetContents = append(targetContents, targetContent)
return castURLs{SourceContent: sourceContent, TargetContents: targetContents}
}
*/
// All OK.. We can proceed. Type A
sourceContent.Name = sourceURL
return castURLs{SourceContent: sourceContent, TargetContents: []*client.Content{{Name: targetURL}}}
@@ -296,23 +268,6 @@ func prepareCastURLsTypeC(sourceURL string, targetURLs []string) <-chan castURLs
return
}
// Type C requires all targets to be a dir and it should exist.
for _, targetURL := range targetURLs {
_, targetContent, err := url2Stat(targetURL)
// Target exist?
if err != nil {
// Target does not exist.
castURLsCh <- castURLs{Error: NewIodine(iodine.New(errTargetNotFound{URL: targetURL}, nil))}
return
}
if !targetContent.Type.IsDir() {
// Target exists, but is not a directory.
castURLsCh <- castURLs{Error: NewIodine(iodine.New(errTargetIsNotDir{URL: targetURL}, nil))}
return
}
}
for sourceContent := range sourceClient.List(true) {
if sourceContent.Err != nil {
// Listing failed.
-12
View File
@@ -159,18 +159,6 @@ func doPrepareCastURLs(session *sessionV2, trapCh <-chan bool) {
console.Errorln(sURLs.Error)
break
}
/* We are going to copy any way now. Let it fail at the time of putObject
if !globalForceFlag {
if len(sURLs.TargetContents) > 0 {
if sURLs.TargetContents[0].Size != 0 || !sURLs.TargetContents[0].Time.IsZero() {
console.Fatalf("Destination already exists, cannot overwrite ‘%s’ with ‘%s’. "+
"Use ‘--force’ flag to override.\n", sURLs.TargetContents[0].Name, sURLs.SourceContent.Name)
break
}
}
}
*/
jsonData, err := json.Marshal(sURLs)
if err != nil {
session.Close()
-9
View File
@@ -147,15 +147,6 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
console.Errorln(cpURLs.Error)
break
}
/* Too expensive. Ignore this for now. Let it fail while putObject.
if !globalForceFlag {
if cpURLs.TargetContent.Size != 0 || !cpURLs.TargetContent.Time.IsZero() {
console.Fatalf("Destination already exists, cannot overwrite ‘%s’ with ‘%s’. "+
"Use ‘--force’ flag to override.\n", cpURLs.TargetContent.Name, cpURLs.SourceContent.Name)
break
}
}
*/
jsonData, err := json.Marshal(cpURLs)
if err != nil {
-32
View File
@@ -97,24 +97,6 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) <-chan copyURLs {
copyURLsCh <- copyURLs{Error: NewIodine(iodine.New(errInvalidSource{URL: sourceURL}, nil))}
return
}
/* Too expensive. Ignore this for now. Let it fail while putObject.
targetClient, err := target2Client(targetURL)
if err != nil {
copyURLsCh <- copyURLs{Error: NewIodine(iodine.New(err, nil))}
return
}
// Target exists?
targetContent, err := targetClient.Stat()
if err == nil { // Target exists.
if !targetContent.Type.IsRegular() { // Target is not a regular file
copyURLsCh <- copyURLs{Error: NewIodine(iodine.New(errInvalidTarget{URL: targetURL}, nil))}
return
}
copyURLsCh <- copyURLs{SourceContent: sourceContent, TargetContent: targetContent}
return
}
*/
// All OK.. We can proceed. Type A
sourceContent.Name = sourceURL
copyURLsCh <- copyURLs{SourceContent: sourceContent, TargetContent: &client.Content{Name: targetURL}}
@@ -202,20 +184,6 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
return
}
_, targetContent, err := url2Stat(targetURL)
// Target exist?
if err != nil {
// Target does not exist.
copyURLsCh <- copyURLs{Error: NewIodine(iodine.New(errTargetNotFound{URL: targetURL}, nil))}
return
}
if !targetContent.Type.IsDir() {
// Target exists, but is not a directory.
copyURLsCh <- copyURLs{Error: NewIodine(iodine.New(errTargetIsNotDir{URL: targetURL}, nil))}
return
}
for sourceContent := range sourceClient.List(true) {
if sourceContent.Err != nil {
// Listing failed.