Process calls all Operations to be performed on a Patch
(patch merger.Patch, cmd *model.Command)
| 73 | |
| 74 | // Process calls all Operations to be performed on a Patch |
| 75 | func (pr *Processor) Process(patch merger.Patch, cmd *model.Command) { |
| 76 | |
| 77 | var interrupted bool |
| 78 | |
| 79 | // Send the patch itself on the doneChan |
| 80 | defer func() { |
| 81 | if interrupted { |
| 82 | patch.Status(model.NewProcessingStatus("Patch interrupted by user").SetError(errors.New("patch interrupted by user"))) |
| 83 | } |
| 84 | patch.Done(patch) |
| 85 | }() |
| 86 | |
| 87 | patch.Filter(pr.GlobalContext, pr.Ignores...) |
| 88 | if errs, b := patch.HasErrors(); b { |
| 89 | for _, e := range errs { |
| 90 | log.Logger(pr.GlobalContext).Error("Errors after filtering patch", zap.Error(e)) |
| 91 | } |
| 92 | return // Errors while filtering, stop now |
| 93 | } |
| 94 | |
| 95 | for _, f := range patch.PostFilter() { |
| 96 | if e := f(); e != nil { |
| 97 | _ = patch.SetPatchError(e) |
| 98 | return |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if patch.Size() == 0 { |
| 103 | log.Logger(pr.GlobalContext).Info("Empty Patch : nothing to do") |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | // This is a bit hacky - We should have a more generic patch chan (not just Done) for publishing patches |
| 108 | if pr.PatchListener != nil { |
| 109 | pr.PatchListener.PublishPatch(patch) |
| 110 | } |
| 111 | |
| 112 | if !pr.SkipTargetChecks { |
| 113 | patch.FilterToTarget(pr.GlobalContext) |
| 114 | if patch.Size() == 0 { |
| 115 | log.Logger(pr.GlobalContext).Info("Empty Patch after filtering") |
| 116 | return |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | var cursor int64 |
| 121 | processUUID := uuid.New() |
| 122 | total := patch.ProgressTotal() |
| 123 | |
| 124 | patch.Status(model.NewProcessingStatus(fmt.Sprintf("Start processing patch (total bytes %d)", total))) |
| 125 | stats := patch.Stats() |
| 126 | pending := make(map[string]int) |
| 127 | if pen, ok := stats["Pending"]; ok { |
| 128 | pending = pen.(map[string]int) |
| 129 | } |
| 130 | |
| 131 | // Setup Session : patch will start/flush/finish session on underlying Source() and Target() |
| 132 | // if necessary. Flush is triggered between each operation type by checking if next type has |