| | |
| | | */
|
| | | package com.gitblit.utils;
|
| | |
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.OutputStream;
|
| | | import java.text.MessageFormat;
|
| | |
| | | import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
| | | import org.apache.commons.compress.compressors.CompressorException;
|
| | | import org.apache.commons.compress.compressors.CompressorStreamFactory;
|
| | | import org.apache.wicket.util.io.ByteArrayOutputStream;
|
| | | import org.eclipse.jgit.lib.Constants;
|
| | | import org.eclipse.jgit.lib.FileMode;
|
| | | import org.eclipse.jgit.lib.MutableObjectId;
|
| | |
| | |
|
| | | /**
|
| | | * Collection of static methods for retrieving information from a repository.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public class CompressionUtils {
|
| | |
|
| | |
| | |
|
| | | /**
|
| | | * Log an error message and exception.
|
| | | * |
| | | *
|
| | | * @param t
|
| | | * @param repository
|
| | | * if repository is not null it MUST be the {0} parameter in the
|
| | |
| | | /**
|
| | | * Zips the contents of the tree at the (optionally) specified revision and
|
| | | * the (optionally) specified basepath to the supplied outputstream.
|
| | | * |
| | | *
|
| | | * @param repository
|
| | | * @param basePath
|
| | | * if unspecified, entire repository is assumed.
|
| | |
| | | } catch (IOException e) {
|
| | | error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
|
| | | } finally {
|
| | | tw.release();
|
| | | tw.close();
|
| | | rw.dispose();
|
| | | }
|
| | | return success;
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * tar the contents of the tree at the (optionally) specified revision and
|
| | | * the (optionally) specified basepath to the supplied outputstream.
|
| | | * |
| | | *
|
| | | * @param repository
|
| | | * @param basePath
|
| | | * if unspecified, entire repository is assumed.
|
| | |
| | | OutputStream os) {
|
| | | return tar(null, repository, basePath, objectId, os);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * tar.gz the contents of the tree at the (optionally) specified revision and
|
| | | * the (optionally) specified basepath to the supplied outputstream.
|
| | | * |
| | | *
|
| | | * @param repository
|
| | | * @param basePath
|
| | | * if unspecified, entire repository is assumed.
|
| | |
| | | OutputStream os) {
|
| | | return tar(CompressorStreamFactory.GZIP, repository, basePath, objectId, os);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * tar.xz the contents of the tree at the (optionally) specified revision and
|
| | | * the (optionally) specified basepath to the supplied outputstream.
|
| | | * |
| | | *
|
| | | * @param repository
|
| | | * @param basePath
|
| | | * if unspecified, entire repository is assumed.
|
| | |
| | | OutputStream os) {
|
| | | return tar(CompressorStreamFactory.XZ, repository, basePath, objectId, os);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * tar.bzip2 the contents of the tree at the (optionally) specified revision and
|
| | | * the (optionally) specified basepath to the supplied outputstream.
|
| | | * |
| | | *
|
| | | * @param repository
|
| | | * @param basePath
|
| | | * if unspecified, entire repository is assumed.
|
| | |
| | | */
|
| | | public static boolean bzip2(Repository repository, String basePath, String objectId,
|
| | | OutputStream os) {
|
| | | |
| | |
|
| | | return tar(CompressorStreamFactory.BZIP2, repository, basePath, objectId, os);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Compresses/archives the contents of the tree at the (optionally)
|
| | | * specified revision and the (optionally) specified basepath to the
|
| | | * supplied outputstream.
|
| | | * |
| | | *
|
| | | * @param algorithm
|
| | | * compression algorithm for tar (optional)
|
| | | * @param repository
|
| | |
| | | if (commit == null) {
|
| | | return false;
|
| | | }
|
| | | |
| | |
|
| | | OutputStream cos = os;
|
| | | if (!StringUtils.isEmpty(algorithm)) {
|
| | | try {
|
| | |
| | | continue;
|
| | | }
|
| | | tw.getObjectId(id, 0);
|
| | | |
| | |
|
| | | ObjectLoader loader = repository.open(id);
|
| | | if (FileMode.SYMLINK == mode) {
|
| | | TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(),TarArchiveEntry.LF_SYMLINK);
|
| | |
| | | entry.setMode(mode.getBits());
|
| | | entry.setModTime(modified);
|
| | | entry.setSize(loader.getSize());
|
| | | tos.putArchiveEntry(entry); |
| | | tos.putArchiveEntry(entry);
|
| | | loader.copyTo(tos);
|
| | | tos.closeArchiveEntry();
|
| | | }
|
| | |
| | | } catch (IOException e) {
|
| | | error(e, repository, "{0} failed to {1} stream files from commit {2}", algorithm, commit.getName());
|
| | | } finally {
|
| | | tw.release();
|
| | | tw.close();
|
| | | rw.dispose();
|
| | | }
|
| | | return success;
|