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

Method HandleLS

agent/agentfiles/ls.go:24–63  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

22var WindowsDriveRegex = regexp.MustCompile(`^[a-zA-Z]:\\$`)
23
24func (api *API) HandleLS(rw http.ResponseWriter, r *http.Request) {
25 ctx := r.Context()
26
27 // An absolute path may be optionally provided, otherwise a path split into an
28 // array must be provided in the body (which can be relative).
29 query := r.URL.Query()
30 parser := httpapi.NewQueryParamParser()
31 path := parser.String(query, "", "path")
32 parser.ErrorExcessParams(query)
33 if len(parser.Errors) > 0 {
34 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
35 Message: "Query parameters have invalid values.",
36 Validations: parser.Errors,
37 })
38 return
39 }
40
41 var req workspacesdk.LSRequest
42 if !httpapi.Read(ctx, rw, r, &req) {
43 return
44 }
45
46 resp, err := listFiles(api.filesystem, path, req)
47 if err != nil {
48 status := http.StatusInternalServerError
49 switch {
50 case errors.Is(err, os.ErrNotExist):
51 status = http.StatusNotFound
52 case errors.Is(err, os.ErrPermission):
53 status = http.StatusForbidden
54 default:
55 }
56 httpapi.Write(ctx, rw, status, codersdk.Response{
57 Message: err.Error(),
58 })
59 return
60 }
61
62 httpapi.Write(ctx, rw, http.StatusOK, resp)
63}
64
65func listFiles(fs afero.Fs, path string, query workspacesdk.LSRequest) (workspacesdk.LSResponse, error) {
66 absolutePathString := path

Callers

nothing calls this directly

Calls 9

StringMethod · 0.95
ErrorExcessParamsMethod · 0.95
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
ReadFunction · 0.92
listFilesFunction · 0.85
ContextMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected