src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 541 forks source link

Failed to clone on Windows with "GetFileInformationByHandle Incorrect function" #1222

Closed fkorotkov closed 4 years ago

fkorotkov commented 4 years ago

I'm hitting a particular issue when cloning a particular SHA of one of the repositories. This bug is reproducible only on Windows.

Here is a project to reproduce: https://github.com/fkorotkov/go-git-clone-windows-issue

Simply run go test ./... to get the following:

C:\Users\Fedor Korotkov\GolandProjects\go-git-clone-windows-issue>go test ./...
2019/09/30 15:06:42 Cloning refs/heads/windows...

2019/09/30 15:06:47 Failed to clone: GetFileInformationByHandle temp-repo\liblumen_beam\src\beam\reader\chunk\aux.rs: Incorrect function.!
FAIL    github.com/fkorotkov/go-git-clone-windows-issue 5.322s
FAIL

I've tried to dig where this GetFileInformationByHandle error is coming from this newFileStatFromGetFileInformationByHandle function. I did put a debugger in there was able to notice only one weird thing:

image

As you can see from the screenshot above chink folder is empty even though it seems all other files got populated. 🤔

Here is the stacktrace of the error just in case.

os.newFileStatFromGetFileInformationByHandle at types_windows.go:48
os.stat at stat_windows.go:119
os.lstatNolog at stat_windows.go:133
os.Lstat at stat.go:22
gopkg.in/src-d/go-billy.v4/osfs.(*OS).Lstat at os.go:115
gopkg.in/src-d/go-billy.v4/helper/polyfill.(*Polyfill).Lstat at polyfill.go:79
gopkg.in/src-d/go-billy.v4/helper/chroot.(*ChrootHelper).Lstat at chroot.go:160
gopkg.in/src-d/go-git%2ev4.(*Worktree).addIndexFromFile at worktree.go:596
gopkg.in/src-d/go-git%2ev4.(*Worktree).checkoutChangeRegularFile at worktree.go:510
gopkg.in/src-d/go-git%2ev4.(*Worktree).checkoutChange at worktree.go:401
gopkg.in/src-d/go-git%2ev4.(*Worktree).resetWorktree at worktree.go:365
gopkg.in/src-d/go-git%2ev4.(*Worktree).Reset at worktree.go:295
gopkg.in/src-d/go-git%2ev4.(*Repository).clone at repository.go:767
gopkg.in/src-d/go-git%2ev4.PlainCloneContext at repository.go:360
gopkg.in/src-d/go-git%2ev4.PlainClone at repository.go:336
github.com/fkorotkov/go-git-clone-windows-issue.clone at main.go:48
github.com/fkorotkov/go-git-clone-windows-issue.TestClone at main_test.go:9
testing.tRunner at testing.go:909
runtime.goexit at asm_amd64.s:1357
 - Async stack trace
testing.(*T).Run at testing.go:960

At the moment I'm kind of in a dead end so will appreciate any help with the issue.

fkorotkov commented 4 years ago

Seems the issue was with a filename reserved by Windoews: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions