Skip to content

Commit a665b5c

Browse files
committed
fix(agent/agentcontainers): remove deleted devcontainers
1 parent 4fd0312 commit a665b5c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

agent/agentcontainers/api.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,18 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
661661

662662
case dc.Container == nil:
663663
if !api.devcontainerNames[dc.Name] {
664-
dc.Name = ""
664+
// If this is a runtime-detected container, check if we
665+
// should remove it.
666+
// TODO(mafredri): Consider using afero.
667+
if _, err := os.Stat(dc.WorkspaceFolder); errors.Is(err, os.ErrNotExist) {
668+
// If the workspace folder doesn't exist, we can assume
669+
// that the devcontainer is no longer valid and should be
670+
// removed.
671+
logger.Debug(ctx, "devcontainer workspace folder does not exist, removing devcontainer")
672+
delete(api.knownDevcontainers, dc.WorkspaceFolder)
673+
// TODO(mafredri): Delete the agent if it exists.
674+
continue
675+
}
665676
}
666677
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStopped
667678
dc.Dirty = false

0 commit comments

Comments
 (0)