diff --git a/internal/model/obj.go b/internal/model/obj.go index 1314c286c7b..346f300d951 100644 --- a/internal/model/obj.go +++ b/internal/model/obj.go @@ -26,3 +26,7 @@ type URL interface { type Thumbnail interface { Thumbnail() string } + +type SetID interface { + SetID(id string) +} diff --git a/internal/model/object.go b/internal/model/object.go index 463d21a4f61..b8124fe8153 100644 --- a/internal/model/object.go +++ b/internal/model/object.go @@ -29,3 +29,7 @@ func (f Object) IsDir() bool { func (f Object) GetID() string { return f.ID } + +func (f *Object) SetID(id string) { + f.ID = id +} diff --git a/internal/operations/fs.go b/internal/operations/fs.go index 4a2466bf660..d3ccf01edcc 100644 --- a/internal/operations/fs.go +++ b/internal/operations/fs.go @@ -44,8 +44,7 @@ func List(ctx context.Context, account driver.Driver, path string) ([]model.Obj, return files, err } -// Get get object from list of files -// TODO: maybe should set object ID with path here +// Get object from list of files func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, error) { // is root folder if r, ok := account.GetAddition().(driver.IRootFolderId); ok && utils.PathEqual(path, "/") { @@ -74,6 +73,13 @@ func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, er } for _, f := range files { if f.GetName() == name { + // use path as id, why don't set id in List function? + // because files maybe cache, set id here can reduce memory usage + if f.GetID() == "" { + if s, ok := f.(model.SetID); ok { + s.SetID(path) + } + } return f, nil } }