[infer] Fix resource leak in RepoCommand
Bug: 509385 Change-Id: I30c427f0dd2fc1fceb6b003dfdee0a05efaefca9 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
1779fb4a57
commit
e78626f414
|
@ -180,17 +180,11 @@ public ObjectId sha1(String uri, String ref) throws GitAPIException {
|
|||
public byte[] readFile(String uri, String ref, String path)
|
||||
throws GitAPIException, IOException {
|
||||
File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Repository repo = Git
|
||||
.cloneRepository()
|
||||
.setBare(true)
|
||||
.setDirectory(dir)
|
||||
.setURI(uri)
|
||||
.call()
|
||||
.getRepository();
|
||||
try {
|
||||
try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
|
||||
.setURI(uri).call();
|
||||
Repository repo = git.getRepository()) {
|
||||
return readFileFromRepo(repo, ref, path);
|
||||
} finally {
|
||||
repo.close();
|
||||
FileUtils.delete(dir, FileUtils.RECURSIVE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue