Search in sources :

Example 11 with FilestoreModel

use of com.gitblit.models.FilestoreModel in project gitblit by gitblit.

the class FilestoreManager method downloadBlob.

@Override
public FilestoreModel.Status downloadBlob(String oid, UserModel user, RepositoryModel repo, OutputStream streamOut) {
    //Access control and object logic
    Status status = canGetObject(oid, user, repo);
    if (status != Status.Available) {
        return status;
    }
    FilestoreModel item = fileCache.get(oid);
    if (streamOut != null) {
        try (FileInputStream streamIn = new FileInputStream(getStoragePath(oid))) {
            IOUtils.copyLarge(streamIn, streamOut);
            streamOut.flush();
            streamIn.close();
        } catch (EOFException e) {
            logger.error(MessageFormat.format("Client aborted connection for {0}", oid), e);
            return Status.Error_Unexpected_Stream_End;
        } catch (Exception e) {
            logger.error(MessageFormat.format("Failed to download blob {0}", oid), e);
            return Status.Error_Unknown;
        }
    }
    return item.getStatus();
}
Also used : Status(com.gitblit.models.FilestoreModel.Status) FilestoreModel(com.gitblit.models.FilestoreModel) EOFException(java.io.EOFException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 12 with FilestoreModel

use of com.gitblit.models.FilestoreModel in project gitblit by gitblit.

the class FilestoreManager method getFilestoreUsedByteCount.

@Override
public long getFilestoreUsedByteCount() {
    Iterator<FilestoreModel> iterator = fileCache.values().iterator();
    long total = 0;
    while (iterator.hasNext()) {
        FilestoreModel item = iterator.next();
        if (item.getStatus() == Status.Available) {
            total += item.getSize();
        }
    }
    return total;
}
Also used : FilestoreModel(com.gitblit.models.FilestoreModel)

Aggregations

FilestoreModel (com.gitblit.models.FilestoreModel)12 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)4 Status (com.gitblit.models.FilestoreModel.Status)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 PathModel (com.gitblit.models.PathModel)2 EOFException (java.io.EOFException)2 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)2 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)2 FileMode (org.eclipse.jgit.lib.FileMode)2 MutableObjectId (org.eclipse.jgit.lib.MutableObjectId)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)2 PathFilter (org.eclipse.jgit.treewalk.filter.PathFilter)2 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)1