MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / getStorageVirtualFilesByPath

Function getStorageVirtualFilesByPath

internal/op/storage.go:378–443  ·  view source on GitHub ↗
(prefix string, rootCallback func(driver.Driver, model.Obj) model.Obj, filterByName string)

Source from the content-addressed store, hash-verified

376}
377
378func getStorageVirtualFilesByPath(prefix string, rootCallback func(driver.Driver, model.Obj) model.Obj, filterByName string) []model.Obj {
379 files := make([]model.Obj, 0)
380 storages := storagesMap.Values()
381 sort.Slice(storages, func(i, j int) bool {
382 if storages[i].GetStorage().Order == storages[j].GetStorage().Order {
383 return storages[i].GetStorage().MountPath < storages[j].GetStorage().MountPath
384 }
385 return storages[i].GetStorage().Order < storages[j].GetStorage().Order
386 })
387
388 if !strings.HasSuffix(prefix, "/") {
389 prefix += "/"
390 }
391 set := make(map[string]int)
392 var wg sync.WaitGroup
393 for _, v := range storages {
394 // Exclude prefix itself and non prefix
395 p, found := strings.CutPrefix(utils.GetActualMountPath(v.GetStorage().MountPath), prefix)
396 if !found || p == "" {
397 continue
398 }
399 name, _, found := strings.Cut(p, "/")
400 if filterByName != "" && name != filterByName {
401 continue
402 }
403
404 if idx, ok := set[name]; ok {
405 if !found {
406 files[idx].(*model.Object).Mask = model.Locked | model.Virtual
407 if rootCallback != nil {
408 wg.Add(1)
409 go func() {
410 defer wg.Done()
411 files[idx] = rootCallback(v, files[idx])
412 }()
413 }
414 }
415 continue
416 }
417 set[name] = len(files)
418 obj := &model.Object{
419 Name: name,
420 Modified: v.GetStorage().Modified,
421 IsFolder: true,
422 }
423 if !found {
424 idx := len(files)
425 obj.Mask = model.Locked | model.Virtual
426 files = append(files, obj)
427 if rootCallback != nil {
428 wg.Add(1)
429 go func() {
430 defer wg.Done()
431 files[idx] = rootCallback(v, files[idx])
432 }()
433 }
434 } else {
435 obj.Mask = model.ReadOnly | model.Virtual

Calls 6

GetActualMountPathFunction · 0.92
ValuesMethod · 0.80
GetStorageMethod · 0.65
AddMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected