lock repository when git access

This commit is contained in:
KOUNOIKE
2019-01-20 02:26:39 +09:00
parent e428346d3b
commit 4661dc3124
3 changed files with 22 additions and 3 deletions

View File

@@ -106,6 +106,7 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
if (isUpdating) {
if (hasDeveloperRole(repository.owner, repository.name, Some(account))) {
request.setAttribute(Keys.Request.UserName, account.userName)
request.setAttribute(Keys.Request.RepositoryLockKey, s"${repository.owner}/${repository.name}")
true
} else false
} else if (repository.repository.isPrivate) {

View File

@@ -55,11 +55,24 @@ class GitRepositoryServlet extends GitServlet with SystemSettingsService {
res.sendRedirect(baseUrl(req) + "/" + paths.dropRight(1).last + "/" + paths.last)
} else if (req.getMethod.toUpperCase == "POST" && req.getRequestURI.endsWith("/info/lfs/objects/batch")) {
serviceGitLfsBatchAPI(req, res)
withLockRepository(req) {
serviceGitLfsBatchAPI(req, res)
}
} else {
// response for git client
super.service(req, res)
withLockRepository(req) {
super.service(req, res)
}
}
}
private def withLockRepository[T](req: HttpServletRequest)(f: => T): T = {
if (req.hasAttribute(Keys.Request.RepositoryLockKey)) {
LockUtil.lock(req.getAttribute(Keys.Request.RepositoryLockKey).asInstanceOf[String]) {
f
}
} else {
f
}
}

View File

@@ -86,6 +86,11 @@ object Keys {
*/
val UserName = "USER_NAME"
/**
* Request key for the Lock key which is used during Git repository write access.
*/
val RepositoryLockKey = "REPOSITORY_LOCK_KEY"
/**
* Generate request key for the request cache.
*/