MCPcopy
hub / github.com/basecamp/once / SaveState

Method SaveState

internal/docker/proxy.go:258–289  ·  view source on GitHub ↗
(ctx context.Context, state *State)

Source from the content-addressed store, hash-verified

256}
257
258func (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
291func (p *Proxy) ExecOutput(ctx context.Context, cmd []string) (string, error) {
292 result, err := execInContainer(ctx, p.namespace.client, p.containerName(), cmd)

Callers 2

checkSelfUpdateMethod · 0.45
saveOperationResultMethod · 0.45

Calls 5

containerNameMethod · 0.95
WriteHeaderMethod · 0.80
CopyToContainerMethod · 0.80
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected