mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 17:14:44 +01:00
Factor RemoteSplit into fs
This commit is contained in:
parent
74a3dfc4e1
commit
d30cc1e119
27
cmd/cmd.go
27
cmd/cmd.go
@ -14,7 +14,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -166,30 +165,6 @@ func NewFsSrcDst(args []string) (fs.Fs, fs.Fs) {
|
|||||||
return fsrc, fdst
|
return fsrc, fdst
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteSplit splits a remote into a parent and a leaf
|
|
||||||
//
|
|
||||||
// if it returns leaf as an empty string then remote is a directory
|
|
||||||
//
|
|
||||||
// if it returns parent as an empty string then that means the current directory
|
|
||||||
//
|
|
||||||
// The returned values have the property that parent + leaf == remote
|
|
||||||
func RemoteSplit(remote string) (parent string, leaf string) {
|
|
||||||
// Split remote on :
|
|
||||||
i := strings.Index(remote, ":")
|
|
||||||
remoteName := ""
|
|
||||||
remotePath := remote
|
|
||||||
if i >= 0 {
|
|
||||||
remoteName = remote[:i+1]
|
|
||||||
remotePath = remote[i+1:]
|
|
||||||
} else if strings.HasSuffix(remotePath, "/") {
|
|
||||||
// if no : and ends with / must be directory
|
|
||||||
return remotePath, ""
|
|
||||||
}
|
|
||||||
// Construct new remote name without last segment
|
|
||||||
parent, leaf = path.Split(remotePath)
|
|
||||||
return remoteName + parent, leaf
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFsSrcDstFiles creates a new src and dst fs from the arguments
|
// NewFsSrcDstFiles creates a new src and dst fs from the arguments
|
||||||
// If src is a file then srcFileName and dstFileName will be non-empty
|
// If src is a file then srcFileName and dstFileName will be non-empty
|
||||||
func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs, dstFileName string) {
|
func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs, dstFileName string) {
|
||||||
@ -197,7 +172,7 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
|
|||||||
// If copying a file...
|
// If copying a file...
|
||||||
dstRemote := args[1]
|
dstRemote := args[1]
|
||||||
if srcFileName != "" {
|
if srcFileName != "" {
|
||||||
dstRemote, dstFileName = RemoteSplit(dstRemote)
|
dstRemote, dstFileName = fs.RemoteSplit(dstRemote)
|
||||||
if dstRemote == "" {
|
if dstRemote == "" {
|
||||||
dstRemote = "."
|
dstRemote = "."
|
||||||
}
|
}
|
||||||
|
30
fs/path.go
Normal file
30
fs/path.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package fs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RemoteSplit splits a remote into a parent and a leaf
|
||||||
|
//
|
||||||
|
// if it returns leaf as an empty string then remote is a directory
|
||||||
|
//
|
||||||
|
// if it returns parent as an empty string then that means the current directory
|
||||||
|
//
|
||||||
|
// The returned values have the property that parent + leaf == remote
|
||||||
|
func RemoteSplit(remote string) (parent string, leaf string) {
|
||||||
|
// Split remote on :
|
||||||
|
i := strings.Index(remote, ":")
|
||||||
|
remoteName := ""
|
||||||
|
remotePath := remote
|
||||||
|
if i >= 0 {
|
||||||
|
remoteName = remote[:i+1]
|
||||||
|
remotePath = remote[i+1:]
|
||||||
|
} else if strings.HasSuffix(remotePath, "/") {
|
||||||
|
// if no : and ends with / must be directory
|
||||||
|
return remotePath, ""
|
||||||
|
}
|
||||||
|
// Construct new remote name without last segment
|
||||||
|
parent, leaf = path.Split(remotePath)
|
||||||
|
return remoteName + parent, leaf
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue
Block a user