diff --git a/cmd/nfsmount/nfsmount.go b/cmd/nfsmount/nfsmount.go index b21ffdd3e..2931cdac0 100644 --- a/cmd/nfsmount/nfsmount.go +++ b/cmd/nfsmount/nfsmount.go @@ -21,8 +21,7 @@ import ( ) var ( - sudo = false - nfsServerOpt nfs.Options + sudo = false ) func init() { @@ -33,11 +32,11 @@ func init() { mountlib.AddRc(name, mount) cmdFlags := cmd.Flags() flags.BoolVarP(cmdFlags, &sudo, "sudo", "", sudo, "Use sudo to run the mount/umount commands as root.", "") - nfs.AddFlags(cmdFlags, &nfsServerOpt) + nfs.AddFlags(cmdFlags) } func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (asyncerrors <-chan error, unmount func() error, err error) { - s, err := nfs.NewServer(context.Background(), VFS, &nfsServerOpt) + s, err := nfs.NewServer(context.Background(), VFS, &nfs.Opt) if err != nil { return } diff --git a/cmd/nfsmount/nfsmount_test.go b/cmd/nfsmount/nfsmount_test.go index 78990b572..8412cea71 100644 --- a/cmd/nfsmount/nfsmount_test.go +++ b/cmd/nfsmount/nfsmount_test.go @@ -7,6 +7,7 @@ import ( "runtime" "testing" + "github.com/rclone/rclone/cmd/serve/nfs" "github.com/rclone/rclone/vfs/vfscommon" "github.com/rclone/rclone/vfs/vfstest" "github.com/stretchr/testify/require" @@ -29,7 +30,7 @@ func TestMount(t *testing.T) { } sudo = true } - nfsServerOpt.HandleCacheDir = t.TempDir() - require.NoError(t, nfsServerOpt.HandleCache.Set("disk")) + nfs.Opt.HandleCacheDir = t.TempDir() + require.NoError(t, nfs.Opt.HandleCache.Set("disk")) vfstest.RunTests(t, false, vfscommon.CacheModeWrites, false, mount) } diff --git a/cmd/serve/nfs/nfs.go b/cmd/serve/nfs/nfs.go index c30b3b755..b6819b52d 100644 --- a/cmd/serve/nfs/nfs.go +++ b/cmd/serve/nfs/nfs.go @@ -43,7 +43,7 @@ var OptionsInfo = fs.Options{{ }} func init() { - fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "nfs", Opt: &opt, Options: OptionsInfo}) + fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "nfs", Opt: &Opt, Options: OptionsInfo}) } type handleCache = fs.Enum[handleCacheChoices] @@ -72,16 +72,17 @@ type Options struct { HandleCacheDir string `config:"nfs_cache_dir"` // where the handle cache should be stored } -var opt Options +// Opt is the default set of serve nfs options +var Opt Options // AddFlags adds flags for serve nfs (and nfsmount) -func AddFlags(flagSet *pflag.FlagSet, Opt *Options) { +func AddFlags(flagSet *pflag.FlagSet) { flags.AddFlagsFromOptions(flagSet, "", OptionsInfo) } func init() { vfsflags.AddFlags(Command.Flags()) - AddFlags(Command.Flags(), &opt) + AddFlags(Command.Flags()) } // Run the command @@ -90,7 +91,7 @@ func Run(command *cobra.Command, args []string) { cmd.CheckArgs(1, 1, command, args) f = cmd.NewFsSrc(args) cmd.Run(false, true, command, func() error { - s, err := NewServer(context.Background(), vfs.New(f, &vfscommon.Opt), &opt) + s, err := NewServer(context.Background(), vfs.New(f, &vfscommon.Opt), &Opt) if err != nil { return err }