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

Method handleDevcontainerDelete

agent/agentcontainers/api.go:1249–1381  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1247}
1248
1249func (api *API) handleDevcontainerDelete(w http.ResponseWriter, r *http.Request) {
1250 var (
1251 ctx = r.Context()
1252 devcontainerID = chi.URLParam(r, "devcontainer")
1253 )
1254
1255 if devcontainerID == "" {
1256 httpapi.Write(ctx, w, http.StatusBadRequest, codersdk.Response{
1257 Message: "Missing devcontainer ID",
1258 Detail: "Devcontainer ID is required to delete a devcontainer.",
1259 })
1260 return
1261 }
1262
1263 api.mu.Lock()
1264
1265 dc, err := api.devcontainerByIDLocked(devcontainerID)
1266 if err != nil {
1267 api.mu.Unlock()
1268 httperror.WriteResponseError(ctx, w, err)
1269 return
1270 }
1271
1272 // NOTE(DanielleMaywood):
1273 // We currently do not support canceling the startup of a dev container.
1274 if dc.Status.Transitioning() {
1275 api.mu.Unlock()
1276
1277 httpapi.Write(ctx, w, http.StatusConflict, codersdk.Response{
1278 Message: "Unable to delete transitioning devcontainer",
1279 Detail: fmt.Sprintf("Devcontainer %q is currently %s and cannot be deleted.", dc.Name, dc.Status),
1280 })
1281 return
1282 }
1283
1284 var (
1285 containerID string
1286 subAgentID uuid.UUID
1287 )
1288 if dc.Container != nil {
1289 containerID = dc.Container.ID
1290 }
1291 if proc, hasSubAgent := api.injectedSubAgentProcs[dc.WorkspaceFolder]; hasSubAgent && proc.agent.ID != uuid.Nil {
1292 subAgentID = proc.agent.ID
1293 proc.stop()
1294 }
1295
1296 dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStopping
1297 dc.Error = ""
1298 api.knownDevcontainers[dc.WorkspaceFolder] = dc
1299 api.broadcastUpdatesLocked()
1300 api.mu.Unlock()
1301
1302 // Stop and remove the container if it exists.
1303 if containerID != "" {
1304 if err := api.ccli.Stop(ctx, containerID); err != nil {
1305 api.logger.Error(ctx, "unable to stop container", slog.Error(err))
1306

Callers

nothing calls this directly

Calls 14

WriteFunction · 0.92
WriteResponseErrorFunction · 0.92
TransitioningMethod · 0.80
ContextMethod · 0.65
stopMethod · 0.65
StopMethod · 0.65
RemoveMethod · 0.65
DeleteMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected