Fix bugs related to cp, mirror code argument validation

This commit is contained in:
Harshavardhana
2015-09-29 00:17:16 -07:00
parent 306e36ef57
commit ee65cf7ab8
6 changed files with 32 additions and 31 deletions
+9
View File
@@ -204,3 +204,12 @@ func target2Client(targetURL string) (client.Client, *probe.Error) {
}
return targetClient, nil
}
// bucketExists returns error
func bucketExists(URL string) *probe.Error {
_, _, err := url2Stat(URL)
if err != nil {
return err.Trace()
}
return nil
}
+6 -15
View File
@@ -178,8 +178,7 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
if cpURLs.Error != nil {
// Print in new line and adjust to top so that we don't print over the ongoing scan bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
errorIf(cpURLs.Error.Trace(), "Unable to prepare URL for copying.")
break
@@ -187,7 +186,7 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
jsonData, err := json.Marshal(cpURLs)
if err != nil {
session.Close()
session.Delete()
fatalIf(probe.NewError(err), "Unable to prepare URL for copying. Error in JSON marshaling.")
}
fmt.Fprintln(dataFP, string(jsonData))
@@ -200,11 +199,9 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
case <-trapCh:
// Print in new line and adjust to top so that we don't print over the ongoing scan bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
session.Close() // If we are interrupted during the URL scanning, we drop the session.
session.Delete()
session.Delete() // If we are interrupted during the URL scanning, we drop the session.
os.Exit(0)
}
}
@@ -259,8 +256,7 @@ func doCopyCmdSession(session *sessionV2) {
} else {
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
switch cpURLs.Error.ToGoError().(type) {
// handle this specifically for filesystem
@@ -282,10 +278,8 @@ func doCopyCmdSession(session *sessionV2) {
os.Exit(0)
}
case <-trapCh: // Receive interrupt notification.
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
session.Close()
session.Info()
@@ -336,7 +330,6 @@ func mainCopy(ctx *cli.Context) {
session.Header.CommandType = "cp"
session.Header.RootPath, e = os.Getwd()
if e != nil {
session.Close()
session.Delete()
fatalIf(probe.NewError(e), "Unable to get current working folder.")
}
@@ -345,12 +338,10 @@ func mainCopy(ctx *cli.Context) {
var err *probe.Error
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
session.Delete()
fatalIf(err.Trace(), "One or more unknown URL types passed.")
}
doCopyCmdSession(session)
session.Close()
session.Delete()
}
+4
View File
@@ -77,9 +77,13 @@ func checkCopySyntax(ctx *cli.Context) {
{
url := client.NewURL(tgtURL)
if url.Host != "" {
// This check is for type URL.
if url.Path == string(url.Separator) {
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL))
}
if err := bucketExists(tgtURL); err != nil {
fatalIf(err.Trace(), fmt.Sprintf("Unable to stat target ‘%s’.", tgtURL))
}
}
}
switch guessCopyURLType(srcURLs, tgtURL) {
+1 -2
View File
@@ -270,8 +270,7 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan DiffMessage) {
wg.Wait()
doneCh <- struct{}{}
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
matchNameCh := make(chan string, 10000)
+6 -14
View File
@@ -174,8 +174,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
if sURLs.Error != nil {
// Print in new line and adjust to top so that we don't print over the ongoing scan bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
errorIf(sURLs.Error.Trace(), "Unable to prepare URLs for mirroring.")
break
@@ -185,7 +184,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
}
jsonData, err := json.Marshal(sURLs)
if err != nil {
session.Close()
session.Delete()
fatalIf(probe.NewError(err), "Unable to marshal URLs into JSON.")
}
fmt.Fprintln(dataFP, string(jsonData))
@@ -198,11 +197,9 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
case <-trapCh:
// Print in new line and adjust to top so that we don't print over the ongoing scan bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
session.Close() // If we are interrupted during the URL scanning, we drop the session.
session.Delete()
session.Delete() // If we are interrupted during the URL scanning, we drop the session.
os.Exit(0)
}
}
@@ -257,8 +254,7 @@ func doMirrorCmdSession(session *sessionV2) {
} else {
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
switch sURLs.Error.ToGoError().(type) {
// handle this specifically for filesystem
@@ -282,8 +278,7 @@ func doMirrorCmdSession(session *sessionV2) {
case <-trapCh: // Receive interrupt notification.
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
if !globalQuietFlag && !globalJSONFlag {
console.Printf("%c[2K\n", 27)
console.Printf("%c[A", 27)
console.Eraseline()
}
session.Close()
session.Info()
@@ -333,7 +328,6 @@ func mainMirror(ctx *cli.Context) {
session.Header.CommandType = "mirror"
session.Header.RootPath, e = os.Getwd()
if e != nil {
session.Close()
session.Delete()
fatalIf(probe.NewError(e), "Unable to get current working folder.")
}
@@ -342,12 +336,10 @@ func mainMirror(ctx *cli.Context) {
var err *probe.Error
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
session.Delete()
fatalIf(err.Trace(ctx.Args()...), fmt.Sprintf("One or more unknown argument types found in ‘%s’.", ctx.Args()))
}
doMirrorCmdSession(session)
session.Close()
session.Delete()
}
+6
View File
@@ -200,6 +200,12 @@ var (
}
return fmt.Sprint(data)
}
// Eraseline Print in new line and adjust to top so that we don't print over the ongoing progress bar
Eraseline = func() {
consolePrintf("Print", Theme["Print"], "%c[2K\n", 27)
consolePrintf("Print", Theme["Print"], "%c[A", 27)
}
)
// wrap around standard fmt functions