From 1cbb9ce16cf8e71eb04f66ba00e9c09086f81949 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 17 Jul 2025 17:28:09 +0200 Subject: [PATCH] Change execv to use current directory as a working directory if no directory is provided --- libs/exec/execv.go | 4 +++- libs/exec/execv_unix.go | 8 +++++--- libs/lakebase/connect.go | 7 ------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/libs/exec/execv.go b/libs/exec/execv.go index 3b9b208b146..859b473ece7 100644 --- a/libs/exec/execv.go +++ b/libs/exec/execv.go @@ -10,7 +10,9 @@ type ExecvOptions struct { // Env is set the environment variables to set in the child process. Env []string - // Dir is the working directory of the child process. + // Dir specifies the working directory of the command. + // If Dir is an empty string, Execv runs the command in the + // calling process's current directory. Dir string // It is not possible to execute a cmd.exe script inlined as a argument diff --git a/libs/exec/execv_unix.go b/libs/exec/execv_unix.go index e81e51d07d0..0ead67022bd 100644 --- a/libs/exec/execv_unix.go +++ b/libs/exec/execv_unix.go @@ -10,9 +10,11 @@ import ( ) func execv(opts ExecvOptions) error { - err := os.Chdir(opts.Dir) - if err != nil { - return fmt.Errorf("changing directory to %s failed: %w", opts.Dir, err) + if opts.Dir != "" { + err := os.Chdir(opts.Dir) + if err != nil { + return fmt.Errorf("changing directory to %s failed: %w", opts.Dir, err) + } } // execve syscall does not perform PATH lookup. Thus we need to query path diff --git a/libs/lakebase/connect.go b/libs/lakebase/connect.go index 1afacfcea4a..8f5536a2dc9 100644 --- a/libs/lakebase/connect.go +++ b/libs/lakebase/connect.go @@ -53,12 +53,6 @@ func Connect(ctx context.Context, databaseInstanceName string, extraArgs ...stri } cmdio.LogString(ctx, "Successfully fetched database credentials") - // Get current working directory - dir, err := os.Getwd() - if err != nil { - return fmt.Errorf("error getting working directory: %w", err) - } - // Check if database name and port are already specified in extra arguments hasDbName := false hasPort := false @@ -103,6 +97,5 @@ func Connect(ctx context.Context, databaseInstanceName string, extraArgs ...stri return exec.Execv(exec.ExecvOptions{ Args: args, Env: cmdEnv, - Dir: dir, }) }