(ctx context.Context, dstPath string, payloads ...any)
| 22 | type DstPathToHook string |
| 23 | |
| 24 | func HookAndRemove(ctx context.Context, dstPath string, payloads ...any) { |
| 25 | dstStorage, dstActualPath, err := op.GetStorageAndActualPath(dstPath) |
| 26 | if err != nil { |
| 27 | log.Error(errors.WithMessage(err, "failed get dst storage")) |
| 28 | return |
| 29 | } |
| 30 | dstNeedHandleHook := setting.GetBool(conf.HandleHookAfterWriting) |
| 31 | dstHandleHookLimit := setting.GetFloat(conf.HandleHookRateLimit, .0) |
| 32 | var listLimiter *rate.Limiter |
| 33 | if dstNeedHandleHook && dstHandleHookLimit > .0 { |
| 34 | listLimiter = rate.NewLimiter(rate.Limit(dstHandleHookLimit), 1) |
| 35 | } |
| 36 | hookedPaths := make(map[string]struct{}) |
| 37 | handleHook := func(actualPath string) { |
| 38 | if _, ok := hookedPaths[actualPath]; ok { |
| 39 | return |
| 40 | } |
| 41 | if listLimiter != nil { |
| 42 | _ = listLimiter.Wait(ctx) |
| 43 | } |
| 44 | files, e := op.List(ctx, dstStorage, actualPath, model.ListArgs{SkipHook: true}) |
| 45 | if e != nil { |
| 46 | log.Errorf("failed handle objs update hook: %v", e) |
| 47 | } else { |
| 48 | op.HandleObjsUpdateHook(ctx, utils.GetFullPath(dstStorage.GetStorage().MountPath, actualPath), files) |
| 49 | hookedPaths[actualPath] = struct{}{} |
| 50 | } |
| 51 | } |
| 52 | if dstNeedHandleHook { |
| 53 | handleHook(dstActualPath) |
| 54 | } |
| 55 | for _, payload := range payloads { |
| 56 | switch p := payload.(type) { |
| 57 | case DstPathToHook: |
| 58 | if dstNeedHandleHook { |
| 59 | handleHook(string(p)) |
| 60 | } |
| 61 | case SrcPathToRemove: |
| 62 | srcStorage, srcActualPath, err := op.GetStorageAndActualPath(string(p)) |
| 63 | if err != nil { |
| 64 | log.Error(errors.WithMessage(err, "failed get src storage")) |
| 65 | continue |
| 66 | } |
| 67 | err = verifyAndRemove(ctx, srcStorage, dstStorage, srcActualPath, dstActualPath) |
| 68 | if err != nil { |
| 69 | log.Error(err) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func verifyAndRemove(ctx context.Context, srcStorage, dstStorage driver.Driver, srcPath, dstPath string) error { |
| 76 | srcObj, err := op.GetUnwrap(ctx, srcStorage, srcPath) |
nothing calls this directly
no test coverage detected