|
4 | 4 | "context"
|
5 | 5 | stdpath "path"
|
6 | 6 | "slices"
|
| 7 | + "strings" |
7 | 8 | "time"
|
8 | 9 |
|
9 | 10 | "github.com/OpenListTeam/OpenList/v4/internal/driver"
|
@@ -255,9 +256,31 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
255 | 256 | if storage.Config().CheckStatus && storage.GetStorage().Status != WORK {
|
256 | 257 | return nil, nil, errors.Errorf("storage not init: %s", storage.GetStorage().Status)
|
257 | 258 | }
|
258 |
| - file, err := GetUnwrap(ctx, storage, path) |
259 |
| - if err != nil { |
260 |
| - return nil, nil, errors.WithMessage(err, "failed to get file") |
| 259 | + var ( |
| 260 | + file model.Obj |
| 261 | + err error |
| 262 | + ) |
| 263 | + // use cache directly |
| 264 | + dir, name := stdpath.Split(stdpath.Join(storage.GetStorage().MountPath, path)) |
| 265 | + if cacheFiles, ok := listCache.Get(strings.TrimSuffix(dir, "/")); ok { |
| 266 | + for _, f := range cacheFiles { |
| 267 | + if f.GetName() == name { |
| 268 | + file = model.UnwrapObj(f) |
| 269 | + break |
| 270 | + } |
| 271 | + } |
| 272 | + } else { |
| 273 | + if g, ok := storage.(driver.GetObjInfo); ok { |
| 274 | + file, err = g.GetObjInfo(ctx, path) |
| 275 | + } else { |
| 276 | + file, err = GetUnwrap(ctx, storage, path) |
| 277 | + } |
| 278 | + } |
| 279 | + if file == nil { |
| 280 | + if err != nil { |
| 281 | + return nil, nil, errors.WithMessage(err, "failed to get file") |
| 282 | + } |
| 283 | + return nil, nil, errors.WithStack(errs.ObjectNotFound) |
261 | 284 | }
|
262 | 285 | if file.IsDir() {
|
263 | 286 | return nil, nil, errors.WithStack(errs.NotFile)
|
|
0 commit comments