Skip to content

Commit

Permalink
Use explicit slash-dot for copy paths (#1781)
Browse files Browse the repository at this point in the history
Co-authored-by: igorpeshansky <[email protected]>
  • Loading branch information
jefferbrecht and igorpeshansky authored Aug 21, 2024
1 parent 7760f01 commit 3c3db61
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion integration_test/gce/gce_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ func getGcloudConfigDir(ctx context.Context) (string, error) {
return out.Stdout, nil
}

// getDirectoryWithTrailingDot returns the given directory with
// a trailing '/.'.
func getDirectoryWithTrailingDot(directory string) string {
// Can't just use filepath.Join(directory, "."), because it eats dot path
// segments. See https://stackoverflow.com/a/51670536.
return filepath.Clean(directory) + string(filepath.Separator) + "."
}

// SetupGcloudConfigDir sets up a new gcloud configuration directory.
// This copies the contents of the context-specified configuration directory
// into the new directory.
Expand All @@ -758,7 +766,9 @@ func SetupGcloudConfigDir(ctx context.Context, directory string) error {
return err
}
// TODO: Replace with os.CopyFS() once available.
if _, err := runCommand(ctx, log.New(io.Discard, "", 0), nil, []string{"cp", "-r", filepath.Join(currentConfigDir, "."), filepath.Join(directory, ".")}, nil); err != nil {
from := getDirectoryWithTrailingDot(currentConfigDir)
to := getDirectoryWithTrailingDot(directory)
if _, err := runCommand(ctx, log.New(io.Discard, "", 0), nil, []string{"cp", "-r", from, to}, nil); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 3c3db61

Please sign in to comment.