use of com.google.gerrit.server.change.ArchiveFormatInternal 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();
ArchiveFormatInternal f = allowedFormats.getExtensions().get("." + options.format);
if (f == null) {
throw new Failure(3, "fatal: upload-archive not permitted for format " + options.format);
}
// 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: " + options.treeIsh);
}
// Verify the user has permissions to read the specified tree.
if (!canRead(treeId)) {
throw new Failure(5, "fatal: no permission to read tree" + options.treeIsh);
}
// 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 (Exception e) {
// NoClassDefFound.
try (SideBandOutputStream sidebandError = new SideBandOutputStream(SideBandOutputStream.CH_ERROR, SideBandOutputStream.MAX_BUF, out)) {
sidebandError.write(e.getMessage().getBytes(UTF_8));
sidebandError.flush();
}
throw e;
} finally {
// In any case, cleanly close the packetOut channel
packetOut.end();
}
}
use of com.google.gerrit.server.change.ArchiveFormatInternal in project gerrit by GerritCodeReview.
the class GetServerInfo method getDownloadInfo.
private DownloadInfo getDownloadInfo() {
DownloadInfo info = new DownloadInfo();
info.schemes = new HashMap<>();
downloadSchemes.runEach(extension -> {
DownloadScheme scheme = extension.get();
if (scheme.isEnabled() && scheme.getUrl("${project}") != null) {
info.schemes.put(extension.getExportName(), getDownloadSchemeInfo(scheme));
}
});
info.archives = archiveFormats.getAllowed().stream().map(ArchiveFormatInternal::getShortName).collect(toList());
return info;
}
use of com.google.gerrit.server.change.ArchiveFormatInternal in project gerrit by GerritCodeReview.
the class GetArchive method apply.
@Override
public Response<BinaryResult> apply(RevisionResource rsrc) throws BadRequestException, IOException, MethodNotAllowedException {
if (Strings.isNullOrEmpty(format)) {
throw new BadRequestException("format is not specified");
}
ArchiveFormatInternal f = allowedFormats.extensions.get("." + format);
if (f == null) {
throw new BadRequestException("unknown archive format");
}
if (f == ArchiveFormatInternal.ZIP) {
throw new MethodNotAllowedException("zip format is disabled");
}
boolean close = true;
Repository repo = repoManager.openRepository(rsrc.getProject());
try {
RevCommit commit;
String name;
try (RevWalk rw = new RevWalk(repo)) {
commit = rw.parseCommit(rsrc.getPatchSet().commitId());
name = name(f, rw, commit);
}
BinaryResult bin = new BinaryResult() {
@Override
public void writeTo(OutputStream out) throws IOException {
try {
new ArchiveCommand(repo).setFormat(f.name()).setTree(commit.getTree()).setOutputStream(out).call();
} catch (GitAPIException e) {
throw new IOException(e);
}
}
@Override
public void close() throws IOException {
repo.close();
}
};
bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName(name);
close = false;
return Response.ok(bin);
} finally {
if (close) {
repo.close();
}
}
}
Aggregations