(rw http.ResponseWriter, r *http.Request)
| 22 | var WindowsDriveRegex = regexp.MustCompile(`^[a-zA-Z]:\\$`) |
| 23 | |
| 24 | func (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 | |
| 65 | func listFiles(fs afero.Fs, path string, query workspacesdk.LSRequest) (workspacesdk.LSResponse, error) { |
| 66 | absolutePathString := path |
nothing calls this directly
no test coverage detected