-
-
Notifications
You must be signed in to change notification settings - Fork 971
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
Fix relative path issues on Windows #96
Changes from 2 commits
e04746b
a54fda6
4ebead5
1f893e9
2114b9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// +build !windows | ||
|
||
package config | ||
|
||
var rootFolder = "/root" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// +build windows | ||
|
||
package config | ||
|
||
var rootFolder = "C:/root" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"github.com/gruntwork-io/terragrunt/errors" | ||
"io/ioutil" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// Return true if the given file exists | ||
|
@@ -83,6 +84,7 @@ func GetPathRelativeTo(path string, basePath string) (string, error) { | |
return "", errors.WithStackTrace(err) | ||
} | ||
|
||
relPath = strings.Replace(relPath, `\`,"/", -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I'm not sure this is the right place for the fix, nor quite the right fix. The bug, as explained here, is caused by the fact that Windows uses backslashes in its paths, but backslashes mean "escape" in HCL. So the fix is not to replace backslashes, but to escape them properly so they work in HCL. Therefore, I think the proper fix is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the problem this causes is that all the tests are using hard coded strings with / as the path separator. So this is going to require either some sort of a per platform mapping for test values (seems excessive), or a conversion from \ to / for the purposes of the test anyway (seems less than ideal). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, pathRelativeToInclude can actually call findInParentFolders indirectly through ResolveTerragruntConfigString. So simple escaping is actually double escaping in many scenarios. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be possible to add a helper to func cleanPath(path string) string {
return strings.Replace(path, "\\", "/", -1)
} And in func cleanPath(path string) string {
return strings.Replace(path, "/", "\\", -1)
} (Perhaps a better name would be You can then wrap all the paths in the tests with a call to |
||
return relPath, nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several other uses of
/root
in this file. Would you mind updating them the same way? That will help prevent these sorts of bugs in the future.