Search in sources :

Example 1 with TooLargeObjectInPackException

use of org.eclipse.jgit.errors.TooLargeObjectInPackException in project gerrit by GerritCodeReview.

the class Receive method runImpl.

@Override
protected void runImpl() throws IOException, Failure {
    CurrentUser currentUser = session.getUser();
    try {
        permissionBackend.user(currentUser).project(project.getNameKey()).check(ProjectPermission.RUN_RECEIVE_PACK);
    } catch (AuthException e) {
        throw new Failure(1, "fatal: receive-pack not permitted on this server", e);
    } catch (PermissionBackendException e) {
        throw new Failure(1, "fatal: unable to check permissions " + e);
    }
    AsyncReceiveCommits arc = factory.create(projectState, currentUser.asIdentifiedUser(), repo, null);
    try {
        Capable r = arc.canUpload();
        if (r != Capable.OK) {
            throw die(r.getMessage());
        }
    } catch (PermissionBackendException e) {
        throw die(e.getMessage());
    }
    ReceivePack rp = arc.getReceivePack();
    try {
        rp.receive(in, out, err);
        session.setPeerAgent(rp.getPeerUserAgent());
    } catch (UnpackException badStream) {
        // we want to present this error to the user
        if (badStream.getCause() instanceof TooLargeObjectInPackException) {
            StringBuilder msg = new StringBuilder();
            msg.append("Receive error on project \"").append(projectState.getName()).append("\"");
            msg.append(" (user ");
            msg.append(currentUser.getUserName().orElse(null));
            msg.append(" account ");
            msg.append(currentUser.getAccountId());
            msg.append("): ");
            msg.append(badStream.getCause().getMessage());
            logger.atInfo().log(msg.toString());
            throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
        }
        StringBuilder msg = new StringBuilder();
        msg.append("Unpack error on project \"").append(projectState.getName()).append("\":\n");
        msg.append("  AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook());
        if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
            msg.append("DEFAULT");
        } else {
            msg.append(rp.getAdvertiseRefsHook().getClass());
        }
        msg.append("\n");
        IOException detail = new IOException(msg.toString(), badStream);
        throw new Failure(128, "fatal: Unpack error, check server log", detail);
    }
}
Also used : TooLargeObjectInPackException(org.eclipse.jgit.errors.TooLargeObjectInPackException) AsyncReceiveCommits(com.google.gerrit.server.git.receive.AsyncReceiveCommits) Capable(com.google.gerrit.common.data.Capable) UnpackException(org.eclipse.jgit.errors.UnpackException) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ReceivePack(org.eclipse.jgit.transport.ReceivePack) IOException(java.io.IOException)

Aggregations

Capable (com.google.gerrit.common.data.Capable)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 AsyncReceiveCommits (com.google.gerrit.server.git.receive.AsyncReceiveCommits)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 IOException (java.io.IOException)1 TooLargeObjectInPackException (org.eclipse.jgit.errors.TooLargeObjectInPackException)1 UnpackException (org.eclipse.jgit.errors.UnpackException)1 ReceivePack (org.eclipse.jgit.transport.ReceivePack)1