From 6089a4b17c61ef30b2efc00e270b0907f51f352a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 6 May 2019 12:22:42 +0200 Subject: Use debDebFile to get control file instead of dpkg-deb --- apt-pkg/deb/debindexfile.cc | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 25e0a3312..279f35a38 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -10,7 +10,9 @@ // Include Files /*{{{*/ #include +#include #include +#include #include #include #include @@ -172,36 +174,23 @@ bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &de if (stat(debfile.c_str(), &Buf) != 0) return false; - // get the control data out of the deb file via dpkg-deb -I - std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg-deb"); - std::vector Args; - Args.push_back(dpkg.c_str()); - Args.push_back("-I"); - Args.push_back(debfile.c_str()); - Args.push_back("control"); - Args.push_back(NULL); - FileFd PipeFd; - pid_t Child; - if(Popen((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false) - return _error->Error("Popen failed"); + FileFd debFd(debfile, FileFd::ReadOnly); + debDebFile deb(debFd); + debDebFile::MemControlExtract extractor("control"); - std::string line; - bool first_line_seen = false; - while (PipeFd.ReadLine(line)) - { - if (first_line_seen == false) - { - if (line.empty()) - continue; - first_line_seen = true; - } - else if (line.empty()) - break; - content << line << "\n"; - } + if (not extractor.Read(deb)) + return _error->Error(_("Could not read meta data from %s"), debfile.c_str()); + + // trim off newlines + while (extractor.Control[extractor.Length] == '\n') + extractor.Control[extractor.Length--] = '\0'; + const char *Control = extractor.Control; + while (isspace_ascii(Control[0])) + Control++; + + content << Control; content << "Filename: " << debfile << "\n"; content << "Size: " << std::to_string(Buf.st_size) << "\n"; - ExecWait(Child, "Popen"); return true; } -- cgit v1.2.3