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

Method HandleWriteFile

agent/agentfiles/files.go:302–335  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

300}
301
302func (api *API) HandleWriteFile(rw http.ResponseWriter, r *http.Request) {
303 ctx := r.Context()
304
305 query := r.URL.Query()
306 parser := httpapi.NewQueryParamParser().RequiredNotEmpty("path")
307 path := parser.String(query, "", "path")
308 parser.ErrorExcessParams(query)
309 if len(parser.Errors) > 0 {
310 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
311 Message: "Query parameters have invalid values.",
312 Validations: parser.Errors,
313 })
314 return
315 }
316
317 status, err := api.writeFile(ctx, r, path)
318 if err != nil {
319 httpapi.Write(ctx, rw, status, codersdk.Response{
320 Message: err.Error(),
321 })
322 return
323 }
324
325 // Track edited path for git watch.
326 if api.pathStore != nil {
327 if chatContext, ok := agentchat.FromContext(ctx); ok {
328 api.pathStore.AddPaths(append([]uuid.UUID{chatContext.ID}, chatContext.AncestorIDs...), []string{path})
329 }
330 }
331
332 httpapi.Write(ctx, rw, http.StatusOK, codersdk.Response{
333 Message: fmt.Sprintf("Successfully wrote to %q", path),
334 })
335}
336
337func (api *API) writeFile(ctx context.Context, r *http.Request, path string) (HTTPResponseCode, error) {
338 if !filepath.IsAbs(path) {

Callers

nothing calls this directly

Calls 10

writeFileMethod · 0.95
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
FromContextFunction · 0.92
RequiredNotEmptyMethod · 0.80
ErrorExcessParamsMethod · 0.80
AddPathsMethod · 0.80
ContextMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected