mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
use FileUtil.withTmpDir and FileUtil.using
This commit is contained in:
@@ -9,7 +9,6 @@ import org.eclipse.jgit.api.Git
|
||||
import org.apache.commons.io._
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
import org.eclipse.jgit.lib.PersonIdent
|
||||
import scala.Some
|
||||
|
||||
class CreateRepositoryController extends CreateRepositoryControllerBase
|
||||
with RepositoryService with AccountService with WikiService with LabelsService with ActivityService
|
||||
@@ -74,8 +73,7 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
||||
JGitUtil.initRepository(gitdir)
|
||||
|
||||
if(form.createReadme){
|
||||
val tmpdir = getInitRepositoryDir(form.owner, form.name)
|
||||
try {
|
||||
FileUtil.withTmpDir(getInitRepositoryDir(form.owner, form.name)){ tmpdir =>
|
||||
// Clone the repository
|
||||
Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call
|
||||
|
||||
@@ -97,9 +95,6 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
||||
.setCommitter(new PersonIdent(loginUserName, loginAccount.mailAddress))
|
||||
.setMessage("Initial commit").call
|
||||
git.push.call
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import util.{LockUtil, CollaboratorsAuthenticator, JGitUtil, ReferrerAuthenticat
|
||||
import util.Directory._
|
||||
import util.Implicits._
|
||||
import util.ControlUtil._
|
||||
import util.FileUtil._
|
||||
import service._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
@@ -15,7 +16,6 @@ import org.eclipse.jgit.api.MergeCommand.FastForwardMode
|
||||
import service.IssuesService._
|
||||
import service.PullRequestService._
|
||||
import util.JGitUtil.DiffInfo
|
||||
import scala.Some
|
||||
import service.RepositoryService.RepositoryTreeNode
|
||||
import util.JGitUtil.CommitInfo
|
||||
|
||||
@@ -99,10 +99,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
LockUtil.lock(s"${owner}/${name}/merge"){
|
||||
getPullRequest(owner, name, issueId).map { case (issue, pullreq) =>
|
||||
val remote = getRepositoryDir(owner, name)
|
||||
val tmpdir = new java.io.File(getTemporaryDir(owner, name), s"merge-${issueId}")
|
||||
val git = Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(pullreq.branch).call
|
||||
withTmpDir(new java.io.File(getTemporaryDir(owner, name), s"merge-${issueId}")){ tmpdir =>
|
||||
using(Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(pullreq.branch).call){ git =>
|
||||
|
||||
try {
|
||||
// mark issue as merged and close.
|
||||
val loginAccount = context.loginAccount.get
|
||||
createComment(owner, name, loginAccount.userName, issueId, form.message, "merge")
|
||||
@@ -159,10 +158,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
}
|
||||
|
||||
redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||
|
||||
} finally {
|
||||
git.getRepository.close
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound
|
||||
}
|
||||
@@ -316,13 +312,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
// TODO Are there more quick way?
|
||||
LockUtil.lock(s"${userName}/${repositoryName}/merge-check"){
|
||||
val remote = getRepositoryDir(userName, repositoryName)
|
||||
val tmpdir = new java.io.File(getTemporaryDir(userName, repositoryName), "merge-check")
|
||||
if(tmpdir.exists()){
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
withTmpDir(new java.io.File(getTemporaryDir(userName, repositoryName), "merge-check")){ tmpdir =>
|
||||
using(Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(branch).call){ git =>
|
||||
|
||||
val git = Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(branch).call
|
||||
try {
|
||||
git.checkout.setName(branch).call
|
||||
|
||||
git.fetch
|
||||
@@ -334,10 +326,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
.setCommit(false).call
|
||||
|
||||
result.getConflicts != null
|
||||
|
||||
} finally {
|
||||
git.getRepository.close
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user