Search in sources :

Example 1 with PacketLineOut

use of org.eclipse.jgit.transport.PacketLineOut in project gerrit by GerritCodeReview.

the class UploadArchive method runImpl.

@Override
protected void runImpl() throws IOException, PermissionBackendException, Failure {
    PacketLineOut packetOut = new PacketLineOut(out);
    packetOut.setFlushOnEnd(true);
    packetOut.writeString("ACK");
    packetOut.end();
    try {
        // Parse Git arguments
        readArguments();
        ArchiveFormat f = allowedFormats.getExtensions().get("." + options.format);
        if (f == null) {
            throw new Failure(3, "fatal: upload-archive not permitted");
        }
        // Find out the object to get from the specified reference and paths
        ObjectId treeId = repo.resolve(options.treeIsh);
        if (treeId == null) {
            throw new Failure(4, "fatal: reference not found");
        }
        // Verify the user has permissions to read the specified tree.
        if (!canRead(treeId)) {
            throw new Failure(5, "fatal: cannot perform upload-archive operation");
        }
        // The archive is sent in DATA sideband channel
        try (SideBandOutputStream sidebandOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, SideBandOutputStream.MAX_BUF, out)) {
            new ArchiveCommand(repo).setFormat(f.name()).setFormatOptions(getFormatOptions(f)).setTree(treeId).setPaths(options.path.toArray(new String[0])).setPrefix(options.prefix).setOutputStream(sidebandOut).call();
            sidebandOut.flush();
        } catch (GitAPIException e) {
            throw new Failure(7, "fatal: git api exception, " + e);
        }
    } catch (Failure f) {
        // Report the error in ERROR sideband channel
        try (SideBandOutputStream sidebandError = new SideBandOutputStream(SideBandOutputStream.CH_ERROR, SideBandOutputStream.MAX_BUF, out)) {
            sidebandError.write(f.getMessage().getBytes(UTF_8));
            sidebandError.flush();
        }
        throw f;
    } finally {
        // In any case, cleanly close the packetOut channel
        packetOut.end();
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PacketLineOut(org.eclipse.jgit.transport.PacketLineOut) ArchiveFormat(com.google.gerrit.server.change.ArchiveFormat) ObjectId(org.eclipse.jgit.lib.ObjectId) SideBandOutputStream(org.eclipse.jgit.transport.SideBandOutputStream) ArchiveCommand(org.eclipse.jgit.api.ArchiveCommand)

Example 2 with PacketLineOut

use of org.eclipse.jgit.transport.PacketLineOut in project gitblit by gitblit.

the class GitDaemonService method execute.

void execute(final GitDaemonClient client, final String commandLine) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException {
    final String name = commandLine.substring(command.length() + 1);
    Repository db;
    try {
        db = client.getDaemon().openRepository(client, name);
    } catch (ServiceMayNotContinueException e) {
        // An error when opening the repo means the client is expecting a ref
        // advertisement, so use that style of error.
        PacketLineOut pktOut = new PacketLineOut(client.getOutputStream());
        //$NON-NLS-1$ //$NON-NLS-2$
        pktOut.writeString("ERR " + e.getMessage() + "\n");
        db = null;
    }
    if (db == null)
        return;
    try {
        if (isEnabledFor(db))
            execute(client, db);
    } finally {
        db.close();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PacketLineOut(org.eclipse.jgit.transport.PacketLineOut) ServiceMayNotContinueException(org.eclipse.jgit.transport.ServiceMayNotContinueException)

Example 3 with PacketLineOut

use of org.eclipse.jgit.transport.PacketLineOut in project gerrit by GerritCodeReview.

the class UploadArchiveIT method argumentsToInputStream.

private InputStream argumentsToInputStream(String c) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PacketLineOut pctOut = new PacketLineOut(out);
    for (String arg : Splitter.on(' ').split(c)) {
        pctOut.writeString("argument " + arg);
    }
    pctOut.end();
    return new ByteArrayInputStream(out.toByteArray());
}
Also used : PacketLineOut(org.eclipse.jgit.transport.PacketLineOut) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

PacketLineOut (org.eclipse.jgit.transport.PacketLineOut)3 ArchiveFormat (com.google.gerrit.server.change.ArchiveFormat)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArchiveCommand (org.eclipse.jgit.api.ArchiveCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 Repository (org.eclipse.jgit.lib.Repository)1 ServiceMayNotContinueException (org.eclipse.jgit.transport.ServiceMayNotContinueException)1 SideBandOutputStream (org.eclipse.jgit.transport.SideBandOutputStream)1