(ref #933) fix/Unable to download large file

This commit is contained in:
nazoking
2015-10-12 21:45:36 +09:00
parent 30a8cefc37
commit 1a97beb8cf
2 changed files with 23 additions and 3 deletions

View File

@@ -293,8 +293,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
getPathObjectId(git, path, revCommit).map { objectId =>
if(raw){
// Download
JGitUtil.getContentFromId(git, objectId, true).map { bytes =>
RawData("application/octet-stream", bytes)
JGitUtil.getObjectLoaderFromId(git, objectId){ loader =>
//RawData("application/octet-stream", bytes)
contentType = "application/octet-stream"
response.setContentLength(loader.getSize.toInt)
loader.copyTo(response.getOutputStream)
Unit
} getOrElse NotFound
} else {
html.blob(id, repository, path.split("/").toList,

View File

@@ -713,7 +713,7 @@ object JGitUtil {
def getContentFromId(git: Git, id: ObjectId, fetchLargeFile: Boolean): Option[Array[Byte]] = try {
using(git.getRepository.getObjectDatabase){ db =>
val loader = db.open(id)
if(fetchLargeFile == false && FileUtil.isLarge(loader.getSize)){
if(loader.isLarge || (fetchLargeFile == false && FileUtil.isLarge(loader.getSize))){
None
} else {
Some(loader.getBytes)
@@ -723,6 +723,22 @@ object JGitUtil {
case e: MissingObjectException => None
}
/**
* Get objectLoader of the given object id from the Git repository.
*
* @param git the Git object
* @param id the object id
* @param f the function process ObjectLoader
* @return None if object does not exist
*/
def loaderFromId[A](git: Git, id: ObjectId)(f: ObjectLoader => A):Option[A] = try {
using(git.getRepository.getObjectDatabase){ db =>
Some(f(db.open(id)))
}
} catch {
case e: MissingObjectException => None
}
/**
* Returns all commit id in the specified repository.
*/