(ctx context.Context, state *State)
| 256 | } |
| 257 | |
| 258 | func (p *Proxy) SaveState(ctx context.Context, state *State) error { |
| 259 | containerName := p.containerName() |
| 260 | |
| 261 | data, err := json.MarshalIndent(state, "", " ") |
| 262 | if err != nil { |
| 263 | return fmt.Errorf("marshaling state: %w", err) |
| 264 | } |
| 265 | |
| 266 | var buf bytes.Buffer |
| 267 | tw := tar.NewWriter(&buf) |
| 268 | |
| 269 | header := &tar.Header{ |
| 270 | Name: stateFileName, |
| 271 | Mode: 0o644, |
| 272 | Size: int64(len(data)), |
| 273 | } |
| 274 | if err := tw.WriteHeader(header); err != nil { |
| 275 | return fmt.Errorf("writing tar header: %w", err) |
| 276 | } |
| 277 | if _, err := tw.Write(data); err != nil { |
| 278 | return fmt.Errorf("writing tar data: %w", err) |
| 279 | } |
| 280 | if err := tw.Close(); err != nil { |
| 281 | return fmt.Errorf("closing tar writer: %w", err) |
| 282 | } |
| 283 | |
| 284 | if err := p.namespace.client.CopyToContainer(ctx, containerName, stateFileDir, &buf, container.CopyToContainerOptions{}); err != nil { |
| 285 | return fmt.Errorf("copying state to container: %w", err) |
| 286 | } |
| 287 | |
| 288 | return nil |
| 289 | } |
| 290 | |
| 291 | func (p *Proxy) ExecOutput(ctx context.Context, cmd []string) (string, error) { |
| 292 | result, err := execInContainer(ctx, p.namespace.client, p.containerName(), cmd) |
no test coverage detected