Fix resource leak.

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

View File

@@ -119,10 +119,12 @@ 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 =>
.filter(_.name.endsWith(".md")) JGitUtil.getFileList(git, "master", ".")
.map(_.name.replaceFirst("\\.md$", "")) .filter(_.name.endsWith(".md"))
.sortBy(x => x) .map(_.name.replaceFirst("\\.md$", ""))
.sortBy(x => x)
}
} }
/** /**
@@ -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){
Git.cloneRepository val git =
.setURI(Directory.getWikiRepositoryDir(owner, repository).toURI.toString) Git.cloneRepository
.setDirectory(workDir) .setURI(Directory.getWikiRepositoryDir(owner, repository).toURI.toString)
.call .setDirectory(workDir)
.call
git.getRepository.close // close .git resources.
} else { } else {
Git.open(workDir).pull.call JGitUtil.withGit(workDir){ git =>
git.pull.call
}
} }
} }