@@ -20,7 +20,9 @@ import (
2020 "strings"
2121
2222 "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
23+ "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/common"
2324 "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
25+ "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/users"
2426 "github.com/spf13/cobra"
2527)
2628
@@ -168,6 +170,28 @@ func initDbx(cmd *cobra.Command, args []string) (err error) {
168170
169171 config = makeDropboxConfig (accessToken , verbose , asMember , domain )
170172
173+ // Auto-detect the root namespace so that team folders are accessible.
174+ // Team manage tokens are for administrative operations and don't need
175+ // a path root; skip auto-detection for those.
176+ if tokType != tokenTeamManage {
177+ usersClient := users .New (config )
178+ account , accountErr := usersClient .GetCurrentAccount ()
179+ if accountErr != nil {
180+ config .LogInfo ("Warning: could not auto-detect root namespace (%v); team folders may not be accessible" , accountErr )
181+ } else {
182+ var rootNamespaceID string
183+ switch ri := account .RootInfo .(type ) {
184+ case * common.TeamRootInfo :
185+ rootNamespaceID = ri .RootNamespaceId
186+ case * common.UserRootInfo :
187+ rootNamespaceID = ri .RootNamespaceId
188+ }
189+ if rootNamespaceID != "" {
190+ config = config .WithRoot (rootNamespaceID )
191+ }
192+ }
193+ }
194+
171195 return
172196}
173197
0 commit comments