carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "context"
5 "errors"
6 "os"
7
8 "github.com/carlosframework/platform/internal/hostbox"
9 "github.com/carlosframework/platform/internal/hostguard"
10)
11
12type claimBoundUnitCleanup struct {
13 inner hostbox.RetirementAuthority
14 retire func(context.Context, hostguard.FenceTarget) error
15}
16
17func (c claimBoundUnitCleanup) WithCleanup(ctx context.Context, t hostguard.FenceTarget, fn func() error) error {
18 return c.inner.WithCleanup(ctx, t, func() error {
19 if err := c.retire(ctx, t); err != nil {
20 return err
21 }
22 return fn()
23 })
24}
25
26func retireClaimBoundUnit(ctx context.Context, t hostguard.FenceTarget, b *claimUnitBindings, m claimUnitMaterializer, gone func(context.Context, string, string) error) error {
27 captured, err := b.read(t.Host)
28 if errors.Is(err, os.ErrNotExist) {
29 return nil
30 }
31 if err != nil {
32 return err
33 }
34 if captured.Owner.Host != t.Host || captured.Owner.Incarnation != t.Incarnation || captured.Owner.Stamp != t.Stamp || captured.Owner.Box != t.Box || captured.Owner.Enrollment != t.Enrollment || gone == nil {
35 return os.ErrPermission
36 }
37 captured.Retiring, captured.Retired = false, false
38 return b.retire(ctx, captured, func(claimUnitBinding) error {
39 return m.retire(ctx, captured, func() error { return gone(ctx, t.Host, "") })
40 })
41}
42