NewObject finds the Object at remote.
(ctx context.Context, remote string)
| 930 | |
| 931 | // NewObject finds the Object at remote. |
| 932 | func (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 |
| 976 | func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) { |