Fix resource leak.

This commit is contained in:
rabitarochan
2013-07-19 18:18:44 +09:00
parent 3546a5d392
commit 8226073506

View File

@@ -119,11 +119,13 @@ trait WikiService {
* Returns the list of wiki page names. * Returns the list of wiki page names.
*/ */
def getWikiPageList(owner: String, repository: String): List[String] = { def getWikiPageList(owner: String, repository: String): List[String] = {
JGitUtil.getFileList(Git.open(Directory.getWikiRepositoryDir(owner, repository)), "master", ".") JGitUtil.withGit(Directory.getWikiRepositoryDir(owner, repository)){ git =>
JGitUtil.getFileList(git, "master", ".")
.filter(_.name.endsWith(".md")) .filter(_.name.endsWith(".md"))
.map(_.name.replaceFirst("\\.md$", "")) .map(_.name.replaceFirst("\\.md$", ""))
.sortBy(x => x) .sortBy(x => x)
} }
}
/** /**
* Save the wiki page. * Save the wiki page.
@@ -210,12 +212,16 @@ trait WikiService {
private def cloneOrPullWorkingCopy(workDir: File, owner: String, repository: String): Unit = { private def cloneOrPullWorkingCopy(workDir: File, owner: String, repository: String): Unit = {
if(!workDir.exists){ if(!workDir.exists){
val git =
Git.cloneRepository Git.cloneRepository
.setURI(Directory.getWikiRepositoryDir(owner, repository).toURI.toString) .setURI(Directory.getWikiRepositoryDir(owner, repository).toURI.toString)
.setDirectory(workDir) .setDirectory(workDir)
.call .call
git.getRepository.close // close .git resources.
} else { } else {
Git.open(workDir).pull.call JGitUtil.withGit(workDir){ git =>
git.pull.call
}
} }
} }