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

Port a bug fix for GetPathRelativeTo over from Terragrunt #76

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions files/paths.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package files

import (
"io/ioutil"
"path/filepath"
"regexp"
"io/ioutil"
"github.com/gruntwork-io/go-commons/errors"

"github.com/mattn/go-zglob"

"github.com/gruntwork-io/go-commons/errors"
)

// Return the canonical version of the given path, relative to the given base path. That is, if the given path is a
Expand Down Expand Up @@ -68,6 +70,13 @@ func Grep(regex *regexp.Regexp, glob string) (bool, error) {

// Return the relative path you would have to take to get from basePath to path
func GetPathRelativeTo(path string, basePath string) (string, error) {
if path == "" {
marinalimeira marked this conversation as resolved.
Show resolved Hide resolved
path = "."
}
if basePath == "" {
basePath = "."
}

inputFolderAbs, err := filepath.Abs(basePath)
if err != nil {
return "", errors.WithStackTrace(err)
Expand All @@ -83,6 +92,5 @@ func GetPathRelativeTo(path string, basePath string) (string, error) {
return "", errors.WithStackTrace(err)
}

return relPath, nil
return filepath.ToSlash(relPath), nil
}