Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Fixes #675. Changes to HasFilepathPrefix to handle Windows better. #704

Merged
merged 2 commits into from
Jun 4, 2017

Conversation

mikijov
Copy link
Contributor

@mikijov mikijov commented Jun 1, 2017

Fixes #675. Old logic lost the drive letter hence subsequent comparisons
were often wrong. New code adds logic to handle volume name
separately. Test changed to always have mismatching case on
windows.

Old logic lost the drive letter hence subsequent comparisons
were often wrong. New code adds logic to handle volume name
separately. Test changed to always have mismatching case on
windows.
@@ -53,7 +63,8 @@ func HasFilepathPrefix(path, prefix string) bool {
return false
}

var d, p string
d := vnPath
Copy link
Member

Choose a reason for hiding this comment

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

Given that we know that Windows will always treat volume name as case insensitive, this seems unnecessary - why isn't it sufficient to just test the strings.ToLower() volume names, as you do above?

Copy link
Contributor Author

@mikijov mikijov Jun 2, 2017

Choose a reason for hiding this comment

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

It's a combination of many small things. strings.Split later on splits the path. On Windows dirs[0] is the drive letter, on Linux it's empty string. Because of that whoever wrote the function ignored the first element by slicing dirs = (...)[1:] it away. On *nix this is perfect. But on Windows loss of the first element meant that isCaseSensitive later on does not have the full path, i.e. C:\Windows becomes only Windows, and isCaseSensitive becomes unpredictable. I honestly do not know how did the tests previously work. In any case, I had to change the code to remember the volume name and initialize d and p with it. One more thing here. filepath.Join("c:", "Windows") returns "c:Windows". So I had to check if volume name is a drive letter (ending with ':') and only in that situation append \.

Sorry the explanation is so convoluted, but it's small idiosyncrasies that caused this not to be so trivial.

@@ -21,25 +22,35 @@ func TestHasFilepathPrefix(t *testing.T) {
}
defer os.RemoveAll(dir)

// dir2 is the same as dir but with different capitalization on Windows to
// test case insensitivity
Copy link
Member

Choose a reason for hiding this comment

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

As noted in the issue discussion, with the exception of the volume name (i guess?), case insensitivity isn't a windows property, but actually a filesystem property. (And within that, I guess, a property of how CreateFile() is called - whether FILE_FLAG_POSIX_SEMANTICS is set). This all suggests to me that some Windows configurations could fail on this test.

That seems like a rare case, though, and this does add coverage for case insensitivity in a way that makes our tests more robust. So, I'll accept it. However, please expand the comment a bit to note that failure may be possible on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could have elaborated more in my comment. I did a bit of research and the information is not very thorough. The best explanation of the situation is in the answers here.
How I read this and other material I have seen is that while NTFS itself is case-sensitive, Windows is not. I.e. you can create a file with specific capitalization, but Windows will not let you create another one with different capitalization.

Now, your point is also well made. The reason I decided to assume case-insensitivity is because I see some value in it as-is, and on the other hand I am not sure how I would write this test properly as I we don't know what file-system temp directory is on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, expanded comment coming up.

Copy link
Member

Choose a reason for hiding this comment

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

The reason I decided to assume case-insensitivity is because I see some value in it as-is, and on the other hand I am not sure how I would write this test properly as I we don't know what file-system temp directory is on.

Yep, agreed with all of this - this is why I'm board with testing it this way. Even though it seems strictly possible there could be errors, restricting to Windows is the best heuristic we have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the comments you asked for (and some more). I do not know if you get notified of commits or I have to call them out in comments like this...

@sdboyer
Copy link
Member

sdboyer commented Jun 4, 2017

OK cool, that'll do it 😄 - thanks, and yay first PR! 🎉

@sdboyer sdboyer merged commit 6b75d6b into golang:master Jun 4, 2017
@mikijov mikijov deleted the issue675-old branch June 24, 2017 15:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants