carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package hostbox
2
3import (
4 "context"
5 "path"
6 "strings"
7)
8
9// IntendRole commits the empty child's exact parent and reserved name before
10// mkdir. Only Reserve can turn it into execution authority.
11func (j *LaunchJournal) IntendRole(ctx context.Context, r LaunchReservation) error {
12 if j == nil {
13 return ErrUnsupported
14 }
15 if j.remote != nil {
16 out, err := journalCall(ctx, j.remote, JournalRequest{Op: "intend", Reservation: r})
17 _ = out
18 return err
19 }
20
21 if r.NeverIntended || r.ID == "" || r.Role == "" || r.InvocationID == "" || r.Inputs == "" || r.State != "" || r.PID != 0 || r.ProcessStart != "" || r.Group.Device != 0 || r.Group.Inode != 0 || r.Group.InvocationID != r.InvocationID || r.Executable.Device == 0 || r.Executable.Inode == 0 || r.Parent.Device == 0 || r.Parent.Inode == 0 || !managedName(r.Parent.RelativePath) || path.Dir(r.Group.RelativePath) != r.Parent.RelativePath || !strings.HasPrefix(path.Base(r.Group.RelativePath), "role-") || !managedName(r.Group.RelativePath) {
22 return ErrUnsupported
23 }
24 return j.mutate(ctx, r.Target, func(in *LaunchInventory) error {
25 parent := false
26 for _, g := range in.Groups {
27 if g == r.Parent {
28 parent = true
29 }
30 }
31 if !parent {
32 return ErrChanged
33 }
34 for _, old := range in.Reservations {
35 if old.ID == r.ID || old.Group.RelativePath == r.Group.RelativePath {
36 return ErrChanged
37 }
38 }
39 for _, g := range in.Groups {
40 if g.RelativePath == r.Group.RelativePath {
41 return ErrChanged
42 }
43 }
44 r.State = "intended"
45 in.Reservations = append(in.Reservations, r)
46 return nil
47 })
48}
49