MCPcopy
hub / github.com/rclone/rclone / List

Method List

backend/cache/cache.go:976–1089  ·  view source on GitHub ↗

List the objects and directories in dir into entries

(ctx context.Context, dir string)

Source from the content-addressed store, hash-verified

974
975// List the objects and directories in dir into entries
976func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {
977 fs.Debugf(f, "list '%s'", dir)
978 cd := ShallowDirectory(f, dir)
979
980 // search for cached dir entries and validate them
981 entries, err = f.cache.GetDirEntries(cd)
982 if err != nil {
983 fs.Debugf(dir, "list: error: %v", err)
984 } else if time.Now().After(cd.CacheTs.Add(time.Duration(f.opt.InfoAge))) {
985 fs.Debugf(dir, "list: cold listing: %v", cd.CacheTs)
986 } else if len(entries) == 0 {
987 // TODO: read empty dirs from source?
988 fs.Debugf(dir, "list: empty listing")
989 } else {
990 fs.Debugf(dir, "list: warm %v from cache for: %v, expiring on: %v", len(entries), cd.abs(), cd.CacheTs.Add(time.Duration(f.opt.InfoAge)))
991 fs.Debugf(dir, "list: cached entries: %v", entries)
992 return entries, nil
993 }
994
995 // we first search any temporary files stored locally
996 var cachedEntries fs.DirEntries
997 if f.opt.TempWritePath != "" {
998 queuedEntries, err := f.cache.searchPendingUploadFromDir(cd.abs())
999 if err != nil {
1000 fs.Errorf(dir, "list: error getting pending uploads: %v", err)
1001 } else {
1002 fs.Debugf(dir, "list: read %v from temp fs", len(queuedEntries))
1003 fs.Debugf(dir, "list: temp fs entries: %v", queuedEntries)
1004
1005 for _, queuedRemote := range queuedEntries {
1006 queuedEntry, err := f.tempFs.NewObject(ctx, f.cleanRootFromPath(queuedRemote))
1007 if err != nil {
1008 fs.Debugf(dir, "list: temp file not found in local fs: %v", err)
1009 continue
1010 }
1011 co := ObjectFromOriginal(ctx, f, queuedEntry).persist()
1012 fs.Debugf(co, "list: cached temp object")
1013 cachedEntries = append(cachedEntries, co)
1014 }
1015 }
1016 }
1017
1018 // search from the source
1019 sourceEntries, err := f.Fs.List(ctx, dir)
1020 if err != nil {
1021 return nil, err
1022 }
1023 fs.Debugf(dir, "list: read %v from source", len(sourceEntries))
1024 fs.Debugf(dir, "list: source entries: %v", sourceEntries)
1025
1026 sort.Sort(sourceEntries)
1027 for _, entry := range entries {
1028 entryRemote := entry.Remote()
1029 i := sort.Search(len(sourceEntries), func(i int) bool { return sourceEntries[i].Remote() >= entryRemote })
1030 if i < len(sourceEntries) && sourceEntries[i].Remote() == entryRemote {
1031 continue
1032 }
1033 fp := path.Join(f.Root(), entryRemote)

Callers 1

recurseMethod · 0.95

Calls 15

cleanRootFromPathMethod · 0.95
RootMethod · 0.95
DebugfFunction · 0.92
ErrorfFunction · 0.92
ShallowDirectoryFunction · 0.85
ObjectFromOriginalFunction · 0.85
DirectoryFromOriginalFunction · 0.85
GetDirEntriesMethod · 0.80
persistMethod · 0.80
JoinMethod · 0.80
RemoveObjectMethod · 0.80

Tested by

no test coverage detected