libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.18k stars 887 forks source link

Access Is Denied to log file #1320

Open JamesBlack001 opened 8 years ago

JamesBlack001 commented 8 years ago

Have an issue with this error message:

LibGit2Sharp.LibGit2SharpException: Could not open 'c:/../.git/logs/HEAD' for writing: Access is denied.

   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\projects\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 160
   at LibGit2Sharp.ReferenceCollection.MoveHeadTarget[T](T target) in c:\projects\libgit2sharp\LibGit2Sharp\ReferenceCollection.cs:line 631
   at LibGit2Sharp.Repository.Checkout(Branch branch, CheckoutOptions options) in c:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 911
carlosmn commented 8 years ago

This is something that can happen when you run multiple operations in parallel. Moving branches or updating the current branch wants to write to the reflog, so it needs to write to it. Unfortunately Windows does not generally like having the same file open at the same time with different intents.

It's clear whether git was used before or after everything else was tried. Do you have parallelism in your application or in your system in general? When you tried with git, had you stopped other operations on the system?

JamesBlack001 commented 8 years ago

We do use parallelism. But we have a lock mechanism around our git operations, so only one thread can access git at a time.

When we used the git command it was after all other operations.

The file only seems to be locked when using libgit2sharp, and continues to be locked after a machine reboot.

ethomson commented 8 years ago

Files can't stay locked in Windows between reboots, AFAIK. Have you used sysinternals process explorer to see what other process has a handle to that file?

txdv commented 8 years ago

You might want to check out "file unlocker", a pretty nifty tool for avoiding locked file issues on windows.