Преглед на файлове

dpkg-deb: Add support for gzip compression strategies

This adds support for filtered, huffman, rle and fixed strategies. Those
are only usable when dpkg-deb uses zlib, because the command line tool
gzip does not have any way to specify them.
Guillem Jover преди 14 години
родител
ревизия
ac02d172c0
променени са 5 файла, в които са добавени 38 реда и са изтрити 3 реда
  1. 2 0
      debian/changelog
  2. 2 1
      dpkg-deb/main.c
  3. 28 1
      lib/dpkg/compress.c
  4. 4 0
      lib/dpkg/compress.h
  5. 2 1
      man/dpkg-deb.1

+ 2 - 0
debian/changelog

@@ -125,6 +125,8 @@ dpkg (1.17.0) UNRELEASED; urgency=low
     the default dpkg-deb compressor, mainly for downstreams.
   * Switch dpkg-deb default compressor from gzip to xz. Build dpkg.deb using
     gzip to make debootstrap life easier on non-Debian based systems.
+  * Add support for gzip compression strategies to dpkg-deb. The new
+    strategies are: filtered, huffman, rle and fixed.
 
   [ Updated programs translations ]
   * Fix typo in Spanish translation of update-alternatives.

+ 2 - 1
dpkg-deb/main.c

@@ -112,7 +112,8 @@ usage(const struct cmdinfo *cip, const char *value)
 "  -Z<type>                         Set the compression type used when building.\n"
 "                                     Allowed types: gzip, xz, bzip2, none.\n"
 "  -S<strategy>                     Set the compression strategy when building.\n"
-"                                     Allowed values: none, extreme (xz).\n"
+"                                     Allowed values: none; extreme (xz);\n"
+"                                     filtered, huffman, rle, fixed (gzip).\n"
 "\n"));
 
   printf(_(

+ 28 - 1
lib/dpkg/compress.c

@@ -180,10 +180,22 @@ compress_gzip(int fd_in, int fd_out, struct compress_params *params, const char
 {
 	char buffer[DPKG_BUFFER_SIZE];
 	char combuf[6];
+	int strategy;
 	int z_errnum;
 	gzFile gzfile;
 
-	snprintf(combuf, sizeof(combuf), "w%d", params->level);
+	if (params->strategy == compressor_strategy_filtered)
+		strategy = 'f';
+	else if (params->strategy == compressor_strategy_huffman)
+		strategy = 'h';
+	else if (params->strategy == compressor_strategy_rle)
+		strategy = 'R';
+	else if (params->strategy == compressor_strategy_fixed)
+		strategy = 'F';
+	else
+		strategy = ' ';
+
+	snprintf(combuf, sizeof(combuf), "w%d%c", params->level, strategy);
 	gzfile = gzdopen(fd_out, combuf);
 	if (gzfile == NULL)
 		ohshit(_("%s: error binding output to gzip stream"), desc);
@@ -742,6 +754,14 @@ compressor_get_strategy(const char *name)
 {
 	if (strcmp(name, "none") == 0)
 		return compressor_strategy_none;
+	if (strcmp(name, "filtered") == 0)
+		return compressor_strategy_filtered;
+	if (strcmp(name, "huffman") == 0)
+		return compressor_strategy_huffman;
+	if (strcmp(name, "rle") == 0)
+		return compressor_strategy_rle;
+	if (strcmp(name, "fixed") == 0)
+		return compressor_strategy_fixed;
 	if (strcmp(name, "extreme") == 0)
 		return compressor_strategy_extreme;
 
@@ -754,6 +774,13 @@ compressor_check_params(struct compress_params *params, struct dpkg_error *err)
 	if (params->strategy == compressor_strategy_none)
 		return true;
 
+	if (params->type == compressor_type_gzip &&
+	    (params->strategy == compressor_strategy_filtered ||
+	     params->strategy == compressor_strategy_huffman ||
+	     params->strategy == compressor_strategy_rle ||
+	     params->strategy == compressor_strategy_fixed))
+		return true;
+
 	if (params->type == compressor_type_xz &&
 	    params->strategy == compressor_strategy_extreme)
 		return true;

+ 4 - 0
lib/dpkg/compress.h

@@ -47,6 +47,10 @@ enum compressor_type {
 enum compressor_strategy {
 	compressor_strategy_unknown = -1,
 	compressor_strategy_none,
+	compressor_strategy_filtered,
+	compressor_strategy_huffman,
+	compressor_strategy_rle,
+	compressor_strategy_fixed,
 	compressor_strategy_extreme,
 };
 

+ 2 - 1
man/dpkg-deb.1

@@ -224,7 +224,8 @@ equivalent to compressor none for all compressors.
 .BI \-S compress-strategy
 Specify which compression strategy to use on the compressor backend, when
 building a package (since dpkg 1.16.2). Allowed values are \fInone\fP (since
-dpkg 1.16.4) and \fIextreme\fP for xz.
+dpkg 1.16.4), \fIfiltered\fP, \fIhuffman\fP, \fIrle\fP and \fIfixed\fP for
+gzip (since dpkg 1.17.0) and \fIextreme\fP for xz.
 .TP
 .BI \-Z compress-type
 Specify which compression type to use when building a package. Allowed