Download this file
| 1 | package hostexec |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "os" |
| 6 | ) |
| 7 | |
| 8 | // ProjectRootClient keeps the agent's status and cleanup hint. It never |
| 9 | // establishes a lifetime lock or participates in root admission. |
| 10 | func ProjectRootClient(dataDir string, state State) error { |
| 11 | d, err := openLocal(dataDir) |
| 12 | if err != nil { |
| 13 | return err |
| 14 | } |
| 15 | defer d.close() |
| 16 | if state.State == "settled" { |
| 17 | old, err := d.read(state.Host) |
| 18 | if errors.Is(err, os.ErrNotExist) { |
| 19 | return nil |
| 20 | } |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | if old.Host != state.Host || old.Incarnation != state.Incarnation || old.Op != state.Op { |
| 25 | return ErrState |
| 26 | } |
| 27 | return d.remove(state.Host) |
| 28 | } |
| 29 | state.Process, err = currentControllerProcess() |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | return d.write(state) |
| 34 | } |
| 35 | |
| 36 | // ClearRootClientMirror follows a successful tokenless root serving view. |
| 37 | // Removing this status hint conveys no execution or update authority. |
| 38 | func ClearRootClientMirror(dataDir, host string) error { |
| 39 | d, err := openLocal(dataDir) |
| 40 | if err != nil { |
| 41 | return err |
| 42 | } |
| 43 | defer d.close() |
| 44 | err = d.remove(host) |
| 45 | if errors.Is(err, os.ErrNotExist) { |
| 46 | return nil |
| 47 | } |
| 48 | return err |
| 49 | } |
| 50 | |