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 caller path trimming Windows-compatible #385

Merged
merged 1 commit into from
Mar 23, 2017

Conversation

moitias
Copy link
Contributor

@moitias moitias commented Mar 23, 2017

Go stdlib runtime.Caller() currently returns forward slashes on Windows (see golang/go#3335) which causes EntryCaller.TrimmedPath() to return full paths instead of the expected trimmed paths on Windows. This is because EntryCaller.TrimmedPath() uses os.PathSeparator to trim the path which is '' on Windows. According to the discussion on the Go bug, it seems like os.PathSeparator might be '' in some cases on Unix too so might cause issues on non-Windows platforms too.

This PR replaces the two occurrences of os.PathSeparator with ''/' as that is what runtime.Caller() currently produces on all platforms.

Did not add tests, as the existing tests for TrimmedPath() failed on Windows with master and work with this PR.

(TestOpen still fails on Windows but doesn't look like it's caused by this; Windows is returning errors in a different format than the test expects.)

make lint (ran from msys2 bash) fails (every single diff fails on every single line even though they look identical; maybe a newline issue?) but golint on entry.go is succesful.

Fixes: #382
See also: golang/go#18151

Before opening your pull request, please make sure that you've:

Thanks for your contribution!

Go stdlib runtime.Caller() currently returns forward slashes on Windows (see golang/go#3335) which causes EntryCaller.TrimmedPath() to return full paths instead of the expected trimmed paths on Windows. This is because EntryCaller.TrimmedPath() uses os.PathSeparator to trim the path which is '\' on Windows. According to the discussion on the Go bug, it seems like os.PathSeparator might be '' in some cases on Unix too so might cause issues on non-Windows platforms too.

This PR replaces the two occurrences of os.PathSeparator with ''/' as that is what runtime.Caller() currently produces on all platforms.

Fixes: uber-go#382
See also: golango/go#18151
@CLAassistant
Copy link

CLAassistant commented Mar 23, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

Looks great - thanks for the contribution!

@akshayjshah akshayjshah changed the title Use forward slashes for TrimmedPath() instead of os.PathSeparator Make caller path trimming Windows-compatible Mar 23, 2017
@akshayjshah akshayjshah merged commit 16dc29a into uber-go:master Mar 23, 2017
@moitias moitias deleted the trimmedpath-separator branch March 23, 2017 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants