Skip to content

Commit

Permalink
Remove storage calls from local.Driver.alterModules
Browse files Browse the repository at this point in the history
Signed-off-by: davis-haba <davishaba@google.com>
  • Loading branch information
davis-haba committed Jan 19, 2022
1 parent b0196c3 commit 4e8c239
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions constraint/pkg/client/drivers/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ func (d *Driver) putModules(namePrefix string, srcs []string) error {
// the provided modules then returns the count of modules removed.
// alterModules expects that the caller is holding the modulesMux lock.
func (d *Driver) alterModules(insert insertParam, remove []string) (int, error) {
// TODO(davis-haba): Remove this Context once it is no longer necessary.
ctx := context.TODO()

updatedModules := copyModules(d.modules)
for _, name := range remove {
delete(updatedModules, name)
Expand All @@ -240,38 +237,14 @@ func (d *Driver) alterModules(insert insertParam, remove []string) (int, error)
updatedModules[name] = mod.parsed
}

txn, err := d.storage.NewTransaction(ctx, storage.WriteParams)
if err != nil {
return 0, err
}

for _, name := range remove {
if err := d.storage.DeletePolicy(ctx, txn, name); err != nil {
d.storage.Abort(ctx, txn)
return 0, err
}
}

c := ast.NewCompiler().WithPathConflictsCheck(storage.NonEmpty(ctx, d.storage, txn)).
c := ast.NewCompiler().
WithCapabilities(d.capabilities).
WithEnablePrintStatements(d.printEnabled)

if c.Compile(updatedModules); c.Failed() {
d.storage.Abort(ctx, txn)
return 0, fmt.Errorf("%w: %v", ErrCompile, c.Errors)
}

for name, mod := range insert {
if err := d.storage.UpsertPolicy(ctx, txn, name, []byte(mod.text)); err != nil {
d.storage.Abort(ctx, txn)
return 0, err
}
}

if err := d.storage.Commit(ctx, txn); err != nil {
return 0, err
}

d.compiler = c
d.modules = updatedModules

Expand Down

0 comments on commit 4e8c239

Please sign in to comment.