MCPcopy
hub / github.com/rclone/rclone / NewObject

Method NewObject

backend/cache/cache.go:932–973  ·  view source on GitHub ↗

NewObject finds the Object at remote.

(ctx context.Context, remote string)

Source from the content-addressed store, hash-verified

930
931// NewObject finds the Object at remote.
932func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
933 var err error
934
935 fs.Debugf(f, "new object '%s'", remote)
936 co := NewObject(f, remote)
937 // search for entry in cache and validate it
938 err = f.cache.GetObject(co)
939 if err != nil {
940 fs.Debugf(remote, "find: error: %v", err)
941 } else if time.Now().After(co.CacheTs.Add(time.Duration(f.opt.InfoAge))) {
942 fs.Debugf(co, "find: cold object: %+v", co)
943 } else {
944 fs.Debugf(co, "find: warm object: %v, expiring on: %v", co, co.CacheTs.Add(time.Duration(f.opt.InfoAge)))
945 return co, nil
946 }
947
948 // search for entry in source or temp fs
949 var obj fs.Object
950 if f.opt.TempWritePath != "" {
951 obj, err = f.tempFs.NewObject(ctx, remote)
952 // not found in temp fs
953 if err != nil {
954 fs.Debugf(remote, "find: not found in local cache fs")
955 obj, err = f.Fs.NewObject(ctx, remote)
956 } else {
957 fs.Debugf(obj, "find: found in local cache fs")
958 }
959 } else {
960 obj, err = f.Fs.NewObject(ctx, remote)
961 }
962
963 // not found in either fs
964 if err != nil {
965 fs.Debugf(obj, "find failed: not found in either local or remote fs")
966 return nil, err
967 }
968
969 // cache the new entry
970 co = ObjectFromOriginal(ctx, f, obj).persist()
971 fs.Debugf(co, "find: cached object")
972 return co, nil
973}
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) {

Callers 1

rcFetchMethod · 0.95

Calls 7

DebugfFunction · 0.92
ObjectFromOriginalFunction · 0.85
persistMethod · 0.80
NewObjectFunction · 0.70
AddMethod · 0.65
NewObjectMethod · 0.65
GetObjectMethod · 0.45

Tested by

no test coverage detected