mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-06 20:57:08 +02:00
lock repository when git access
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user