Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit393f6e9

Browse files
committed
use a []byte instead of a string
1 parenta7d1ea4 commit393f6e9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

‎agent/agentcontainers/containers_dockercli.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,16 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
279279
// will still contain valid JSON. We will just end up missing
280280
// information about the removed container. We could potentially
281281
// log this error, but I'm not sure it's worth it.
282-
ins,dockerInspectStderr,err:=runDockerInspect(ctx,dcl.execer,ids...)
282+
dockerInspectStdout,dockerInspectStderr,err:=runDockerInspect(ctx,dcl.execer,ids...)
283283
iferr!=nil {
284284
return codersdk.WorkspaceAgentListContainersResponse{},xerrors.Errorf("run docker inspect: %w",err)
285285
}
286286

287-
ifdockerInspectStderr!="" {
288-
res.Warnings=append(res.Warnings,dockerInspectStderr)
287+
iflen(dockerInspectStderr)>0 {
288+
res.Warnings=append(res.Warnings,string(dockerInspectStderr))
289289
}
290290

291-
outs,warns,err:=convertDockerInspect(ins)
291+
outs,warns,err:=convertDockerInspect(dockerInspectStdout)
292292
iferr!=nil {
293293
return codersdk.WorkspaceAgentListContainersResponse{},xerrors.Errorf("convert docker inspect output: %w",err)
294294
}
@@ -301,19 +301,19 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
301301
// runDockerInspect is a helper function that runs `docker inspect` on the given
302302
// container IDs and returns the parsed output.
303303
// The stderr output is also returned for logging purposes.
304-
funcrunDockerInspect(ctx context.Context,execer agentexec.Execer,ids...string) (stdout,stderrstring,errerror) {
304+
funcrunDockerInspect(ctx context.Context,execer agentexec.Execer,ids...string) (stdout,stderr[]byte,errerror) {
305305
varstdoutBuf,stderrBuf bytes.Buffer
306306
cmd:=execer.CommandContext(ctx,"docker",append([]string{"inspect"},ids...)...)
307307
cmd.Stdout=&stdoutBuf
308308
cmd.Stderr=&stderrBuf
309309
err=cmd.Run()
310-
stdout=strings.TrimSpace(stdoutBuf.String())
311-
stderr=strings.TrimSpace(stderrBuf.String())
310+
stdout=bytes.TrimSpace(stdoutBuf.Bytes())
311+
stderr=bytes.TrimSpace(stderrBuf.Bytes())
312312
iferr!=nil {
313313
returnstdout,stderr,err
314314
}
315315

316-
returnstdoutBuf.String(),stderr,nil
316+
returnstdout,stderr,nil
317317
}
318318

319319
// To avoid a direct dependency on the Docker API, we use the docker CLI
@@ -371,10 +371,10 @@ func (dis dockerInspectState) String() string {
371371
returnsb.String()
372372
}
373373

374-
funcconvertDockerInspect(rawstring) ([]codersdk.WorkspaceAgentDevcontainer, []string,error) {
374+
funcconvertDockerInspect(raw[]byte) ([]codersdk.WorkspaceAgentDevcontainer, []string,error) {
375375
varwarns []string
376376
varins []dockerInspect
377-
iferr:=json.NewDecoder(strings.NewReader(raw)).Decode(&ins);err!=nil {
377+
iferr:=json.NewDecoder(bytes.NewReader(raw)).Decode(&ins);err!=nil {
378378
returnnil,nil,xerrors.Errorf("decode docker inspect output: %w",err)
379379
}
380380
outs:=make([]codersdk.WorkspaceAgentDevcontainer,0,len(ins))

‎agent/agentcontainers/containers_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func TestConvertDockerInspect(t *testing.T) {
607607
t.Parallel()
608608
bs,err:=os.ReadFile(filepath.Join("testdata",tt.name,"docker_inspect.json"))
609609
require.NoError(t,err,"failed to read testdata file")
610-
actual,warns,err:=convertDockerInspect(string(bs))
610+
actual,warns,err:=convertDockerInspect(bs)
611611
iflen(tt.expectWarns)>0 {
612612
assert.Len(t,warns,len(tt.expectWarns),"expected warnings")
613613
for_,warn:=rangett.expectWarns {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp