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, }) }