applyUpdateOperationToDatabase applies an update operation to the database.
(adapter persist.Adapter, op persist.PolicyOperation)
| 190 | |
| 191 | // applyUpdateOperationToDatabase applies an update operation to the database. |
| 192 | func (tx *Transaction) applyUpdateOperationToDatabase(adapter persist.Adapter, op persist.PolicyOperation) error { |
| 193 | if updateAdapter, ok := adapter.(persist.UpdatableAdapter); ok { |
| 194 | // Use update operation if available. |
| 195 | return updateAdapter.UpdatePolicies(op.Section, op.PolicyType, op.OldRules, op.Rules) |
| 196 | } |
| 197 | |
| 198 | // Fall back to remove + add. |
| 199 | for i, oldRule := range op.OldRules { |
| 200 | if err := adapter.RemovePolicy(op.Section, op.PolicyType, oldRule); err != nil { |
| 201 | return err |
| 202 | } |
| 203 | if err := adapter.AddPolicy(op.Section, op.PolicyType, op.Rules[i]); err != nil { |
| 204 | return err |
| 205 | } |
| 206 | } |
| 207 | return nil |
| 208 | } |
| 209 | |
| 210 | // applyOperationsToModel applies all buffered operations to the in-memory model. |
| 211 | func (tx *Transaction) applyOperationsToModel() error { |
no test coverage detected