MCPcopy Create free account
hub / github.com/dropbox/dbxcli / getRecursiveInternal

Function getRecursiveInternal

cmd/get.go:247–342  ·  view source on GitHub ↗
(dbx filesClient, src, dst string, rootMeta files.IsMetadata, opts getOptions, collectResults bool)

Source from the content-addressed store, hash-verified

245}
246
247func getRecursiveInternal(dbx filesClient, src, dst string, rootMeta files.IsMetadata, opts getOptions, collectResults bool) ([]getResult, error) {
248 arg := files.NewListFolderArg(src)
249 arg.Recursive = true
250
251 res, err := dbx.ListFolderContext(currentContext(), arg)
252 if err != nil {
253 return nil, withJSONErrorDetails(fmt.Errorf("list folder %s: %v", src, err), operationErrorDetails("download"), pathErrorDetails(src))
254 }
255
256 var entries []files.IsMetadata
257 entries = append(entries, res.Entries...)
258 for res.HasMore {
259 cont := files.NewListFolderContinueArg(res.Cursor)
260 res, err = dbx.ListFolderContinueContext(currentContext(), cont)
261 if err != nil {
262 return nil, withJSONErrorDetails(fmt.Errorf("list folder continue: %v", err), operationErrorDetails("download"), pathErrorDetails(src))
263 }
264 entries = append(entries, res.Entries...)
265 }
266
267 var results []getResult
268
269 if collectResults {
270 result, err := ensureLocalDirectoryResult(src, dst, rootMeta)
271 if err != nil {
272 return nil, err
273 }
274 results = append(results, result)
275 } else {
276 if err := os.MkdirAll(dst, 0755); err != nil {
277 return nil, err
278 }
279 }
280
281 var downloadErrors []error
282
283 for _, entry := range entries {
284 switch f := entry.(type) {
285 case *files.FolderMetadata:
286 relPath, err := relativeTo(src, f.PathDisplay)
287 if err != nil {
288 downloadErrors = append(downloadErrors, err)
289 continue
290 }
291 if relPath == "" {
292 continue
293 }
294 localDir := filepath.Join(dst, filepath.FromSlash(relPath))
295 if collectResults {
296 result, err := ensureLocalDirectoryResult(f.PathDisplay, localDir, f)
297 if err != nil {
298 downloadErrors = append(downloadErrors, fmt.Errorf("mkdir %s: %w", localDir, err))
299 continue
300 }
301 results = append(results, result)
302 } else {
303 if err := os.MkdirAll(localDir, 0755); err != nil {
304 downloadErrors = append(downloadErrors, fmt.Errorf("mkdir %s: %w", localDir, err))

Callers 2

getRecursiveFunction · 0.85
getRecursiveWithResultsFunction · 0.85

Calls 14

currentContextFunction · 0.85
withJSONErrorDetailsFunction · 0.85
operationErrorDetailsFunction · 0.85
pathErrorDetailsFunction · 0.85
relativeToFunction · 0.85
getErrorOutputFunction · 0.85
downloadFileWithResultFunction · 0.85
downloadFileFunction · 0.85
mergeJSONErrorDetailsFunction · 0.85
relocationErrorDetailsFunction · 0.85

Tested by

no test coverage detected