bisync: implementation #5164

Fixes #118

Co-authored-by: Chris Nelson <stuff@cjnaz.com>
This commit is contained in:
Ivan Andreev
2021-05-16 19:39:33 +03:00
parent 940e99a929
commit 6210e22ab5
16 changed files with 3057 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
// Package bilib provides common stuff for bisync and bisync_test
package bilib
import (
"os"
"regexp"
"runtime"
"strings"
"github.com/rclone/rclone/fs"
)
// FsPath converts Fs to a suitable rclone argument
func FsPath(f fs.Fs) string {
name, path, slash := f.Name(), f.Root(), "/"
if name == "local" {
slash = string(os.PathSeparator)
if runtime.GOOS == "windows" {
path = strings.ReplaceAll(path, "/", slash)
path = strings.TrimPrefix(path, `\\?\`)
}
} else {
path = name + ":" + path
}
if !strings.HasSuffix(path, slash) {
path += slash
}
return path
}
// CanonicalPath converts a remote to a suitable base file name
func CanonicalPath(remote string) string {
trimmed := strings.Trim(remote, `\/`)
return nonCanonicalChars.ReplaceAllString(trimmed, "_")
}
var nonCanonicalChars = regexp.MustCompile(`[\s\\/:?*]`)
// SessionName makes a unique base name for the sync operation
func SessionName(fs1, fs2 fs.Fs) string {
return CanonicalPath(FsPath(fs1)) + ".." + CanonicalPath(FsPath(fs2))
}