diff --git a/common-methods.go b/common-methods.go index df48b823..2aeb5af1 100644 --- a/common-methods.go +++ b/common-methods.go @@ -109,7 +109,7 @@ func newClientFromAlias(alias string, urlStr string) (client.Client, *probe.Erro s3Config.AccessKey = hostCfg.AccessKey s3Config.SecretKey = hostCfg.SecretKey s3Config.Signature = hostCfg.API - s3Config.AppName = "Minio" + s3Config.AppName = "mc" s3Config.AppVersion = mcVersion s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH} s3Config.HostURL = urlStr diff --git a/cp-main.go b/cp-main.go index e146d877..f916d6fd 100644 --- a/cp-main.go +++ b/cp-main.go @@ -23,6 +23,7 @@ import ( "io" "math" "os" + "path/filepath" "runtime" "strings" "sync" @@ -88,12 +89,9 @@ EXAMPLES: // copyMessage container for file copy messages type copyMessage struct { - Status string `json:"status"` - SourceAlias string `json:"sourceAlias,omitempty"` - Source string `json:"source"` - TargetAlias string `json:"targetAlias,omitempty"` - Target string `json:"target"` - Length int64 `json:"length"` + Status string `json:"status"` + Source string `json:"source"` + Target string `json:"target"` } // String colorized copy message @@ -147,24 +145,29 @@ func doCopy(cpURLs copyURLs, progressReader *barSend, accountingReader *accounte progressReader.SetCaption(cpURLs.SourceContent.URL.String() + ": ") } - reader, err := getSourceFromAlias(cpURLs.SourceAlias, cpURLs.SourceContent.URL.String()) + sourceAlias := cpURLs.SourceAlias + sourceURL := cpURLs.SourceContent.URL + targetAlias := cpURLs.TargetAlias + targetURL := cpURLs.TargetContent.URL + length := cpURLs.SourceContent.Size + + reader, err := getSourceFromAlias(sourceAlias, sourceURL.String()) if err != nil { if !globalQuiet && !globalJSON { - progressReader.ErrorGet(cpURLs.SourceContent.Size) + progressReader.ErrorGet(length) } - cpURLs.Error = err.Trace(cpURLs.SourceContent.URL.String()) + cpURLs.Error = err.Trace(sourceURL.String()) statusCh <- cpURLs return } var newReader io.ReadSeeker if globalQuiet || globalJSON { + sourcePath := filepath.Join(sourceAlias, sourceURL.Path) + targetPath := filepath.Join(targetAlias, targetURL.Path) printMsg(copyMessage{ - SourceAlias: cpURLs.SourceAlias, - Source: cpURLs.SourceContent.URL.String(), - TargetAlias: cpURLs.TargetAlias, - Target: cpURLs.TargetContent.URL.String(), - Length: cpURLs.SourceContent.Size, + Source: sourcePath, + Target: targetPath, }) // No accounting necessary for JSON output. if globalJSON { @@ -178,11 +181,12 @@ func doCopy(cpURLs copyURLs, progressReader *barSend, accountingReader *accounte // set up progress newReader = progressReader.NewProxyReader(reader) } - if err := putTarget(cpURLs.TargetContent.URL.String(), newReader, cpURLs.SourceContent.Size); err != nil { + err = putTargetFromAlias(targetAlias, targetURL.String(), newReader, length) + if err != nil { if !globalQuiet && !globalJSON { - progressReader.ErrorPut(cpURLs.SourceContent.Size) + progressReader.ErrorPut(length) } - cpURLs.Error = err.Trace(cpURLs.TargetContent.URL.String()) + cpURLs.Error = err.Trace(targetURL.String()) statusCh <- cpURLs return } diff --git a/cp-url.go b/cp-url.go index 94c3fdd0..63278c93 100644 --- a/cp-url.go +++ b/cp-url.go @@ -94,7 +94,8 @@ func guessCopyURLType(sourceURLs []string, targetURL string, isRecursive bool) ( func prepareCopyURLsTypeA(sourceURL string, targetURL string) copyURLs { // Extract alias before fiddling with the URL. sourceAlias, _, _ := mustExpandAlias(sourceURL) - targetAlias, _, _ := mustExpandAlias(targetURL) + // Find alias and expanded URL. + targetAlias, targetURL, _ := mustExpandAlias(targetURL) if sourceURL == targetURL { // source and target can not be same @@ -129,7 +130,8 @@ func makeCopyContentTypeA(sourceAlias string, sourceContent *client.Content, tar func prepareCopyURLsTypeB(sourceURL string, targetURL string) copyURLs { // Extract alias before fiddling with the URL. sourceAlias, _, _ := mustExpandAlias(sourceURL) - targetAlias, _, _ := mustExpandAlias(targetURL) + // Find alias and expanded URL. + targetAlias, targetURL, _ := mustExpandAlias(targetURL) _, sourceContent, err := url2Stat(sourceURL) if err != nil { @@ -162,7 +164,8 @@ func makeCopyContentTypeB(sourceAlias string, sourceContent *client.Content, tar func prepareCopyURLsTypeC(sourceURL, targetURL string, isRecursive bool) <-chan copyURLs { // Extract alias before fiddling with the URL. sourceAlias, _, _ := mustExpandAlias(sourceURL) - targetAlias, _, _ := mustExpandAlias(targetURL) + // Find alias and expanded URL. + targetAlias, targetURL, _ := mustExpandAlias(targetURL) copyURLsCh := make(chan copyURLs) go func(sourceURL, targetURL string, copyURLsCh chan copyURLs) { diff --git a/mirror-main.go b/mirror-main.go index de57501b..c9ae1c2c 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -23,6 +23,7 @@ import ( "io" "math" "os" + "path/filepath" "runtime" "sync" "syscall" @@ -78,11 +79,9 @@ EXAMPLES: // mirrorMessage container for file mirror messages type mirrorMessage struct { - Status string `json:"status"` - SourceAlias string `json:"sourceAlias,omitempty"` - Source string `json:"source"` - TargetAlias string `json:"targetAlias,omitempty"` - Target string `json:"target"` + Status string `json:"status"` + Source string `json:"source"` + Target string `json:"target"` } // String colorized mirror message @@ -133,32 +132,32 @@ func doMirror(sURLs mirrorURLs, progressReader *barSend, accountingReader *accou } sourceAlias := sURLs.SourceAlias - sourceURL := sURLs.SourceContent.URL.String() + sourceURL := sURLs.SourceContent.URL targetAlias := sURLs.TargetAlias - targetURL := sURLs.TargetContent.URL.String() + targetURL := sURLs.TargetContent.URL length := sURLs.SourceContent.Size if !globalQuiet && !globalJSON { - progressReader.SetCaption(sourceURL + ": ") + progressReader.SetCaption(sourceURL.String() + ": ") } - reader, err := getSourceFromAlias(sourceAlias, sourceURL) + reader, err := getSourceFromAlias(sourceAlias, sourceURL.String()) if err != nil { if !globalQuiet && !globalJSON { progressReader.ErrorGet(length) } - sURLs.Error = err.Trace(sourceURL) + sURLs.Error = err.Trace(sourceURL.String()) statusCh <- sURLs return } var newReader io.ReadSeeker if globalQuiet || globalJSON { + sourcePath := filepath.Join(sourceAlias, sourceURL.Path) + targetPath := filepath.Join(targetAlias, targetURL.Path) printMsg(mirrorMessage{ - SourceAlias: sourceAlias, - Source: sourceURL, - TargetAlias: targetAlias, - Target: targetURL, + Source: sourcePath, + Target: targetPath, }) if globalJSON { newReader = reader @@ -170,12 +169,12 @@ func doMirror(sURLs mirrorURLs, progressReader *barSend, accountingReader *accou // set up progress newReader = progressReader.NewProxyReader(reader) } - err = putTargetFromAlias(targetAlias, targetURL, newReader, length) + err = putTargetFromAlias(targetAlias, targetURL.String(), newReader, length) if err != nil { if !globalQuiet && !globalJSON { progressReader.ErrorPut(length) } - sURLs.Error = err.Trace(targetURL) + sURLs.Error = err.Trace(targetURL.String()) statusCh <- sURLs return } diff --git a/mirror-url.go b/mirror-url.go index e66efd90..35cf8b20 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -94,7 +94,8 @@ func checkMirrorSyntax(ctx *cli.Context) { func deltaSourceTargets(sourceURL string, targetURL string, isForce bool, mirrorURLsCh chan<- mirrorURLs) { // Extract alias before fiddling with the URL. sourceAlias, _, _ := mustExpandAlias(sourceURL) - targetAlias, _, _ := mustExpandAlias(targetURL) + // Find alias and expanded URL + targetAlias, targetURL, _ := mustExpandAlias(targetURL) defer close(mirrorURLsCh) diff --git a/progress-bar.go b/progress-bar.go index 474fa1e4..b4399aba 100644 --- a/progress-bar.go +++ b/progress-bar.go @@ -50,7 +50,9 @@ type proxyReader struct { func (r *proxyReader) Read(p []byte) (n int, err error) { n, err = r.ReadSeeker.Read(p) if err != nil { - return + if err != io.EOF { + return + } } r.bar.Progress(int64(n)) return