Skip to content

Commit a338fdb

Browse files
authored
Change execv to use current directory as a working directory if no directory is provided (#3267)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> This is a follow-up for the comment in the previous PR #3128 : #3128 (comment) ## Tests <!-- How have you tested the changes? --> - Existing acceptance test on cmd/psql is still passing even though the production code is not specifying a directory - Manually checked that when executed with `pwd` the process prints current working directory on Mac and on Windows <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent ec51221 commit a338fdb

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

libs/exec/execv.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type ExecvOptions struct {
1010
// Env is set the environment variables to set in the child process.
1111
Env []string
1212

13-
// Dir is the working directory of the child process.
13+
// Dir specifies the working directory of the command.
14+
// If Dir is an empty string, Execv runs the command in the
15+
// calling process's current directory.
1416
Dir string
1517

1618
// It is not possible to execute a cmd.exe script inlined as a argument

libs/exec/execv_unix.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
)
1111

1212
func execv(opts ExecvOptions) error {
13-
err := os.Chdir(opts.Dir)
14-
if err != nil {
15-
return fmt.Errorf("changing directory to %s failed: %w", opts.Dir, err)
13+
if opts.Dir != "" {
14+
err := os.Chdir(opts.Dir)
15+
if err != nil {
16+
return fmt.Errorf("changing directory to %s failed: %w", opts.Dir, err)
17+
}
1618
}
1719

1820
// execve syscall does not perform PATH lookup. Thus we need to query path

libs/lakebase/connect.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ func Connect(ctx context.Context, databaseInstanceName string, extraArgs ...stri
5353
}
5454
cmdio.LogString(ctx, "Successfully fetched database credentials")
5555

56-
// Get current working directory
57-
dir, err := os.Getwd()
58-
if err != nil {
59-
return fmt.Errorf("error getting working directory: %w", err)
60-
}
61-
6256
// Check if database name and port are already specified in extra arguments
6357
hasDbName := false
6458
hasPort := false
@@ -103,6 +97,5 @@ func Connect(ctx context.Context, databaseInstanceName string, extraArgs ...stri
10397
return exec.Execv(exec.ExecvOptions{
10498
Args: args,
10599
Env: cmdEnv,
106-
Dir: dir,
107100
})
108101
}

0 commit comments

Comments
 (0)