mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-01-05 15:20:02 +01:00
(ref #933) fix/Unable to download large file
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user