MCPcopy Create free account
hub / github.com/coder/envbuilder / handleSession

Function handleSession

testutil/gittest/gittest.go:174–228  ·  view source on GitHub ↗
(sess ssh.Session)

Source from the content-addressed store, hash-verified

172}
173
174func handleSession(sess ssh.Session) {
175 c := sess.Command()
176 if len(c) < 1 {
177 _, _ = fmt.Fprintf(os.Stderr, "invalid command: %q\n", c)
178 }
179
180 cmd := exec.Command(c[0], c[1:]...)
181 stdout, err := cmd.StdoutPipe()
182 if err != nil {
183 _, _ = fmt.Fprintf(os.Stderr, "cmd stdout pipe: %s\n", err.Error())
184 return
185 }
186
187 stdin, err := cmd.StdinPipe()
188 if err != nil {
189 _, _ = fmt.Fprintf(os.Stderr, "cmd stdin pipe: %s\n", err.Error())
190 return
191 }
192
193 stderr, err := cmd.StderrPipe()
194 if err != nil {
195 _, _ = fmt.Fprintf(os.Stderr, "cmd stderr pipe: %s\n", err.Error())
196 return
197 }
198
199 err = cmd.Start()
200 if err != nil {
201 _, _ = fmt.Fprintf(os.Stderr, "start cmd: %s\n", err.Error())
202 return
203 }
204
205 go func() {
206 defer stdin.Close()
207 _, _ = io.Copy(stdin, sess)
208 }()
209
210 var wg sync.WaitGroup
211 wg.Add(2)
212
213 go func() {
214 defer wg.Done()
215 _, _ = io.Copy(sess.Stderr(), stderr)
216 }()
217
218 go func() {
219 defer wg.Done()
220 _, _ = io.Copy(sess, stdout)
221 }()
222
223 wg.Wait()
224
225 if err := cmd.Wait(); err != nil {
226 _, _ = fmt.Fprintf(os.Stderr, "wait cmd: %s\n", err.Error())
227 }
228}
229
230// CommitFunc commits to a repo.
231type CommitFunc func(billy.Filesystem, *git.Repository)

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected