Use url.Separator everywhere that is needed

This commit is contained in:
Harshavardhana
2015-06-10 21:54:05 -07:00
parent e6ad28079b
commit 08d38fb7da
4 changed files with 40 additions and 33 deletions
+11 -9
View File
@@ -25,6 +25,7 @@ import (
"sync"
"github.com/minio/cli"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/countlock"
"github.com/minio/mc/pkg/yielder"
@@ -69,34 +70,35 @@ EXAMPLES:
}
// doCopy - Copy a singe file from source to destination
func doCopy(sourceURL string, targetURL string, bar *barSend) error {
func doCopy(cURLs *cpURLs, bar *barSend) error {
if !globalQuietFlag {
bar.SetPrefix(sourceURL + ": ")
sourceContentParse, _ := client.Parse(cURLs.SourceContent.Name)
bar.SetCaption(caption{message: cURLs.SourceContent.Name + ": ", separator: sourceContentParse.Separator})
}
reader, length, err := getSource(sourceURL)
reader, length, err := getSource(cURLs.SourceContent.Name)
if err != nil {
if !globalQuietFlag {
bar.ErrorGet(int64(length))
}
return iodine.New(err, map[string]string{"URL": sourceURL})
return iodine.New(err, map[string]string{"URL": cURLs.SourceContent.Name})
}
defer reader.Close()
var newReader io.Reader
switch globalQuietFlag {
case true:
console.Infoln(fmt.Sprintf("‘%s’ -> ‘%s’", sourceURL, targetURL))
console.Infoln(fmt.Sprintf("‘%s’ -> ‘%s’", cURLs.SourceContent.Name, cURLs.TargetContent.Name))
newReader = yielder.NewReader(reader)
default:
// set up progress
newReader = bar.NewProxyReader(yielder.NewReader(reader))
}
err = putTarget(targetURL, length, newReader)
err = putTarget(cURLs.TargetContent.Name, length, newReader)
if err != nil {
if !globalQuietFlag {
bar.ErrorPut(int64(length))
}
return iodine.New(err, map[string]string{"URL": targetURL})
return iodine.New(err, map[string]string{"URL": cURLs.TargetContent.Name})
}
return nil
}
@@ -115,9 +117,9 @@ func args2URLs(args cli.Args) ([]string, error) {
return URLs, nil
}
func doCopyInRoutine(cpurls *cpURLs, bar *barSend, cpQueue chan bool, errCh chan error, wg *sync.WaitGroup) {
func doCopyInRoutine(cURLs *cpURLs, bar *barSend, cpQueue chan bool, errCh chan error, wg *sync.WaitGroup) {
defer wg.Done()
if err := doCopy(cpurls.SourceContent.Name, cpurls.TargetContent.Name, bar); err != nil {
if err := doCopy(cURLs, bar); err != nil {
errCh <- err
}
<-cpQueue // Signal that this copy routine is done.
+3 -1
View File
@@ -25,6 +25,7 @@ import (
"sync"
"github.com/minio/cli"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/countlock"
"github.com/minio/mc/pkg/yielder"
@@ -72,7 +73,8 @@ EXAMPLES:
func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, errCh chan error, wg *sync.WaitGroup) {
defer wg.Done()
if !globalQuietFlag {
bar.SetPrefix(sURLs.SourceContent.Name + ": ")
sourceContentParse, _ := client.Parse(sURLs.SourceContent.Name)
bar.SetCaption(caption{message: sURLs.SourceContent.Name + ": ", separator: sourceContentParse.Separator})
}
reader, length, err := getSource(sURLs.SourceContent.Name)
if err != nil {
+22 -19
View File
@@ -19,7 +19,6 @@ package main
import (
"fmt"
"io"
"path/filepath"
"strings"
"sync/atomic"
"time"
@@ -36,7 +35,7 @@ const (
cpBarCmdFinish
cpBarCmdPutError
cpBarCmdGetError
cpBarCmdSetPrefix
cpBarCmdSetCaption
)
type copyReader struct {
@@ -80,8 +79,13 @@ func (b *barSend) NewProxyReader(r io.Reader) *copyReader {
return &copyReader{r, b}
}
func (b *barSend) SetPrefix(prefix string) {
b.cmdCh <- barMsg{Cmd: cpBarCmdSetPrefix, Arg: prefix}
type caption struct {
message string
separator rune
}
func (b *barSend) SetCaption(c caption) {
b.cmdCh <- barMsg{Cmd: cpBarCmdSetCaption, Arg: c}
}
func (b barSend) Finish() {
@@ -90,20 +94,20 @@ func (b barSend) Finish() {
<-b.finishCh
}
func trimBarCaption(caption string, width int) string {
if len(caption) > width {
func trimBarCaption(c caption, width int) string {
if len(c.message) > width {
// Trim caption to fit within the screen
trimSize := len(caption) - width + 3 + 1
if trimSize < len(caption) {
caption = "..." + caption[trimSize:]
trimSize := len(c.message) - width + 3 + 1
if trimSize < len(c.message) {
c.message = "..." + c.message[trimSize:]
// Further trim partial names.
partialTrimSize := strings.IndexByte(caption, filepath.Separator)
partialTrimSize := strings.IndexByte(c.message, byte(c.separator))
if partialTrimSize > 0 {
caption = caption[partialTrimSize:]
c.message = c.message[partialTrimSize:]
}
}
}
return caption
return c.message
}
// newCpBar - instantiate a cpBar.
@@ -111,10 +115,10 @@ func newCpBar() barSend {
cmdCh := make(chan barMsg)
finishCh := make(chan bool)
go func(cmdCh <-chan barMsg, finishCh chan<- bool) {
started := false
redraw := false
barCaption := ""
var totalBytesRead int64 // total amounts of bytes copied
var started bool
var redraw bool
var barCaption string
var totalBytesRead int64 // total amounts of bytes read
bar := pb.New64(0)
bar.SetUnits(pb.U_BYTES)
bar.SetRefreshRate(time.Millisecond * 10)
@@ -135,9 +139,8 @@ func newCpBar() barSend {
bar.Format("[=> ]")
for msg := range cmdCh {
switch msg.Cmd {
case cpBarCmdSetPrefix:
barCaption = msg.Arg.(string)
barCaption = trimBarCaption(barCaption, bar.GetWidth())
case cpBarCmdSetCaption:
barCaption = trimBarCaption(msg.Arg.(caption), bar.GetWidth())
case cpBarCmdExtend:
atomic.AddInt64(&bar.Total, msg.Arg.(int64))
case cpBarCmdProgress:
+4 -4
View File
@@ -55,7 +55,7 @@ func (f *fsClient) fsStat() (os.FileInfo, error) {
fpath := f.path
// Golang strips trailing / if you clean(..) or
// EvalSymlinks(..). Adding '.' prevents it from doing so.
if strings.HasSuffix(fpath, string(filepath.Separator)) {
if strings.HasSuffix(fpath, string(f.URL().Separator)) {
fpath = fpath + "."
}
@@ -127,7 +127,7 @@ func (f *fsClient) GetObject(offset, length int64) (io.ReadCloser, int64, error)
fpath := f.path
// Golang strips trailing / if you clean(..) or
// EvalSymlinks(..). Adding '.' prevents it from doing so.
if strings.HasSuffix(fpath, string(filepath.Separator)) {
if strings.HasSuffix(fpath, string(f.URL().Separator)) {
fpath = fpath + "."
}
@@ -172,7 +172,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
fpath := f.path
// Golang strips trailing / if you clean(..) or
// EvalSymlinks(..). Adding '.' prevents it from doing so.
if strings.HasSuffix(fpath, string(filepath.Separator)) {
if strings.HasSuffix(fpath, string(f.URL().Separator)) {
fpath = fpath + "."
}
@@ -274,7 +274,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
func (f *fsClient) delimited(fp string) string {
var stripPrefix string
stripPrefix = f.path[:strings.LastIndex(f.path, string(filepath.Separator))+1]
stripPrefix = f.path[:strings.LastIndex(f.path, string(f.URL().Separator))+1]
return strings.TrimPrefix(fp, stripPrefix)
}