Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cmd: make names of argument parsing functions more consistent

Nick Craig-Wood291954babab8
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 6e0d19fe6..315a26cca 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -144,9 +144,10 @@ func ShowVersion() {
fmt.Printf("- go version: %s\n", runtime.Version())
}
-// NewFsFile creates a dst Fs from a name but may point to a file.
+// NewFsFile creates a Fs from a name but may point to a file.
//
// It returns a string with the file name if points to a file
+// otherwise "".
func NewFsFile(remote string) (fs.Fs, string) {
fsInfo, configName, fsPath, err := fs.ParseRemote(remote)
if err != nil {
@@ -166,12 +167,11 @@ func NewFsFile(remote string) (fs.Fs, string) {
return nil, ""
}
-// newFsSrc creates a src Fs from a name
+// newFsFileAddFilter creates a src Fs from a name
//
-// It returns a string with the file name if limiting to one file
-//
-// This can point to a file
-func newFsSrc(remote string) (fs.Fs, string) {
+// This works the same as NewFsFile however it adds filters to the Fs
+// to limit it to a single file if the remote pointed to a file.
+func newFsFileAddFilter(remote string) (fs.Fs, string) {
f, fileName := NewFsFile(remote)
if fileName != "" {
if !filter.Active.InActive() {
@@ -189,10 +189,20 @@ func newFsSrc(remote string) (fs.Fs, string) {
return f, fileName
}
-// newFsDst creates a dst Fs from a name
+// NewFsSrc creates a new src fs from the arguments.
+//
+// The source can be a file or a directory - if a file then it will
+// limit the Fs to a single file.
+func NewFsSrc(args []string) fs.Fs {
+ fsrc, _ := newFsFileAddFilter(args[0])
+ fs.CalculateModifyWindow(fsrc)
+ return fsrc
+}
+
+// newFsDir creates an Fs from a name
//
// This must point to a directory
-func newFsDst(remote string) fs.Fs {
+func newFsDir(remote string) fs.Fs {
f, err := fs.NewFs(remote)
if err != nil {
fs.CountError(err)
@@ -201,10 +211,19 @@ func newFsDst(remote string) fs.Fs {
return f
}
+// NewFsDir creates a new Fs from the arguments
+//
+// The argument must point a directory
+func NewFsDir(args []string) fs.Fs {
+ fdst := newFsDir(args[0])
+ fs.CalculateModifyWindow(fdst)
+ return fdst
+}
+
// NewFsSrcDst creates a new src and dst fs from the arguments
func NewFsSrcDst(args []string) (fs.Fs, fs.Fs) {
- fsrc, _ := newFsSrc(args[0])
- fdst := newFsDst(args[1])
+ fsrc, _ := newFsFileAddFilter(args[0])
+ fdst := newFsDir(args[1])
fs.CalculateModifyWindow(fdst, fsrc)
return fsrc, fdst
}
@@ -212,7 +231,7 @@ func NewFsSrcDst(args []string) (fs.Fs, fs.Fs) {
// NewFsSrcDstFiles creates a new src and dst fs from the arguments
// 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) {
- fsrc, srcFileName = newFsSrc(args[0])
+ fsrc, srcFileName = newFsFileAddFilter(args[0])
// If copying a file...
dstRemote := args[1]
// If file exists then srcFileName != "", however if the file
@@ -240,22 +259,6 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
return
}
-// NewFsSrc creates a new src fs from the arguments
-func NewFsSrc(args []string) fs.Fs {
- fsrc, _ := newFsSrc(args[0])
- fs.CalculateModifyWindow(fsrc)
- return fsrc
-}
-
-// NewFsDst creates a new dst fs from the arguments
-//
-// Dst fs-es can't point to single files
-func NewFsDst(args []string) fs.Fs {
- fdst := newFsDst(args[0])
- fs.CalculateModifyWindow(fdst)
- return fdst
-}
-
// NewFsDstFile creates a new dst fs with a destination file name from the arguments
func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) {
dstRemote, dstFileName := fspath.RemoteSplit(args[0])
@@ -265,7 +268,7 @@ func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) {
if dstFileName == "" {
log.Fatalf("%q is a directory", args[0])
}
- fdst = newFsDst(dstRemote)
+ fdst = newFsDir(dstRemote)
fs.CalculateModifyWindow(fdst)
return
}
diff --git a/cmd/info/info.go b/cmd/info/info.go
index 06385264d..1a85bcf86 100644
--- a/cmd/info/info.go
+++ b/cmd/info/info.go
@@ -48,7 +48,7 @@ a bit of go code for each one.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1E6, command, args)
for i := range args {
- f := cmd.NewFsDst(args[i : i+1])
+ f := cmd.NewFsDir(args[i : i+1])
cmd.Run(false, false, command, func() error {
return readInfo(f)
})
diff --git a/cmd/mkdir/mkdir.go b/cmd/mkdir/mkdir.go
index 0c55a4237..4cac2d6e2 100644
--- a/cmd/mkdir/mkdir.go
+++ b/cmd/mkdir/mkdir.go
@@ -15,7 +15,7 @@ var commandDefintion = &cobra.Command{
Short: `Make the path if it doesn't already exist.`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
- fdst := cmd.NewFsDst(args)
+ fdst := cmd.NewFsDir(args)
cmd.Run(true, false, command, func() error {
return operations.Mkdir(fdst, "")
})
diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go
index a6fa42202..00fa0c911 100644
--- a/cmd/mountlib/mount.go
+++ b/cmd/mountlib/mount.go
@@ -215,7 +215,7 @@ be copied to the vfs cache before opening with --vfs-cache-mode full.
` + vfs.Help,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(2, 2, command, args)
- fdst := cmd.NewFsDst(args)
+ fdst := cmd.NewFsDir(args)
// Show stats if the user has specifically requested them
if cmd.ShowStats() {
diff --git a/cmd/purge/purge.go b/cmd/purge/purge.go
index 804cb2812..33c8b5eb6 100644
--- a/cmd/purge/purge.go
+++ b/cmd/purge/purge.go
@@ -20,7 +20,7 @@ you want to selectively delete files.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
- fdst := cmd.NewFsDst(args)
+ fdst := cmd.NewFsDir(args)
cmd.Run(true, false, command, func() error {
return operations.Purge(fdst, "")
})
diff --git a/cmd/rmdir/rmdir.go b/cmd/rmdir/rmdir.go
index 9b10c0696..6f85cf86c 100644
--- a/cmd/rmdir/rmdir.go
+++ b/cmd/rmdir/rmdir.go
@@ -18,7 +18,7 @@ Remove the path. Note that you can't remove a path with
objects in it, use purge for that.`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
- fdst := cmd.NewFsDst(args)
+ fdst := cmd.NewFsDir(args)
cmd.Run(true, false, command, func() error {
return operations.Rmdir(fdst, "")
})
diff --git a/cmd/rmdirs/rmdirs.go b/cmd/rmdirs/rmdirs.go
index 354920b14..41c0e23ee 100644
--- a/cmd/rmdirs/rmdirs.go
+++ b/cmd/rmdirs/rmdirs.go
@@ -30,7 +30,7 @@ empty directories in.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
- fdst := cmd.NewFsDst(args)
+ fdst := cmd.NewFsDir(args)
cmd.Run(true, false, command, func() error {
return operations.Rmdirs(fdst, "", leaveRoot)
})