mirror/cp: Remove aliases from being printed in json output. - fixes #1563
Additionally save expanded targetURL also part of session.
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+21
-17
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+15
-16
@@ -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
|
||||
}
|
||||
|
||||
+2
-1
@@ -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)
|
||||
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user