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
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit6b0a0d3

Browse files
committed
AcivityWriter
1 parent174c866 commit6b0a0d3

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

‎cmd/coder/shell.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
144144
stdin:=process.Stdin()
145145
deferstdin.Close()
146146

147-
ap:=&activity.Pusher{Source:"ssh",EnvID:env.ID,Client:entClient}
147+
ap:=&activity.Pusher{Source:sshActivityName,EnvID:env.ID,Client:entClient}
148148
deferap.Start()()
149149

150-
activity.Copy(ap,stdin,os.Stdin)
150+
wr:=activity.Writer(ap,stdin)
151+
io.Copy(wr,os.Stdin)
151152
}()
152153
goio.Copy(os.Stdout,process.Stdout())
153154
goio.Copy(os.Stderr,process.Stderr())
154155

155156
returnprocess.Wait()
156157
}
158+
159+
constsshActivityName="ssh"

‎internal/activity/copy.go

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,16 @@ package activity
22

33
import"io"
44

5-
// Copy copyes src to dst, pushing activity when bytes are read from src.
6-
funcCopy(p*Pusher,dst io.Writer,src io.Reader) (writtenint64,errerror) {
7-
buf:=make([]byte,32*1024)
8-
9-
for {
10-
nr,er:=src.Read(buf)
11-
ifnr>0 {
12-
p.Push()
5+
typeactivityWriterstruct {
6+
p*Pusher
7+
wr io.Writer
8+
}
139

14-
nw,ew:=dst.Write(buf[0:nr])
15-
ifnw>0 {
16-
written+=int64(nw)
17-
}
18-
ifew!=nil {
19-
err=ew
20-
break
21-
}
22-
ifnr!=nw {
23-
err=io.ErrShortWrite
24-
break
25-
}
26-
}
27-
ifer!=nil {
28-
ifer!=io.EOF {
29-
err=er
30-
}
31-
break
32-
}
33-
}
10+
func (w*activityWriter)Write(p []byte) (nint,errerror) {
11+
w.p.Push()
12+
returnw.wr.Write(p)
13+
}
3414

35-
returnwritten,err
15+
funcWriter(p*Pusher,wr io.Writer) io.Writer {
16+
return&activityWriter{p:p,wr:wr}
3617
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp