mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-04 20:45:58 +01:00
(refs #330)Return NotFound if specified file does not exist
This commit is contained in:
@@ -82,17 +82,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||
|
||||
@scala.annotation.tailrec
|
||||
def getPathObjectId(path: String, walk: TreeWalk): ObjectId = walk.next match {
|
||||
case true if(walk.getPathString == path) => walk.getObjectId(0)
|
||||
def getPathObjectId(path: String, walk: TreeWalk): Option[ObjectId] = walk.next match {
|
||||
case true if(walk.getPathString == path) => Some(walk.getObjectId(0))
|
||||
case true => getPathObjectId(path, walk)
|
||||
case false => None
|
||||
}
|
||||
|
||||
val objectId = using(new TreeWalk(git.getRepository)){ treeWalk =>
|
||||
using(new TreeWalk(git.getRepository)){ treeWalk =>
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
treeWalk.setRecursive(true)
|
||||
getPathObjectId(path, treeWalk)
|
||||
}
|
||||
|
||||
} map { objectId =>
|
||||
if(raw){
|
||||
// Download
|
||||
defining(JGitUtil.getContent(git, objectId, false).get){ bytes =>
|
||||
@@ -120,6 +120,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
|
||||
repo.html.blob(id, repository, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit))
|
||||
}
|
||||
} getOrElse NotFound
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user