The following commit has been merged in the master branch:
commit 584c3b4036048cebd93c08a009f365d639025811
Author: Guillem Jover <[email protected]>
Date: Tue Nov 22 20:32:50 2011 +0100
dpkg-deb: Add compression strategy support
The only currently supported option is “extreme” for xz.
Closes: #647915
diff --git a/debian/changelog b/debian/changelog
index 190370b..d244605 100644
--- a/debian/changelog
+++ b/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
diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c
index d2bec9d..14f24d0 100644
--- a/dpkg-deb/build.c
+++ b/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(¶ms, p1[0], gzfd, _("control member"));
exit(0);
diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c
index 6d52bea..df61401 100644
--- a/dpkg-deb/main.c
+++ b/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);
diff --git a/lib/dpkg/compress.c b/lib/dpkg/compress.c
index fb761d5..2f4d302 100644
--- a/lib/dpkg/compress.c
+++ b/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)
{
diff --git a/lib/dpkg/compress.h b/lib/dpkg/compress.h
index 8ae4f7c..78ad430 100644
--- a/lib/dpkg/compress.h
+++ b/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);
diff --git a/man/dpkg-deb.1 b/man/dpkg-deb.1
index d5fc5b5..cd8ce30 100644
--- a/man/dpkg-deb.1
+++ b/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
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]