(refs #330)Return NotFound if specified file does not exist

This commit is contained in:
takezoe
2014-03-05 04:18:45 +09:00
parent 5cf96134d5
commit f11be44c02

View File

@@ -82,17 +82,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id)) val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
@scala.annotation.tailrec @scala.annotation.tailrec
def getPathObjectId(path: String, walk: TreeWalk): ObjectId = walk.next match { def getPathObjectId(path: String, walk: TreeWalk): Option[ObjectId] = walk.next match {
case true if(walk.getPathString == path) => walk.getObjectId(0) case true if(walk.getPathString == path) => Some(walk.getObjectId(0))
case true => getPathObjectId(path, walk) 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.addTree(revCommit.getTree)
treeWalk.setRecursive(true) treeWalk.setRecursive(true)
getPathObjectId(path, treeWalk) getPathObjectId(path, treeWalk)
} } map { objectId =>
if(raw){ if(raw){
// Download // Download
defining(JGitUtil.getContent(git, objectId, false).get){ bytes => 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)) repo.html.blob(id, repository, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit))
} }
} getOrElse NotFound
} }
}) })