Merge pull request #835 from harshavardhana/pr_out_fix_sync_bug_when_in_typea_and_typeb_sync_style_source_doesn_t_exist

This commit is contained in:
Harshavardhana
2015-06-22 15:59:07 -07:00
13 changed files with 110 additions and 36 deletions
+1 -3
View File
@@ -74,7 +74,7 @@ func runConfigCmd(ctx *cli.Context) {
if err != nil {
console.Fatals(ErrorMessage{
Message: msg,
Error: err,
Error: iodine.New(err, nil),
})
}
console.Infos(InfoMessage{
@@ -89,12 +89,10 @@ func saveConfig(arg string, aliases []string) error {
if isMcConfigExist() {
return iodine.New(errConfigExists{}, nil)
}
config, err := newConfig()
if err != nil {
return iodine.New(err, nil)
}
err = writeConfig(config)
if err != nil {
return iodine.New(err, nil)
+13 -4
View File
@@ -95,7 +95,10 @@ func doCopySession(cURLs cpURLs, bar *barSend, s *sessionV1) error {
var newReader io.Reader
switch globalQuietFlag {
case true:
console.Infoln(fmt.Sprintf("‘%s’ -> ‘%s’", cURLs.SourceContent.Name, cURLs.TargetContent.Name))
console.Infos(CopyMessage{
Source: cURLs.SourceContent.Name,
Target: cURLs.TargetContent.Name,
})
newReader = yielder.NewReader(reader)
default:
// set up progress
@@ -226,13 +229,19 @@ func runCopyCmd(ctx *cli.Context) {
}
if !isSessionDirExists() {
if err := createSessionDir(); err != nil {
console.Fatalln(iodine.ToError(err))
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
}
}
s, err := newSession()
if err != nil {
console.Fatalln(iodine.ToError(err))
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
}
s.CommandType = "cp"
@@ -262,7 +271,7 @@ func runCopyCmd(ctx *cli.Context) {
if err := saveSession(s); err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.ToError(err),
Error: iodine.New(err, nil),
})
}
console.Infos(InfoMessage{
+7 -7
View File
@@ -68,7 +68,7 @@ func runDiffCmd(ctx *cli.Context) {
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: err,
Error: iodine.New(err, nil),
})
}
@@ -81,12 +81,12 @@ func runDiffCmd(ctx *cli.Context) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", firstURL),
Error: err,
Error: iodine.New(err, nil),
})
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", firstURL),
Error: err,
Error: iodine.New(err, nil),
})
}
}
@@ -96,19 +96,19 @@ func runDiffCmd(ctx *cli.Context) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", secondURL),
Error: err,
Error: iodine.New(err, nil),
})
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", secondURL),
Error: err,
Error: iodine.New(err, nil),
})
}
}
if isURLRecursive(secondURL) {
console.Fatals(ErrorMessage{
Message: "Second URL cannot be recursive, diff command is unidirectional",
Error: errInvalidArgument{},
Error: iodine.New(errInvalidArgument{}, nil),
})
}
newFirstURL := stripRecursiveURL(firstURL)
@@ -116,7 +116,7 @@ func runDiffCmd(ctx *cli.Context) {
if diff.err != nil {
console.Fatals(ErrorMessage{
Message: diff.message,
Error: diff.err,
Error: iodine.New(diff.err, nil),
})
}
console.Infos(InfoMessage{
+2 -2
View File
@@ -119,7 +119,7 @@ func runListCmd(ctx *cli.Context) {
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Failed to list ‘%s’", targetURL),
Error: iodine.New(err, nil),
Error: iodine.New(err, map[string]string{"Target": targetURL}),
})
}
}
@@ -133,7 +133,7 @@ func doListCmd(targetURL string, recursive bool) error {
}
err = doList(clnt, recursive)
if err != nil {
return iodine.New(err, nil)
return iodine.New(err, map[string]string{"Target": targetURL})
}
return nil
}
+3 -3
View File
@@ -73,7 +73,7 @@ func listSessions(sdir string) error {
if err != nil {
return iodine.New(err, nil)
}
console.Println(s)
console.Prints(s)
}
}
return nil
@@ -140,7 +140,7 @@ func sessionExecute(bar barSend, s *sessionV1) {
if err := saveSession(s); err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.ToError(err),
Error: iodine.New(err, nil),
})
}
os.Exit(0)
@@ -158,7 +158,7 @@ func sessionExecute(bar barSend, s *sessionV1) {
if err := saveSession(s); err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.ToError(err),
Error: iodine.New(err, nil),
})
}
// this os.Exit is needed really to exit in-case of "os.Interrupt"
+18 -3
View File
@@ -23,6 +23,7 @@ import (
"os"
"os/signal"
"runtime"
"strings"
"sync"
"github.com/minio/cli"
@@ -71,9 +72,13 @@ EXAMPLES:
// doSyncSession - Sync an object to multiple destination
func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan syncSession, wg *sync.WaitGroup, s *sessionV1) {
// waitgroup reply deferred until this function returns
defer wg.Done()
// hold lock for map updates inside session
s.Lock.Lock()
defer s.Lock.Unlock()
if !globalQuietFlag {
bar.SetCaption(sURLs.SourceContent.Name + ": ")
}
@@ -105,6 +110,10 @@ func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan
var newReader io.Reader
switch globalQuietFlag {
case true:
console.Infos(SyncMessage{
Source: sURLs.SourceContent.Name,
Target: strings.Join(targetURLs, " "),
})
newReader = yielder.NewReader(reader)
default:
// set up progress
@@ -222,13 +231,19 @@ func runSyncCmd(ctx *cli.Context) {
if !isSessionDirExists() {
if err := createSessionDir(); err != nil {
console.Fatalln(iodine.ToError(err))
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
}
}
s, err := newSession()
if err != nil {
console.Fatalln(iodine.ToError(err))
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
}
s.CommandType = "sync"
@@ -258,7 +273,7 @@ func runSyncCmd(ctx *cli.Context) {
if err := saveSession(s); err != nil {
console.Fatals(ErrorMessage{
Message: "Failed wtih",
Error: iodine.ToError(err),
Error: iodine.New(err, nil),
})
}
console.Infos(InfoMessage{
+2 -3
View File
@@ -18,7 +18,6 @@ package main
import (
"encoding/json"
"fmt"
"net/http"
"runtime"
"time"
@@ -93,7 +92,7 @@ https://dl.minio.io:9000 for continuous updates`
if err != nil {
return "", err
}
fmt.Println(msg)
console.Prints(InfoMessage{Message: msg})
return "", nil
}
return "You are already running the most recent version of ‘mc’", nil
@@ -120,6 +119,6 @@ func runUpdateCmd(ctx *cli.Context) {
}
// no msg do not print one
if msg != "" {
console.Infoln(msg)
console.Infos(InfoMessage{Message: msg})
}
}
+7
View File
@@ -53,6 +53,13 @@ type cpURLs struct {
Error error
}
func (c cpURLs) IsEmpty() bool {
if c.SourceContent == nil && c.TargetContent == nil {
return true
}
return false
}
type cpURLsType uint8
const (
+10 -4
View File
@@ -77,20 +77,26 @@ func doList(clnt client.Client, recursive bool) error {
var err error
for contentCh := range clnt.List(recursive) {
if contentCh.Err != nil {
switch e := iodine.ToError(contentCh.Err).(type) {
switch err := iodine.ToError(contentCh.Err).(type) {
// handle this specifically for filesystem
case client.ISBrokenSymlink:
console.Errorln(e)
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
continue
}
if os.IsNotExist(iodine.ToError(contentCh.Err)) || os.IsPermission(iodine.ToError(contentCh.Err)) {
console.Errorln(iodine.ToError(contentCh.Err))
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(contentCh.Err, nil),
})
continue
}
err = contentCh.Err
break
}
console.Println(parseContent(contentCh.Content))
console.Prints(parseContent(contentCh.Content))
}
if err != nil {
return iodine.New(err, map[string]string{"Target": clnt.URL().String()})
+4 -4
View File
@@ -35,7 +35,7 @@ func checkConfig() {
if err != nil {
console.Fatals(ErrorMessage{
Message: "Unable to determine current user",
Error: err,
Error: iodine.New(err, nil),
})
}
@@ -49,7 +49,7 @@ func checkConfig() {
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file: %s", mustGetMcConfigPath()),
Error: err,
Error: iodine.New(err, nil),
})
}
}
@@ -126,7 +126,7 @@ func main() {
err := iodine.New(errInvalidTheme{Theme: themeName}, nil)
console.Errors(ErrorMessage{
Message: fmt.Sprintf("Please choose from this list: %s.", console.GetThemeNames()),
Error: err,
Error: iodine.New(err, nil),
})
return err
default:
@@ -134,7 +134,7 @@ func main() {
if err != nil {
console.Errors(ErrorMessage{
Message: fmt.Sprintf("Failed to set theme ‘%s’.", themeName),
Error: err,
Error: iodine.New(err, nil),
})
return err
}
+1 -1
View File
@@ -128,7 +128,7 @@ var (
Prints = func(data ...interface{}) {
for i := 0; i < len(data); i++ {
if NoJSONPrint {
println(themesDB[currThemeName].Info, data[i])
println(themesDB[currThemeName].Print, data[i])
return
}
infoBytes, _ := json.Marshal(&data[i])
+20
View File
@@ -18,6 +18,8 @@
package main
import (
"fmt"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
)
@@ -71,3 +73,21 @@ type InfoMessage struct {
func (i InfoMessage) String() string {
return i.Message
}
// CopyMessage container for file copy messages
type CopyMessage struct {
Message string `json:"message"`
Source string `json:"source"`
Target string `json:"target"`
}
func (c CopyMessage) String() string {
return fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target)
}
// SyncMessage container for file sync messages, inherits CopyMessage
type SyncMessage CopyMessage
func (s SyncMessage) String() string {
return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Target)
}
+22 -2
View File
@@ -52,6 +52,22 @@ type syncURLs struct {
Error error
}
func (s syncURLs) IsEmpty() bool {
empty := false
if s.SourceContent == nil {
empty = true
if s.TargetContents == nil {
empty = true
return empty
}
if len(s.TargetContents) > 0 && s.TargetContents[0] == nil {
empty = true
return empty
}
}
return empty
}
type syncURLsType cpURLsType
// guessSyncURLType guesses the type of URL. This approach all allows prepareURL
@@ -91,7 +107,9 @@ func prepareSyncURLsTypeA(sourceURL string, targetURLs []string) <-chan syncURLs
sURLs.SourceContent = cURLs.SourceContent
sURLs.TargetContents = append(sURLs.TargetContents, cURLs.TargetContent)
}
syncURLsCh <- sURLs
if !sURLs.IsEmpty() {
syncURLsCh <- sURLs
}
}()
return syncURLsCh
}
@@ -113,7 +131,9 @@ func prepareSyncURLsTypeB(sourceURL string, targetURLs []string) <-chan syncURLs
sURLs.SourceContent = cURLs.SourceContent
sURLs.TargetContents = append(sURLs.TargetContents, cURLs.TargetContent)
}
syncURLsCh <- sURLs
if !sURLs.IsEmpty() {
syncURLsCh <- sURLs
}
}()
return syncURLsCh
}