Przeglądaj źródła

dpkg-deb: Add compression strategy support

The only currently supported option is “extreme” for xz.

Closes: #647915
Guillem Jover 14 lat temu
rodzic
commit
584c3b4036
6 zmienionych plików z 66 dodań i 1 usunięć
  1. 2 0
      debian/changelog
  2. 1 0
      dpkg-deb/build.c
  3. 8 0
      dpkg-deb/main.c
  4. 43 1
      lib/dpkg/compress.c
  5. 7 0
      lib/dpkg/compress.h
  6. 5 0
      man/dpkg-deb.1

+ 2 - 0
debian/changelog

@@ -37,6 +37,8 @@ dpkg (1.16.2) UNRELEASED; urgency=low
   * Treat dpkg-deb compression level independently for each backend. This
     has the effect of changing the current behaviour for level 0 on all
     compressors except gzip.
+  * Add new dpkg-deb -S option to specify the compression strategy. The only
+    currently supported value is “extreme” for xz. Closes: #647915
 
   [ Raphaël Hertzog ]
   * Update Dpkg::Shlibs to look into multiarch paths when cross-building

+ 1 - 0
dpkg-deb/build.c

@@ -479,6 +479,7 @@ do_build(const char *const *argv)
 
     params.type = compressor_type_gzip;
     params.level = 9;
+    params.strategy = NULL;
 
     compress_filter(&params, p1[0], gzfd, _("control member"));
     exit(0);

+ 8 - 0
dpkg-deb/main.c

@@ -106,6 +106,8 @@ usage(const struct cmdinfo *cip, const char *value)
 "  -z#                              Set the compression level when building.\n"
 "  -Z<type>                         Set the compression type used when building.\n"
 "                                     Allowed types: gzip, xz, bzip2, lzma, none.\n"
