diff options
author | David Kalnischkies <david@kalnischkies.de> | 2015-12-22 16:32:56 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2015-12-22 16:35:06 +0100 |
commit | 7a68effcb904b4424b54a30e448b6f2560cd1078 (patch) | |
tree | 873af8bdf70d61175f9223e6bf33a5c3eda1640b /apt-pkg/contrib/fileutl.cc | |
parent | 885a1ffd27e621d7cd2452b39e2053e2f1044253 (diff) |
parse xz-compression level from configuration
If we use the library to compress xz, still try to understand and pick
up the arguments we would have used to call xz to figure out which level
the user wants us to use instead of defaulting to level 6 (which is the
default level of xz).
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 11b0e658d..ca2710a79 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1253,6 +1253,32 @@ class LzmaFileFdPrivate: public FileFdPrivate { /*{{{*/ } }; LZMAFILE* lzma; + static uint32_t findXZlevel(std::vector<std::string> const &Args) + { + for (auto a = Args.rbegin(); a != Args.rend(); ++a) + if (a->empty() == false && (*a)[0] == '-' && (*a)[1] != '-') + { + auto const number = a->find_last_of("0123456789"); + if (number == std::string::npos) + continue; + auto const extreme = a->find("e", number); + uint32_t level = (extreme != std::string::npos) ? LZMA_PRESET_EXTREME : 0; + switch ((*a)[number]) + { + case '0': return level | 0; + case '1': return level | 1; + case '2': return level | 2; + case '3': return level | 3; + case '4': return level | 4; + case '5': return level | 5; + case '6': return level | 6; + case '7': return level | 7; + case '8': return level | 8; + case '9': return level | 9; + } + } + return 6; + } public: virtual bool InternalOpen(int const iFd, unsigned int const Mode) override { @@ -1269,13 +1295,12 @@ public: if (lzma->file == nullptr) return false; - uint32_t const xzlevel = 6; - uint64_t const memlimit = UINT64_MAX; lzma_stream tmp_stream = LZMA_STREAM_INIT; lzma->stream = tmp_stream; if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly) { + uint32_t const xzlevel = findXZlevel(compressor.CompressArgs); if (compressor.Name == "xz") { if (lzma_easy_encoder(&lzma->stream, xzlevel, LZMA_CHECK_CRC64) != LZMA_OK) @@ -1292,6 +1317,7 @@ public: } else { + uint64_t const memlimit = UINT64_MAX; if (compressor.Name == "xz") { if (lzma_auto_decoder(&lzma->stream, memlimit, 0) != LZMA_OK) |