Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all paths supplied by flags absolute #35

Merged
merged 3 commits into from
Dec 12, 2024
Merged

Conversation

SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Dec 11, 2024

Closes #34

This PR makes the --goldens and --tests flag values be converted to absolute paths before they're used. This avoids the problem described in the linked issue.

I also changed how the path to the Terraform binary is made absolute, so that it's consistent. The function filepath.Abs is implemented pretty much the same way as the code that's being replaced:

// src/path/filepath/path.go
func Abs(path string) (string, error) {
	return abs(path)
}

// src/path/filepath/path_unix.go
func abs(path string) (string, error) {
	return unixAbs(path)
}

// src/path/filepath/path.go
func unixAbs(path string) (string, error) {
	if IsAbs(path) {
		return Clean(path), nil
	}
	wd, err := os.Getwd()
	if err != nil {
		return "", err
	}
	return Join(wd, path), nil
}

I'm unsure of any pitfalls around converting paths to absolute paths, which is the main thing I'd like to address during review. E.g. usage on non-unix machines?

@SarahFrench SarahFrench marked this pull request as ready for review December 12, 2024 11:48
@SarahFrench SarahFrench requested a review from a team as a code owner December 12, 2024 11:48
Copy link
Member

@liamcervante liamcervante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think filepath is actually architecture specific anyway, so this should work across windows/linux/mac/etc.

@liamcervante liamcervante merged commit 0c4ec7d into main Dec 12, 2024
4 checks passed
@liamcervante liamcervante deleted the make-all-paths-abs branch December 12, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update command fails to copy new goldens to target directory from tmp directory when using relative paths
2 participants