+"  -S<strategy>                     Set the compression strategy when building.\n"
+"                                     Allowed values: extreme (xz).\n"
 "\n"));
 
   printf(_(
@@ -137,6 +139,7 @@ int opt_verbose = 0;
 struct compress_params compress_params = {
   .type = compressor_type_gzip,
   .level = -1,
+  .strategy = NULL,
 };
 
 static void
@@ -182,6 +185,7 @@ static const struct cmdinfo cmdinfos[]= {
   { "nocheck",       0,   0, &nocheckflag,   NULL,         NULL,          1 },
   { "compression",   'z', 1, NULL,           NULL,         set_compress_level },
   { "compress_type", 'Z', 1, NULL,           NULL,         setcompresstype  },
+  { NULL,            'S', 1, NULL,           &compress_params.strategy, NULL },
   { "showformat",    0,   1, NULL,           &showformat,  NULL             },
   { "help",          'h', 0, NULL,           NULL,         usage            },
   { "version",       0,   0, NULL,           NULL,         printversion     },
@@ -189,6 +193,7 @@ static const struct cmdinfo cmdinfos[]= {
 };
 
 int main(int argc, const char *const *argv) {
+  struct dpkg_error err;
   int ret;
 
   setlocale(LC_NUMERIC, "POSIX");
@@ -202,6 +207,9 @@ int main(int argc, const char *const *argv) {
 
   if (!cipaction) badusage(_("need an action option"));
 
+  if (!compressor_check_params(&compress_params, &err))
+    badusage(_("invalid compressor parameters: %s"), err.str);
+
   unsetenv("GZIP");
 
   ret = cipaction->action(argv);

+ 43 - 1
lib/dpkg/compress.c

@@ -37,6 +37,7 @@
 
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
+#include <dpkg/error.h>
 #include <dpkg/varbuf.h>
 #include <dpkg/fdio.h>
 #include <dpkg/buffer.h>
@@ -77,6 +78,8 @@ struct compressor {
 	const char *name;
 	const char *extension;
 	int default_level;
+	bool (*check_params)(struct compress_params *params,
+	                     struct dpkg_error *err);
 	void (*fixup_params)(struct compress_params *params);
 	void (*compress)(int fd_in, int fd_out, struct compress_params *params,
 	                 const char *desc);
@@ -87,6 +90,17 @@ struct compressor {
  * No compressor (pass-through).
  */
 
+static bool
+check_none_params(struct compress_params *params, struct dpkg_error *err)
+{
+	if (params->strategy) {
+		dpkg_put_warn(err, _("unknown compression strategy"));
+		return false;
+	}
+
+	return true;
+}
+
 static void
 fixup_none_params(struct compress_params *params)
 {
@@ -108,6 +122,7 @@ static const struct compressor compressor_none = {
 	.name = "none",
 	.extension = "",
 	.default_level = 0,
+	.check_params = check_none_params,
 	.fixup_params = fixup_none_params,
 	.compress = compress_none,
 	.decompress = decompress_none,
@@ -225,6 +240,7 @@ static const struct compressor compressor_gzip = {
 	.name = "gzip",
 	.extension = ".gz",
 	.default_level = 9,
+	.check_params = check_none_params,
 	.fixup_params = fixup_gzip_params,
 	.compress = compress_gzip,
 	.decompress = decompress_gzip,
@@ -347,6 +363,7 @@ static const struct compressor compressor_bzip2 = {
 	.name = "bzip2",
 	.extension = ".bz2",
 	.default_level = 9,
+	.check_params = check_none_params,
 	.fixup_params = fixup_bzip2_params,
 	.compress = compress_bzip2,
 	.decompress = decompress_bzip2,
@@ -356,6 +373,17 @@ static const struct compressor compressor_bzip2 = {
  * Xz compressor.
  */
 
+static bool
+check_xz_params(struct compress_params *params, struct dpkg_error *err)
+{
+	if (params->strategy && strcmp(params->strategy, "extreme") != 0) {
+		dpkg_put_warn(err, _("unknown compression strategy"));
+		return false;
+	}
+
+	return true;
+}
+
 static void
 decompress_xz(int fd_in, int fd_out, const char *desc)
 {
@@ -366,15 +394,22 @@ static void
 compress_xz(int fd_in, int fd_out, struct compress_params *params, const char *desc)
 {
 	char combuf[6];
+	const char *strategy;
+
+	if (params->strategy && strcmp(params->strategy, "extreme") == 0)
+		strategy = "-e";
+	else
+		strategy = NULL;
 
 	snprintf(combuf, sizeof(combuf), "-c%d", params->level);
-	fd_fd_filter(fd_in, fd_out, desc, XZ, combuf, NULL);
+	fd_fd_filter(fd_in, fd_out, desc, XZ, combuf, strategy, NULL);
 }
 
 static const struct compressor compressor_xz = {
 	.name = "xz",
 	.extension = ".xz",
 	.default_level = 6,
+	.check_params = check_xz_params,
 	.fixup_params = fixup_none_params,
 	.compress = compress_xz,
 	.decompress = decompress_xz,
@@ -403,6 +438,7 @@ static const struct compressor compressor_lzma = {
 	.name = "lzma",
 	.extension = ".lzma",
 	.default_level = 6,
+	.check_params = check_none_params,
 	.fixup_params = fixup_none_params,
 	.compress = compress_lzma,
 	.decompress = decompress_lzma,
@@ -461,6 +497,12 @@ compressor_find_by_extension(const char *extension)
 	return compressor_type_unknown;
 }
 
+bool
+compressor_check_params(struct compress_params *params, struct dpkg_error *err)
+{
+	return compressor_get(params->type)->check_params(params, err);
+}
+
 static void
 compressor_fixup_params(struct compress_params *params)
 {

+ 7 - 0
lib/dpkg/compress.h

@@ -23,6 +23,9 @@
 #define LIBDPKG_COMPRESS_H
 
 #include <dpkg/macros.h>
+#include <dpkg/error.h>
+
+#include <stdbool.h>
 
 DPKG_BEGIN_DECLS
 
@@ -41,6 +44,7 @@ enum compressor_type {
 
 struct compress_params {
 	enum compressor_type type;
+	const char *strategy;
 	int level;
 };
 
@@ -49,6 +53,9 @@ enum compressor_type compressor_find_by_extension(const char *name);
 
 const char *compressor_get_extension(enum compressor_type type);
 
+bool compressor_check_params(struct compress_params *params,
+                             struct dpkg_error *err);
+
 void decompress_filter(enum compressor_type type, int fd_in, int fd_out,
                        const char *desc, ...)
                        DPKG_ATTR_PRINTF(4);

+ 5 - 0
man/dpkg-deb.1

@@ -201,6 +201,11 @@ The accepted values are 0-9 with: 0 being mapped to compressor none for
 gzip and 0 mapped to 1 for bzip2. Before dpkg 1.16.2 level 0 was
 equivalent to compressor none for all compressors.
 .TP
+.BI \-S compress-strategy
+Specify which compression stratregy to use on the compressor backend, when
+building a package (since dpkg 1.16.2). Allowed value is \fIextreme\fP for
+xz.
+.TP
 .BI \-Z compress-type
 Specify which compression type to use when building a package. Allowed
 values are \fIgzip\fP, \fIxz\fP, \fIbzip2\fP, \fIlzma\fP, and \fInone\fP