WriteFile writes to a file in the workspace.
(ctx context.Context, path string, reader io.Reader)
| 1019 | |
| 1020 | // WriteFile writes to a file in the workspace. |
| 1021 | func (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. |
| 1044 | type ReadFileLinesResponse struct { |
nothing calls this directly
no test coverage detected