Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Ngit File locks #49

Open
dougrathbone opened this issue Dec 30, 2012 · 12 comments
Open

Ngit File locks #49

dougrathbone opened this issue Dec 30, 2012 · 12 comments

Comments

@dougrathbone
Copy link

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
Copy link
Member

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

@dougrathbone
Copy link
Author

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
Copy link
Author

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

@dougrathbone
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

Therzok commented Mar 24, 2014

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
Copy link
Contributor

Therzok commented Mar 24, 2014

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

@dougrathbone
Copy link
Author

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

@Therzok
Copy link
Contributor

Therzok commented Mar 24, 2014

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

@dougrathbone
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants