Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d76cf6

Browse files
chore: appease linter
1 parent ae5dd1e commit 9d76cf6

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ func (a *agent) createDevcontainer(
12341234
startTime = a.clock.Now()
12351235
status = proto.Timing_OK
12361236
)
1237-
if err = a.containerAPI.CreateDevcontainer(dc); err != nil {
1237+
if err = a.containerAPI.CreateDevcontainer(dc, dc.ConfigPath, agentcontainers.CreateBehaviorStart); err != nil {
12381238
exitCode = 1
12391239
status = proto.Timing_EXIT_FAILURE
12401240
}

agent/agentcontainers/api.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
921921
api.knownDevcontainers[dc.WorkspaceFolder] = dc
922922
api.asyncWg.Add(1)
923923
go func() {
924-
_ = api.createDevcontainer(dc, configPath, true)
924+
_ = api.CreateDevcontainer(dc, configPath, CreateBehaviorRestart)
925925
}()
926926

927927
api.mu.Unlock()
@@ -932,16 +932,12 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
932932
})
933933
}
934934

935-
func (api *API) CreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer) error {
936-
api.mu.Lock()
937-
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStarting
938-
dc.Container = nil
939-
api.knownDevcontainers[dc.WorkspaceFolder] = dc
940-
api.asyncWg.Add(1)
941-
api.mu.Unlock()
935+
type CreateBehavior bool
942936

943-
return api.createDevcontainer(dc, dc.ConfigPath, false)
944-
}
937+
const (
938+
CreateBehaviorStart CreateBehavior = false
939+
CreateBehaviorRestart CreateBehavior = true
940+
)
945941

946942
// createDevcontainer should run in its own goroutine and is responsible for
947943
// recreating a devcontainer based on the provided devcontainer configuration.
@@ -950,9 +946,18 @@ func (api *API) CreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer) error
950946
// has a different config file than the one stored in the devcontainer state.
951947
// The devcontainer state must be set to starting and the asyncWg must be
952948
// incremented before calling this function.
953-
func (api *API) createDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, configPath string, restart bool) error {
949+
func (api *API) CreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, configPath string, behavior CreateBehavior) error {
954950
defer api.asyncWg.Done()
955951

952+
if behavior == CreateBehaviorStart {
953+
api.mu.Lock()
954+
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStarting
955+
dc.Container = nil
956+
api.knownDevcontainers[dc.WorkspaceFolder] = dc
957+
api.asyncWg.Add(1)
958+
api.mu.Unlock()
959+
}
960+
956961
var (
957962
err error
958963
ctx = api.ctx
@@ -993,7 +998,7 @@ func (api *API) createDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, confi
993998
logger.Debug(ctx, "starting devcontainer recreation")
994999

9951000
upOptions := []DevcontainerCLIUpOptions{WithUpOutput(infoW, errW)}
996-
if restart {
1001+
if behavior == CreateBehaviorRestart {
9971002
upOptions = append(upOptions, WithRemoveExistingContainer())
9981003
}
9991004

0 commit comments

Comments
 (0)