mono / ngit

Automated jgit port to c#
261 stars 151 forks source link

Ngit File locks #49

Open dougrathbone opened 11 years ago

dougrathbone commented 11 years ago

While trying to write some NGit related tests I always get UnauthorizedAccessExceptions when trying to delete my repo path after creating it.

is there a way to release any pack file locks?

running

repo.GetRepository().Close();

doesn't seem to fix things.

alanmcgovern commented 11 years ago

What version of ngit are you using? Is it the very latest commit in master?

dougrathbone commented 11 years ago

Yes i've pulled from here on my recent builds and the problem is definitely there.. If I do a simple clone, and then try and recursively delete the folder i've cloned into a few seconds later (even 10 second later) the files are locked.

dougrathbone commented 11 years ago

Any update to this? I still can't delete the cloned directory within a short timespan

dougrathbone commented 10 years ago

Try this:

var repoPath = "C:\\otherrepopath";
var checkoutDir = "C:\\output"; 

var cmd = Git.CloneRepository();
cmd.SetDirectory(checkoutDir);
cmd.SetURI(repoPath);
var git = cmd.Call();
git.Checkout().SetName("master").Call();

Directory.Delete(checkoutDir,true);

am I missing something? the IDX will be locked.

calling GetRespository().Close() doesn't appear help.

dougrathbone commented 10 years ago

This is also mentioned in a number of jGit posts:

http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg01951.html

http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg01954.html

I've tested by even ReposityCache.Close(repo) until the useCnt drops to -1 and the file is still locked.

This seems to be a breaking issue with NGit.

Therzok commented 10 years ago

Yeah. JGit is broken in that regard. I haven't managed to find a high level fix, so that means we're stuck with waiting for the JGit team to fix it.

Therzok commented 10 years ago

Could you try forcing a few GC collections? Try doing it at least 3 times.

dougrathbone commented 10 years ago

Are there any hacks I can do to release the file handle?

Therzok commented 10 years ago

I've tried setting FileAttributes to normal, but it didn't cut it.

dougrathbone commented 10 years ago

Yeah I've also tried to recommended FileUtils.Delete(checkoutDir, FileUtils.RECURSIVE | FileUtils.RETRY); the jGit guys are using with no luck.

many rounds of GC.Collect do nothing. There is a stream or file handle left open. Am trying to open the solution locally to start debugging the lock, but don't have SharpZipLib,Mono.Posix or Mono.Security.

Where can I grab these?

dougrathbone commented 10 years ago

I have found a way to clear all of the file handles. You need to really be specific about your releases.

original example:

var repoPath = "C:\\otherrepopath";
var checkoutDir = "C:\\output"; 

var cmd = Git.CloneRepository();
cmd.SetDirectory(checkoutDir);
cmd.SetURI(repoPath);
var git = cmd.Call();
git.Checkout().SetName("master").Call();

Directory.Delete(checkoutDir,true);

New version without file locks:

var repoPath = "C:\\otherrepopath";
var checkoutDir = "C:\\output"; 

var cmd = Git.CloneRepository();
cmd.SetDirectory(checkoutDir);
cmd.SetURI(repoPath);
var git = cmd.Call();
var gitCheckout = git.Checkout().SetName("master").Call(); //assign the return to capture the handle
gitCheckout.GetRepository().Close(); //release the handle
git.GetRepository().Close(); // release the first handle

Directory.Delete(checkoutDir,true);
dougrathbone commented 10 years ago

I find that the fluent API makes it very easy to lose track of references and file handles made between fluent calls.

This seems to be a serious issue with Ngit that should be addressed whereby if being called through the fluent API, previous references should be closed in consecutive calls.