Welcome to mirror list, hosted at ThFree Co, Russian Federation.

monitor_stdin_command.go « ssh « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e04bbdb197d79e1d560e72d4e01f2cad04ad770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package ssh

import (
	"context"
	"fmt"
	"io"

	"gitlab.com/gitlab-org/gitaly/v15/internal/command"
	"gitlab.com/gitlab-org/gitaly/v15/internal/git"
	"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
	"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)

func monitorStdinCommand(
	ctx context.Context,
	gitCmdFactory git.CommandFactory,
	repo *gitalypb.Repository,
	stdin io.Reader,
	stdout, stderr io.Writer,
	sc git.Command,
	opts ...git.CmdOpt,
) (*command.Command, *pktline.ReadMonitor, error) {
	stdinPipe, monitor, cleanup, err := pktline.NewReadMonitor(ctx, stdin)
	if err != nil {
		return nil, nil, fmt.Errorf("create monitor: %w", err)
	}

	cmd, err := gitCmdFactory.New(ctx, repo, sc, append([]git.CmdOpt{
		git.WithStdin(stdinPipe),
		git.WithStdout(stdout),
		git.WithStderr(stderr),
		git.WithFinalizer(func(*command.Command) { cleanup() }),
	}, opts...)...)
	stdinPipe.Close() // this now belongs to cmd
	if err != nil {
		cleanup()
		return nil, nil, fmt.Errorf("start cmd: %w", err)
	}

	return cmd, monitor, err
}