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

smb: save the user name in the config even if it matches the current user - fixes #9356

phatlc3c51b96774c2
diff --git a/backend/smb/smb.go b/backend/smb/smb.go
index 541a4fcd0..b6be8277e 100644
--- a/backend/smb/smb.go
+++ b/backend/smb/smb.go
@@ -51,8 +51,7 @@ func init() {
Sensitive: true,
}, {
Name: "user",
- Help: "SMB username.",
- Default: currentUser,
+ Help: "SMB username.\n\nLeave blank to use the current user name.",
Sensitive: true,
}, {
Name: "port",
@@ -205,6 +204,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
if err != nil {
return nil, err
}
+ if opt.User == "" {
+ opt.User = currentUser
+ }
// if root is empty or ends with / (must be a directory)
isRootDir := isPathDir(root)
diff --git a/backend/smb/smb_internal_test.go b/backend/smb/smb_internal_test.go
index f11e131d1..03216f959 100644
--- a/backend/smb/smb_internal_test.go
+++ b/backend/smb/smb_internal_test.go
@@ -158,3 +158,33 @@ func TestIsPathDir(t *testing.T) {
})
}
}
+
+func TestNewFsUser(t *testing.T) {
+ ctx := context.Background()
+ for _, test := range []struct {
+ user string
+ want string
+ }{
+ {user: "", want: currentUser},
+ {user: currentUser, want: currentUser},
+ {user: "someone", want: "someone"},
+ } {
+ m := configmap.Simple{"host": "localhost", "user": test.user}
+ f, err := NewFs(ctx, "TestSMB", "", m)
+ require.NoError(t, err)
+ assert.Equal(t, test.want, f.(*Fs).opt.User, "user=%q", test.user)
+ }
+
+ // No user in the config at all
+ f, err := NewFs(ctx, "TestSMB", "", configmap.Simple{"host": "localhost"})
+ require.NoError(t, err)
+ assert.Equal(t, currentUser, f.(*Fs).opt.User)
+}
+
+// The default is blank so that a user name which happens to match the
+// current user is still written to the config file.
+func TestUserDefault(t *testing.T) {
+ ri, err := fs.Find("smb")
+ require.NoError(t, err)
+ assert.Equal(t, "", ri.Options.Get("user").Default)
+}