2021-05-16 16:39:33 +00:00
|
|
|
package bisync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/fs"
|
2023-11-17 17:14:38 +00:00
|
|
|
"github.com/rclone/rclone/lib/encoder"
|
2023-11-06 11:59:41 +00:00
|
|
|
"github.com/rclone/rclone/lib/terminal"
|
2021-05-16 16:39:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b *bisyncRun) indentf(tag, file, format string, args ...interface{}) {
|
|
|
|
b.indent(tag, file, fmt.Sprintf(format, args...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bisyncRun) indent(tag, file, msg string) {
|
|
|
|
logf := fs.Infof
|
|
|
|
switch {
|
|
|
|
case tag == "ERROR":
|
|
|
|
tag = ""
|
|
|
|
logf = fs.Errorf
|
|
|
|
case tag == "INFO":
|
|
|
|
tag = ""
|
|
|
|
case strings.HasPrefix(tag, "!"):
|
|
|
|
tag = tag[1:]
|
|
|
|
logf = fs.Logf
|
|
|
|
}
|
2023-11-06 11:59:41 +00:00
|
|
|
|
|
|
|
tag = Color(terminal.BlueFg, tag)
|
|
|
|
msg = Color(terminal.MagentaFg, msg)
|
|
|
|
file = Color(terminal.CyanFg, escapePath(file, false))
|
|
|
|
logf(nil, "- %-18s%-43s - %s", tag, msg, file)
|
2021-05-16 16:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// escapePath will escape control characters in path.
|
|
|
|
// It won't quote just due to backslashes on Windows.
|
|
|
|
func escapePath(path string, forceQuotes bool) string {
|
2023-11-17 17:14:38 +00:00
|
|
|
path = encode(path)
|
2021-05-16 16:39:33 +00:00
|
|
|
test := path
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
test = strings.ReplaceAll(path, "\\", "/")
|
|
|
|
}
|
|
|
|
if strconv.Quote(test) != `"`+test+`"` {
|
|
|
|
return strconv.Quote(path)
|
|
|
|
}
|
|
|
|
if forceQuotes {
|
|
|
|
return `"` + path + `"`
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
func quotePath(path string) string {
|
|
|
|
return escapePath(path, true)
|
|
|
|
}
|
2023-11-06 11:59:41 +00:00
|
|
|
|
|
|
|
// Color handles terminal colors for bisync
|
|
|
|
func Color(style string, s string) string {
|
|
|
|
terminal.Start()
|
|
|
|
return style + s + terminal.Reset
|
|
|
|
}
|
2023-11-17 17:14:38 +00:00
|
|
|
|
|
|
|
func encode(s string) string {
|
|
|
|
return encoder.OS.ToStandardPath(encoder.OS.FromStandardPath(s))
|
|
|
|
}
|