Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "path/filepath" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/activator" |
| 9 | "github.com/carlosframework/platform/internal/instancefs" |
| 10 | "github.com/carlosframework/platform/internal/provision" |
| 11 | "github.com/carlosframework/platform/internal/registry" |
| 12 | ) |
| 13 | |
| 14 | func ensureClaimLaunchToken(ctx context.Context, backend *activator.ExecBackend, route registry.Route, authorize func(context.Context, func() error) error) error { |
| 15 | if authorize == nil { |
| 16 | return backend.EnsureClaimAdminToken(ctx, route, nil) |
| 17 | } |
| 18 | return backend.EnsureClaimAdminToken(ctx, route, func(call context.Context, effect func() error) error { |
| 19 | return authorize(call, func() error { |
| 20 | if layout, _ := backend.Layout(route); layout == activator.LayoutNested { |
| 21 | dir := provision.InstanceDir(backend.DataDir, route.Host) |
| 22 | parent := filepath.Dir(dir) |
| 23 | if _, err := instancefs.EnsureDirBeneath(parent, filepath.Base(dir), 0700); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | fd, err := instancefs.OpenDirBeneath(parent, ".") |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | if err = errors.Join(fd.Sync(), fd.Close()); err != nil { |
| 31 | return err |
| 32 | } |
| 33 | } |
| 34 | return effect() |
| 35 | }) |
| 36 | }) |
| 37 | } |
| 38 | |