4

I've created a local repository using JGit API's. When all processing is done, I'd like to delete the local repo (which is a simple java.io.File). However File.delete() operation fails. I'm already calling

org.eclipse.jgit.api.Git.close()
org.eclipse.jgit.lib.Repository.close()

Is there any further cleanup required?

centic
  • 15,565
  • 9
  • 68
  • 125
qwerty
  • 3,801
  • 2
  • 28
  • 43
  • I would use http://file-leak-detector.kohsuke.org/ to find out where there are still files open. – centic May 25 '15 at 16:29

1 Answers1

3

One thing that I ran into was that if you use Git.cloneRepository().call(), you need to close the result that is returned, i.e.

    Git result = Git.cloneRepository()
            ....
            .call();

    try {
        ...
    } finally {
        result.close();
    }

See also this code snippet from the jgit-cookbook

Additionally some places in JGit that might keep file-handles open were fixed at some point after JGit 3.5.1, see this bug, so it might also help to ensure that you use the latest version of JGit if you are still using an older one.

centic
  • 15,565
  • 9
  • 68
  • 125
  • Thank you so much! Closing the Git handle returned by cloneRepository() fixed the issue. I was using 3.6.1, so the JGit version wasn't an issue – qwerty May 25 '15 at 17:01