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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-16 14:48:39 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-17 11:41:05 +0300
commit593c23833d4798e0ef1b58ef406cd0077472e724 (patch)
tree91db9043f1c5b657bdc8566e9487a1dc57c24cf7
parent3418e8b495757e8e102fedf3d5a087cddc793f75 (diff)
command: Introduce options to configure spawned commands
We're about to extend construction of commands so that all members of the resulting structure will be set at construction time in order to fix racy access patterns. For this we will need to pass more parameters to `New()` so that it has all information available at construction time. Right now the function isn't all that extensive though given that it only accepts a fixed set of parameters. Refactor `New()` to instead accept a variable number of `Option`s. As a first step, convert all parameters currently passed to it to instead use these new options.
-rw-r--r--cmd/gitaly-lfs-smudge/main_test.go8
-rw-r--r--internal/cgroups/v1_linux_test.go8
-rw-r--r--internal/command/command.go31
-rw-r--r--internal/command/command_test.go34
-rw-r--r--internal/command/option.go44
-rw-r--r--internal/git/command_factory.go9
-rw-r--r--internal/git/objectpool/fetch.go2
-rw-r--r--internal/git/packfile/index.go2
-rw-r--r--internal/git2go/executor.go7
-rw-r--r--internal/gitaly/hook/custom.go7
-rw-r--r--internal/gitaly/linguist/linguist.go2
-rw-r--r--internal/gitaly/service/repository/archive.go4
-rw-r--r--internal/gitaly/service/repository/backup_custom_hooks.go2
-rw-r--r--internal/gitaly/service/repository/create_repository_from_snapshot.go2
-rw-r--r--internal/gitaly/service/repository/replicate.go4
-rw-r--r--internal/gitaly/service/repository/restore_custom_hooks.go4
-rw-r--r--internal/gitaly/service/repository/size.go2
17 files changed, 118 insertions, 54 deletions
diff --git a/cmd/gitaly-lfs-smudge/main_test.go b/cmd/gitaly-lfs-smudge/main_test.go
index 37814a34b..6154bcd25 100644
--- a/cmd/gitaly-lfs-smudge/main_test.go
+++ b/cmd/gitaly-lfs-smudge/main_test.go
@@ -184,10 +184,10 @@ func TestGitalyLFSSmudge(t *testing.T) {
var stdout, stderr bytes.Buffer
cmd, err := command.New(ctx,
exec.Command(binary),
- tc.stdin,
- &stdout,
- &stderr,
- env...,
+ command.WithStdin(tc.stdin),
+ command.WithStdout(&stdout),
+ command.WithStderr(&stderr),
+ command.WithEnvironment(env),
)
require.NoError(t, err)
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index 844b06225..73bb7df6c 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -81,7 +81,7 @@ func TestAddCommand(t *testing.T) {
ctx := testhelper.Context(t)
cmd1 := exec.Command("ls", "-hal", ".")
- cmd2, err := command.New(ctx, cmd1, nil, nil, nil)
+ cmd2, err := command.New(ctx, cmd1)
require.NoError(t, err)
require.NoError(t, cmd2.Wait())
@@ -173,11 +173,11 @@ func TestMetrics(t *testing.T) {
logger.SetLevel(logrus.DebugLevel)
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
- cmd, err := command.New(ctx, exec.Command("ls", "-hal", "."), nil, nil, nil)
+ cmd, err := command.New(ctx, exec.Command("ls", "-hal", "."))
require.NoError(t, err)
- gitCmd1, err := command.New(ctx, exec.Command("ls", "-hal", "."), nil, nil, nil)
+ gitCmd1, err := command.New(ctx, exec.Command("ls", "-hal", "."))
require.NoError(t, err)
- gitCmd2, err := command.New(ctx, exec.Command("ls", "-hal", "."), nil, nil, nil)
+ gitCmd2, err := command.New(ctx, exec.Command("ls", "-hal", "."))
require.NoError(t, err)
require.NoError(t, v1Manager1.AddCommand(cmd, repo))
diff --git a/internal/command/command.go b/internal/command/command.go
index 024bdd333..2ebd3d12f 100644
--- a/internal/command/command.go
+++ b/internal/command/command.go
@@ -147,13 +147,9 @@ type Command struct {
cgroupPath string
}
-// New creates a Command from an exec.Cmd. On success, the Command
-// contains a running subprocess. When ctx is canceled the embedded
-// process will be terminated and reaped automatically.
-//
-// If stdin is specified as SetupStdin, you will be able to write to the stdin
-// of the subprocess by calling Write() on the returned Command.
-func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.Writer, env ...string) (*Command, error) {
+// New creates a Command from an exec.Cmd. On success, the Command contains a running subprocess.
+// When ctx is canceled the embedded process will be terminated and reaped automatically.
+func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
if ctx.Done() == nil {
panic(contextWithoutDonePanic("command spawned with context without Done() channel"))
}
@@ -162,6 +158,11 @@ func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.
return nil, err
}
+ var cfg config
+ for _, opt := range opts {
+ opt(&cfg)
+ }
+
span, ctx := opentracing.StartSpanFromContext(
ctx,
cmd.Path,
@@ -200,7 +201,7 @@ func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.
// Export allowed environment variables as set in the Gitaly process.
cmd.Env = AllowedEnvironment(os.Environ())
// Append environment variables explicitly requested by the caller.
- cmd.Env = append(cmd.Env, env...)
+ cmd.Env = append(cmd.Env, cfg.environment...)
// And finally inject environment variables required for tracing into the command.
cmd.Env = envInjector(ctx, cmd.Env)
@@ -211,20 +212,20 @@ func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.
// * nil - Go implicitly uses /dev/null
// * SetupStdin - configure with cmd.StdinPipe(), allowing Write() to work
// * Another io.Reader - becomes cmd.Stdin. Write() will not work
- if stdin == SetupStdin {
+ if cfg.stdin == SetupStdin {
pipe, err := cmd.StdinPipe()
if err != nil {
return nil, fmt.Errorf("GitCommand: stdin: %v", err)
}
command.writer = pipe
- } else if stdin != nil {
- cmd.Stdin = stdin
+ } else if cfg.stdin != nil {
+ cmd.Stdin = cfg.stdin
}
- if stdout != nil {
+ if cfg.stdout != nil {
// We don't assign a reader if an stdout override was passed. We assume
// output is going to be directly handled by the caller.
- cmd.Stdout = stdout
+ cmd.Stdout = cfg.stdout
} else {
pipe, err := cmd.StdoutPipe()
if err != nil {
@@ -233,8 +234,8 @@ func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.
command.reader = pipe
}
- if stderr != nil {
- cmd.Stderr = stderr
+ if cfg.stderr != nil {
+ cmd.Stderr = cfg.stderr
} else {
command.stderrBuffer, err = newStderrBuffer(maxStderrBytes, maxStderrLineLength, []byte("\n"))
if err != nil {
diff --git a/internal/command/command_test.go b/internal/command/command_test.go
index 0c48a18f9..7bf69ba9c 100644
--- a/internal/command/command_test.go
+++ b/internal/command/command_test.go
@@ -30,7 +30,7 @@ func TestNew_environment(t *testing.T) {
extraVar := "FOOBAR=123456"
var buf bytes.Buffer
- cmd, err := New(ctx, exec.Command("/usr/bin/env"), nil, &buf, nil, extraVar)
+ cmd, err := New(ctx, exec.Command("/usr/bin/env"), WithStdout(&buf), WithEnvironment([]string{extraVar}))
require.NoError(t, err)
require.NoError(t, cmd.Wait())
@@ -118,7 +118,7 @@ func TestNew_exportedEnvironment(t *testing.T) {
testhelper.ModifyEnvironment(t, tc.key, tc.value)
var buf bytes.Buffer
- cmd, err := New(ctx, exec.Command("/usr/bin/env"), nil, &buf, nil)
+ cmd, err := New(ctx, exec.Command("/usr/bin/env"), WithStdout(&buf))
require.NoError(t, err)
require.NoError(t, cmd.Wait())
@@ -135,7 +135,7 @@ func TestNew_unexportedEnv(t *testing.T) {
testhelper.ModifyEnvironment(t, unexportedEnvKey, unexportedEnvVal)
var buf bytes.Buffer
- cmd, err := New(ctx, exec.Command("/usr/bin/env"), nil, &buf, nil)
+ cmd, err := New(ctx, exec.Command("/usr/bin/env"), WithStdout(&buf))
require.NoError(t, err)
require.NoError(t, cmd.Wait())
@@ -146,7 +146,7 @@ func TestNew_rejectContextWithoutDone(t *testing.T) {
t.Parallel()
require.PanicsWithValue(t, contextWithoutDonePanic("command spawned with context without Done() channel"), func() {
- _, err := New(testhelper.ContextWithoutCancel(), exec.Command("true"), nil, nil, nil)
+ _, err := New(testhelper.ContextWithoutCancel(), exec.Command("true"))
require.NoError(t, err)
})
}
@@ -169,7 +169,7 @@ func TestNew_spawnTimeout(t *testing.T) {
errCh := make(chan error)
go func() {
- _, err := New(ctx, exec.Command("true"), nil, nil, nil)
+ _, err := New(ctx, exec.Command("true"))
errCh <- err
}()
@@ -191,7 +191,7 @@ func TestCommand_Wait_contextCancellationKillsCommand(t *testing.T) {
ctx, cancel := context.WithCancel(testhelper.Context(t))
- cmd, err := New(ctx, exec.CommandContext(ctx, "sleep", "1h"), nil, nil, nil)
+ cmd, err := New(ctx, exec.CommandContext(ctx, "sleep", "1h"))
require.NoError(t, err)
// Cancel the command early.
@@ -212,7 +212,7 @@ func TestNew_setupStdin(t *testing.T) {
stdin := "Test value"
var buf bytes.Buffer
- cmd, err := New(ctx, exec.Command("cat"), SetupStdin, &buf, nil)
+ cmd, err := New(ctx, exec.Command("cat"), WithStdin(SetupStdin), WithStdout(&buf))
require.NoError(t, err)
_, err = fmt.Fprintf(cmd, "%s", stdin)
@@ -227,7 +227,7 @@ func TestCommand_read(t *testing.T) {
ctx := testhelper.Context(t)
- cmd, err := New(ctx, exec.Command("echo", "test value"), nil, nil, nil)
+ cmd, err := New(ctx, exec.Command("echo", "test value"))
require.NoError(t, err)
output, err := io.ReadAll(cmd)
@@ -242,7 +242,7 @@ func TestNew_nulByteInArgument(t *testing.T) {
ctx := testhelper.Context(t)
- cmd, err := New(ctx, exec.Command("sh", "-c", "hello\x00world"), nil, nil, nil)
+ cmd, err := New(ctx, exec.Command("sh", "-c", "hello\x00world"))
require.Equal(t, fmt.Errorf("detected null byte in command argument %q", "hello\x00world"), err)
require.Nil(t, cmd)
}
@@ -252,7 +252,7 @@ func TestNew_missingBinary(t *testing.T) {
ctx := testhelper.Context(t)
- cmd, err := New(ctx, exec.Command("command-non-existent"), nil, nil, nil)
+ cmd, err := New(ctx, exec.Command("command-non-existent"))
require.Equal(t, fmt.Errorf("GitCommand: start [command-non-existent]: exec: \"command-non-existent\": executable file not found in $PATH"), err)
require.Nil(t, cmd)
}
@@ -273,7 +273,7 @@ func TestCommand_stderrLogging(t *testing.T) {
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
var stdout bytes.Buffer
- cmd, err := New(ctx, exec.Command(binaryPath), nil, &stdout, nil)
+ cmd, err := New(ctx, exec.Command(binaryPath), WithStdout(&stdout))
require.NoError(t, err)
require.EqualError(t, cmd.Wait(), "exit status 1")
@@ -297,7 +297,7 @@ func TestCommand_stderrLoggingTruncation(t *testing.T) {
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
var stdout bytes.Buffer
- cmd, err := New(ctx, exec.Command(binaryPath), nil, &stdout, nil)
+ cmd, err := New(ctx, exec.Command(binaryPath), WithStdout(&stdout))
require.NoError(t, err)
require.Error(t, cmd.Wait())
@@ -318,7 +318,7 @@ func TestCommand_stderrLoggingWithNulBytes(t *testing.T) {
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
var stdout bytes.Buffer
- cmd, err := New(ctx, exec.Command(binaryPath), nil, &stdout, nil)
+ cmd, err := New(ctx, exec.Command(binaryPath), WithStdout(&stdout))
require.NoError(t, err)
require.Error(t, cmd.Wait())
@@ -341,7 +341,7 @@ func TestCommand_stderrLoggingLongLine(t *testing.T) {
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
var stdout bytes.Buffer
- cmd, err := New(ctx, exec.Command(binaryPath), nil, &stdout, nil)
+ cmd, err := New(ctx, exec.Command(binaryPath), WithStdout(&stdout))
require.NoError(t, err)
require.Error(t, cmd.Wait())
@@ -388,7 +388,7 @@ func TestCommand_stderrLoggingMaxBytes(t *testing.T) {
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
var stdout bytes.Buffer
- cmd, err := New(ctx, exec.Command(binaryPath), nil, &stdout, nil)
+ cmd, err := New(ctx, exec.Command(binaryPath), WithStdout(&stdout))
require.NoError(t, err)
require.Error(t, cmd.Wait())
@@ -404,7 +404,7 @@ func TestCommand_logMessage(t *testing.T) {
ctx := ctxlogrus.ToContext(testhelper.Context(t), logrus.NewEntry(logger))
- cmd, err := New(ctx, exec.Command("echo", "hello world"), nil, nil, nil)
+ cmd, err := New(ctx, exec.Command("echo", "hello world"))
require.NoError(t, err)
cgroupPath := "/sys/fs/cgroup/1"
cmd.SetCgroupPath(cgroupPath)
@@ -434,7 +434,7 @@ func TestNew_commandSpawnTokenMetrics(t *testing.T) {
tags.Set("grpc.request.fullMethod", "/test.Service/TestRPC")
ctx = grpcmwtags.SetInContext(ctx, tags)
- cmd, err := New(ctx, exec.Command("echo", "goodbye, cruel world."), nil, nil, nil)
+ cmd, err := New(ctx, exec.Command("echo", "goodbye, cruel world."))
require.NoError(t, err)
require.NoError(t, cmd.Wait())
diff --git a/internal/command/option.go b/internal/command/option.go
new file mode 100644
index 000000000..f31602254
--- /dev/null
+++ b/internal/command/option.go
@@ -0,0 +1,44 @@
+package command
+
+import "io"
+
+type config struct {
+ stdin io.Reader
+ stdout io.Writer
+ stderr io.Writer
+ environment []string
+}
+
+// Option is an option that can be passed to `New()` for controlling how the command is being
+// created.
+type Option func(cfg *config)
+
+// WithStdin sets up the command to read from the given reader. If stdin is specified as SetupStdin,
+// you will be able to write to the stdin of the subprocess by calling Write() on the returned
+// Command.
+func WithStdin(stdin io.Reader) Option {
+ return func(cfg *config) {
+ cfg.stdin = stdin
+ }
+}
+
+// WithStdout sets up the command to write standard output to the given writer.
+func WithStdout(stdout io.Writer) Option {
+ return func(cfg *config) {
+ cfg.stdout = stdout
+ }
+}
+
+// WithStderr sets up the command to write standard error to the given writer.
+func WithStderr(stderr io.Writer) Option {
+ return func(cfg *config) {
+ cfg.stderr = stderr
+ }
+}
+
+// WithEnvironment sets up environment variables that shall be set for the command.
+func WithEnvironment(environment []string) Option {
+ return func(cfg *config) {
+ cfg.environment = environment
+ }
+}
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index 2f2ded567..0e222c677 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -341,7 +341,7 @@ func (cf *ExecCommandFactory) GitVersion(ctx context.Context) (Version, error) {
// Furthermore, note that we're not using `newCommand()` but instead hand-craft the command.
// This is required to avoid a cyclic dependency when we need to check the version in
// `newCommand()` itself.
- cmd, err := command.New(ctx, exec.Command(execEnv.BinaryPath, "version"), nil, nil, nil, execEnv.EnvironmentVariables...)
+ cmd, err := command.New(ctx, exec.Command(execEnv.BinaryPath, "version"), command.WithEnvironment(execEnv.EnvironmentVariables))
if err != nil {
return Version{}, fmt.Errorf("spawning version command: %w", err)
}
@@ -397,7 +397,12 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
execCommand := exec.Command(execEnv.BinaryPath, args...)
execCommand.Dir = dir
- command, err := command.New(ctx, execCommand, config.stdin, config.stdout, config.stderr, env...)
+ command, err := command.New(ctx, execCommand,
+ command.WithStdin(config.stdin),
+ command.WithStdout(config.stdout),
+ command.WithStderr(config.stderr),
+ command.WithEnvironment(env),
+ )
if err != nil {
return nil, err
}
diff --git a/internal/git/objectpool/fetch.go b/internal/git/objectpool/fetch.go
index 6aedcc7e5..549522809 100644
--- a/internal/git/objectpool/fetch.go
+++ b/internal/git/objectpool/fetch.go
@@ -226,7 +226,7 @@ func (o *ObjectPool) logStats(ctx context.Context, when string) error {
func sizeDir(ctx context.Context, dir string) (int64, error) {
// du -k reports size in KB
- cmd, err := command.New(ctx, exec.Command("du", "-sk", dir), nil, nil, nil)
+ cmd, err := command.New(ctx, exec.Command("du", "-sk", dir))
if err != nil {
return 0, err
}
diff --git a/internal/git/packfile/index.go b/internal/git/packfile/index.go
index 2aa7f4be7..e8915e1d3 100644
--- a/internal/git/packfile/index.go
+++ b/internal/git/packfile/index.go
@@ -93,7 +93,7 @@ func ReadIndex(idxPath string) (*Index, error) {
return nil, err
}
- showIndex, err := command.New(ctx, exec.Command("git", "show-index"), f, nil, nil)
+ showIndex, err := command.New(ctx, exec.Command("git", "show-index"), command.WithStdin(f))
if err != nil {
return nil, err
}
diff --git a/internal/git2go/executor.go b/internal/git2go/executor.go
index 75d451fe0..d5319304f 100644
--- a/internal/git2go/executor.go
+++ b/internal/git2go/executor.go
@@ -88,7 +88,12 @@ func (b *Executor) run(ctx context.Context, repo repository.GitRepo, stdin io.Re
}, args...)
var stdout bytes.Buffer
- cmd, err := command.New(ctx, exec.Command(b.binaryPath, args...), stdin, &stdout, log, env...)
+ cmd, err := command.New(ctx, exec.Command(b.binaryPath, args...),
+ command.WithStdin(stdin),
+ command.WithStdout(&stdout),
+ command.WithStderr(log),
+ command.WithEnvironment(env),
+ )
if err != nil {
return nil, err
}
diff --git a/internal/gitaly/hook/custom.go b/internal/gitaly/hook/custom.go
index 327e014de..490409773 100644
--- a/internal/gitaly/hook/custom.go
+++ b/internal/gitaly/hook/custom.go
@@ -68,7 +68,12 @@ func (m *GitLabHookManager) newCustomHooksExecutor(repo *gitalypb.Repository, ho
for _, hookFile := range hookFiles {
cmd := exec.Command(hookFile, args...)
cmd.Dir = repoPath
- c, err := command.New(ctx, cmd, bytes.NewReader(stdinBytes), stdout, stderr, env...)
+ c, err := command.New(ctx, cmd,
+ command.WithStdin(bytes.NewReader(stdinBytes)),
+ command.WithStdout(stdout),
+ command.WithStderr(stderr),
+ command.WithEnvironment(env),
+ )
if err != nil {
return err
}
diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go
index 4ac9abfd2..4bc9dbce1 100644
--- a/internal/gitaly/linguist/linguist.go
+++ b/internal/gitaly/linguist/linguist.go
@@ -95,7 +95,7 @@ func (inst *Instance) startGitLinguist(ctx context.Context, repoPath string, com
cmd := exec.Command(bundle, "exec", "bin/gitaly-linguist", "--repository="+repoPath, "--commit="+commitID)
cmd.Dir = inst.cfg.Ruby.Dir
- internalCmd, err := command.New(ctx, cmd, nil, nil, nil, env.AllowedRubyEnvironment(os.Environ())...)
+ internalCmd, err := command.New(ctx, cmd, command.WithEnvironment(env.AllowedRubyEnvironment(os.Environ())))
if err != nil {
return nil, fmt.Errorf("creating command: %w", err)
}
diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go
index fd2497ac2..a657c9428 100644
--- a/internal/gitaly/service/repository/archive.go
+++ b/internal/gitaly/service/repository/archive.go
@@ -235,7 +235,9 @@ func (s *server) handleArchive(ctx context.Context, p archiveParams) error {
}
if p.compressCmd != nil {
- command, err := command.New(ctx, p.compressCmd, archiveCommand, p.writer, nil)
+ command, err := command.New(ctx, p.compressCmd,
+ command.WithStdin(archiveCommand), command.WithStdout(p.writer),
+ )
if err != nil {
return err
}
diff --git a/internal/gitaly/service/repository/backup_custom_hooks.go b/internal/gitaly/service/repository/backup_custom_hooks.go
index da774f89b..e434e6f65 100644
--- a/internal/gitaly/service/repository/backup_custom_hooks.go
+++ b/internal/gitaly/service/repository/backup_custom_hooks.go
@@ -30,7 +30,7 @@ func (s *server) BackupCustomHooks(in *gitalypb.BackupCustomHooksRequest, stream
ctx := stream.Context()
tar := exec.Command("tar", "-c", "-f", "-", "-C", repoPath, customHooksDir)
- cmd, err := command.New(ctx, tar, nil, writer, nil)
+ cmd, err := command.New(ctx, tar, command.WithStdout(writer))
if err != nil {
return status.Errorf(codes.Internal, "%v", err)
}
diff --git a/internal/gitaly/service/repository/create_repository_from_snapshot.go b/internal/gitaly/service/repository/create_repository_from_snapshot.go
index 021bb2cec..f665faa87 100644
--- a/internal/gitaly/service/repository/create_repository_from_snapshot.go
+++ b/internal/gitaly/service/repository/create_repository_from_snapshot.go
@@ -67,7 +67,7 @@ func untar(ctx context.Context, path string, in *gitalypb.CreateRepositoryFromSn
return status.Errorf(codes.Internal, "HTTP server: %v", rsp.Status)
}
- cmd, err := command.New(ctx, exec.Command("tar", "-C", path, "-xvf", "-"), rsp.Body, nil, nil)
+ cmd, err := command.New(ctx, exec.Command("tar", "-C", path, "-xvf", "-"), command.WithStdin(rsp.Body))
if err != nil {
return err
}
diff --git a/internal/gitaly/service/repository/replicate.go b/internal/gitaly/service/repository/replicate.go
index 851ba8b4c..6c66bcd74 100644
--- a/internal/gitaly/service/repository/replicate.go
+++ b/internal/gitaly/service/repository/replicate.go
@@ -188,7 +188,9 @@ func (s *server) extractSnapshot(ctx context.Context, source, target *gitalypb.R
}
stderr := &bytes.Buffer{}
- cmd, err := command.New(ctx, exec.Command("tar", "-C", targetPath, "-xvf", "-"), snapshotReader, nil, stderr)
+ cmd, err := command.New(ctx, exec.Command("tar", "-C", targetPath, "-xvf", "-"),
+ command.WithStdin(snapshotReader), command.WithStderr(stderr),
+ )
if err != nil {
return fmt.Errorf("create tar command: %w", err)
}
diff --git a/internal/gitaly/service/repository/restore_custom_hooks.go b/internal/gitaly/service/repository/restore_custom_hooks.go
index 54d73ddc0..572181ffe 100644
--- a/internal/gitaly/service/repository/restore_custom_hooks.go
+++ b/internal/gitaly/service/repository/restore_custom_hooks.go
@@ -62,7 +62,7 @@ func (s *server) RestoreCustomHooks(stream gitalypb.RepositoryService_RestoreCus
}
ctx := stream.Context()
- cmd, err := command.New(ctx, exec.Command("tar", cmdArgs...), reader, nil, nil)
+ cmd, err := command.New(ctx, exec.Command("tar", cmdArgs...), command.WithStdin(reader))
if err != nil {
return status.Errorf(codes.Internal, "RestoreCustomHooks: Could not untar custom hooks tar %v", err)
}
@@ -149,7 +149,7 @@ func (s *server) restoreCustomHooksWithVoting(stream gitalypb.RepositoryService_
customHooksDir,
}
- cmd, err := command.New(ctx, exec.Command("tar", cmdArgs...), reader, nil, nil)
+ cmd, err := command.New(ctx, exec.Command("tar", cmdArgs...), command.WithStdin(reader))
if err != nil {
return helper.ErrInternalf("RestoreCustomHooks: Could not untar custom hooks tar %w", err)
}
diff --git a/internal/gitaly/service/repository/size.go b/internal/gitaly/service/repository/size.go
index d8476274a..95bf22402 100644
--- a/internal/gitaly/service/repository/size.go
+++ b/internal/gitaly/service/repository/size.go
@@ -67,7 +67,7 @@ func (s *server) GetObjectDirectorySize(ctx context.Context, in *gitalypb.GetObj
}
func getPathSize(ctx context.Context, path string) int64 {
- cmd, err := command.New(ctx, exec.Command("du", "-sk", path), nil, nil, nil)
+ cmd, err := command.New(ctx, exec.Command("du", "-sk", path))
if err != nil {
ctxlogrus.Extract(ctx).WithError(err).Warn("ignoring du command error")
return 0