-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
path/filepath: Glob matching does not work on Windows with long path workaround #10577
Comments
This seems to be sufficient to fix it. // hasMeta returns true if path contains any of the magic characters
// recognized by Match.
func hasMeta(path string) bool {
+ // Strip off Windows long path prefix if it exists.
+ if runtime.GOOS == "windows" && strings.HasPrefix(path, "\\\\?\\") {
+ path = path[4:]
+ }
// TODO(niemeyer): Should other magic characters be added here?
return strings.IndexAny(path, "*?[") >= 0
} |
I am bit worried about using long paths. Not all programs support them. As far as I remember simple shell commands fail with long paths. Why do you need long path support? Alex |
Well, the rest of the stdlib works with long paths, so I don't see why Glob shouldn't. Especially because you are not using some win32/magic which doesn't support it, but have your own thing which does the job. Furthermore, Glob has nothing todo with long shell commands, it's a convenience function for finding files, plus it's broken even for short path if you happen to have the prefix by accident/default. |
I don't think it is true. There are many problems with long paths. That is why I think we should support them as little as possible. For example, why this test http://play.golang.org/p/uF7_491yCT fails:
But, if you insist, send a change http://golang.org/doc/contribute.html Others might think differently. Alex |
Too late for Go 1.5, but Alex I would like to understand why your test program fails like that. It looks like Chdir succeeds but then trying to write to 'hello.txt' in the current directory fails? How is that possible? Are we using the wrong system call in OpenFile or something like that? Thanks. |
I don't know much about this subject. See MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx - "Maximum Path Length Limitation" section in particular. Also http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx might explain this somewhat. Alex |
CL https://golang.org/cl/32451 mentions this issue. |
If you run this:
Expected output would be:
Matches: 3 Long matches: 3
Actual output is:
Matches: 3 Long matches: 0
The magical
\\?\
prefix is a workaround for 252 character filepath limits on the ancient Win32 API.Verified in go 1.4.2
The text was updated successfully, but these errors were encountered: