MCPcopy Index your code
hub / github.com/coder/coder / WriteFile

Method WriteFile

codersdk/workspacesdk/agentconn.go:1021–1041  ·  view source on GitHub ↗

WriteFile writes to a file in the workspace.

(ctx context.Context, path string, reader io.Reader)

Source from the content-addressed store, hash-verified

1019
1020// WriteFile writes to a file in the workspace.
1021func (c *agentConn) WriteFile(ctx context.Context, path string, reader io.Reader) error {
1022 ctx, span := tracing.StartSpan(ctx)
1023 defer span.End()
1024
1025 res, err := c.apiRequest(ctx, http.MethodPost, agentAPIPath("/api/v0/write-file", neturl.Values{
1026 "path": []string{path},
1027 }), reader)
1028 if err != nil {
1029 return xerrors.Errorf("do request: %w", err)
1030 }
1031 defer res.Body.Close()
1032 if res.StatusCode != http.StatusOK {
1033 return codersdk.ReadBodyAsError(res)
1034 }
1035
1036 var m codersdk.Response
1037 if err := json.NewDecoder(res.Body).Decode(&m); err != nil {
1038 return xerrors.Errorf("decode response body: %w", err)
1039 }
1040 return nil
1041}
1042
1043// ReadFileLinesResponse is the response from the line-based file reader.
1044type ReadFileLinesResponse struct {

Callers

nothing calls this directly

Calls 6

apiRequestMethod · 0.95
StartSpanFunction · 0.92
ReadBodyAsErrorFunction · 0.92
agentAPIPathFunction · 0.85
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected