summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2020-12-02 15:51:09 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2021-02-02 19:56:46 +0100
commitf2c087449286812823d06d1b560fa947e438fa0d (patch)
tree97f9b02fb44ac8e19eaf5f65a5dd1f5871b9fa77 /apt-pkg/deb
parentb4b5e9bf97970e0efc4a994de96066a92e3a9b8f (diff)
Guess compressor only if no AR nember with exact name exists
Explicitly opening a tar member is a bit harder than it needs to be as you have to remove the compressor extension so that it can be guessed here gain potentially choosing the wrong member. Doesn't really matter for deb packages of course as the member count is pretty low and strongly defined, but testing is easier this way. It also finally fixes an incorrectly formatted error message.
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/debfile.cc59
1 files changed, 34 insertions, 25 deletions
diff --git a/apt-pkg/deb/debfile.cc b/apt-pkg/deb/debfile.cc
index bef0cd0d8..645a579ef 100644
--- a/apt-pkg/deb/debfile.cc
+++ b/apt-pkg/deb/debfile.cc
@@ -24,9 +24,12 @@
#include <apt-pkg/error.h>
#include <apt-pkg/extracttar.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
#include <apt-pkg/tagfile.h>
+#include <algorithm>
#include <string>
+#include <sstream>
#include <vector>
#include <string.h>
#include <sys/stat.h>
@@ -105,42 +108,48 @@ const ARArchive::Member *debDebFile::GotoMember(const char *Name)
/* Simple wrapper around tar.. */
bool debDebFile::ExtractTarMember(pkgDirStream &Stream,const char *Name)
{
- // Get the archive member
- const ARArchive::Member *Member = NULL;
std::string Compressor;
+ auto const Compressors = APT::Configuration::getCompressors();
- std::vector<APT::Configuration::Compressor> compressor = APT::Configuration::getCompressors();
- for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
- c != compressor.end(); ++c)
+ ARArchive::Member const *Member = AR.FindMember(Name);
+ if (Member != nullptr)
{
- Member = AR.FindMember(std::string(Name).append(c->Extension).c_str());
- if (Member == NULL)
- continue;
- Compressor = c->Name;
- break;
+ auto const found = std::find_if(Compressors.cbegin(), Compressors.cend(), [&](auto const &c) {
+ return not c.Extension.empty() && APT::String::Endswith(Name, c.Extension);
+ });
+ if (found != Compressors.cend())
+ Compressor = found->Name;
}
-
- if (Member == NULL)
- Member = AR.FindMember(std::string(Name).c_str());
-
- if (Member == NULL)
+ else
{
- std::string ext = std::string(Name) + ".{";
- for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
- c != compressor.end(); ++c) {
- if (!c->Extension.empty())
- ext.append(c->Extension.substr(1));
+ for (auto const &c : Compressors)
+ {
+ if (c.Extension.empty())
+ continue;
+ Member = AR.FindMember(std::string(Name).append(c.Extension).c_str());
+ if (Member == nullptr)
+ continue;
+ Compressor = c.Name;
+ break;
}
- ext.append("}");
- return _error->Error(_("Internal error, could not locate member %s"), ext.c_str());
}
- if (File.Seek(Member->Start) == false)
+ if (Member == nullptr)
+ {
+ std::ostringstream ext;
+ ext << Name << '{';
+ for (auto const &c : Compressors)
+ if (not c.Extension.empty())
+ ext << c.Extension << ',';
+ ext << '}';
+ return _error->Error(_("Internal error, could not locate member %s"), ext.str().c_str());
+ }
+
+ if (not File.Seek(Member->Start))
return false;
- // Prepare Tar
ExtractTar Tar(File,Member->Size,Compressor);
- if (_error->PendingError() == true)
+ if (_error->PendingError())
return false;
return Tar.Go(Stream);
}