]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/debindexfile.cc
support long keyid and fingerprint in gpgv's GOODSIG
[apt.git] / apt-pkg / deb / debindexfile.cc
index d3599b35369bf09679e58b4a464c217a5f558f7f..c55847305ff96c4038c64eae425a6b173f0d28e2 100644 (file)
 #include <stdio.h>
 #include <iostream>
 #include <string>
 #include <stdio.h>
 #include <iostream>
 #include <string>
+#include <sstream>
 
 #include <sys/stat.h>
 
 #include <sys/stat.h>
+#include <unistd.h>
                                                                        /*}}}*/
 
 // Sources Index                                                       /*{{{*/
                                                                        /*}}}*/
 
 // Sources Index                                                       /*{{{*/
@@ -79,7 +81,11 @@ debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted
 std::string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator const &Ver) const
 {
    std::string Res = Target.Description;
 std::string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator const &Ver) const
 {
    std::string Res = Target.Description;
-   Res.erase(Target.Description.rfind(' '));
+   {
+      auto const space = Target.Description.rfind(' ');
+      if (space != std::string::npos)
+        Res.erase(space);
+   }
 
    Res += " ";
    Res += Ver.ParentPkg().Name();
 
    Res += " ";
    Res += Ver.ParentPkg().Name();
@@ -120,12 +126,18 @@ std::string debTranslationsIndex::GetArchitecture() const
 pkgCacheListParser * debTranslationsIndex::CreateListParser(FileFd &Pkg)
 {
    if (Pkg.IsOpen() == false)
 pkgCacheListParser * debTranslationsIndex::CreateListParser(FileFd &Pkg)
 {
    if (Pkg.IsOpen() == false)
-      return NULL;
+      return nullptr;
    _error->PushToStack();
    pkgCacheListParser * const Parser = new debTranslationsParser(&Pkg);
    bool const newError = _error->PendingError();
    _error->MergeWithStack();
    _error->PushToStack();
    pkgCacheListParser * const Parser = new debTranslationsParser(&Pkg);
    bool const newError = _error->PendingError();
    _error->MergeWithStack();
-   return newError ? NULL : Parser;
+   if (newError)
+   {
+      delete Parser;
+      return nullptr;
+   }
+   else
+      return Parser;
 }
                                                                        /*}}}*/
 // dpkg/status Index                                                   /*{{{*/
 }
                                                                        /*}}}*/
 // dpkg/status Index                                                   /*{{{*/
@@ -144,6 +156,23 @@ uint8_t debStatusIndex::GetIndexFlags() const
 {
    return pkgCache::Flag::NotSource;
 }
 {
    return pkgCache::Flag::NotSource;
 }
+
+pkgCacheListParser * debStatusIndex::CreateListParser(FileFd &Pkg)
+{
+   if (Pkg.IsOpen() == false)
+      return nullptr;
+   _error->PushToStack();
+   pkgCacheListParser * const Parser = new debStatusListParser(&Pkg);
+   bool const newError = _error->PendingError();
+   _error->MergeWithStack();
+   if (newError)
+   {
+      delete Parser;
+      return nullptr;
+   }
+   else
+      return Parser;
+}
                                                                        /*}}}*/
 // DebPkgFile Index - a single .deb file as an index                   /*{{{*/
 debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile)
                                                                        /*}}}*/
 // DebPkgFile Index - a single .deb file as an index                   /*{{{*/
 debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile)
@@ -169,6 +198,9 @@ bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &de
    if(Popen((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
       return _error->Error("Popen failed");
 
    if(Popen((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
       return _error->Error("Popen failed");
 
+   content << "Filename: " << debfile << "\n";
+   content << "Size: " << std::to_string(Buf.st_size) << "\n";
+   bool first_line_seen = false;
    char buffer[1024];
    do {
       unsigned long long actual = 0;
    char buffer[1024];
    do {
       unsigned long long actual = 0;
@@ -177,13 +209,19 @@ bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &de
       if (actual == 0)
         break;
       buffer[actual] = '\0';
       if (actual == 0)
         break;
       buffer[actual] = '\0';
-      content << buffer;
+      char const * b = buffer;
+      if (first_line_seen == false)
+      {
+        for (; *b != '\0' && (*b == '\n' || *b == '\r'); ++b)
+           /* skip over leading newlines */;
+        if (*b == '\0')
+           continue;
+        first_line_seen = true;
+      }
+      content << b;
    } while(true);
    ExecWait(Child, "Popen");
 
    } while(true);
    ExecWait(Child, "Popen");
 
-   content << "Filename: " << debfile << "\n";
-   content << "Size: " << Buf.st_size << "\n";
-
    return true;
 }
 bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
    return true;
 }
 bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
@@ -204,12 +242,18 @@ bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
 pkgCacheListParser * debDebPkgFileIndex::CreateListParser(FileFd &Pkg)
 {
    if (Pkg.IsOpen() == false)
 pkgCacheListParser * debDebPkgFileIndex::CreateListParser(FileFd &Pkg)
 {
    if (Pkg.IsOpen() == false)
-      return NULL;
+      return nullptr;
    _error->PushToStack();
    pkgCacheListParser * const Parser = new debDebFileParser(&Pkg, DebFile);
    bool const newError = _error->PendingError();
    _error->MergeWithStack();
    _error->PushToStack();
    pkgCacheListParser * const Parser = new debDebFileParser(&Pkg, DebFile);
    bool const newError = _error->PendingError();
    _error->MergeWithStack();
-   return newError ? NULL : Parser;
+   if (newError)
+   {
+      delete Parser;
+      return nullptr;
+   }
+   else
+      return Parser;
 }
 uint8_t debDebPkgFileIndex::GetIndexFlags() const
 {
 }
 uint8_t debDebPkgFileIndex::GetIndexFlags() const
 {
@@ -237,7 +281,14 @@ pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const
 
    return File;
 }
 
    return File;
 }
-
+std::string debDebPkgFileIndex::ArchiveInfo_impl(pkgCache::VerIterator const &Ver) const
+{
+   std::string Res = IndexFileName() + " ";
+   Res.append(Ver.ParentPkg().Name()).append(" ");
+   Res.append(Ver.Arch()).append(" ");
+   Res.append(Ver.VerStr());
+   return Res;
+}
                                                                        /*}}}*/
 // DscFile Index - a single .dsc file as an index                      /*{{{*/
 debDscFileIndex::debDscFileIndex(std::string const &DscFile)
                                                                        /*}}}*/
 // DscFile Index - a single .dsc file as an index                      /*{{{*/
 debDscFileIndex::debDscFileIndex(std::string const &DscFile)
@@ -249,6 +300,57 @@ pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
    if (Exists() == false)
       return NULL;
    return new debDscRecordParser(File, this);
    if (Exists() == false)
       return NULL;
    return new debDscRecordParser(File, this);
+}
+std::string debDscFileIndex::GetComponent() const
+{
+   return "local-dsc";
+}
+std::string debDscFileIndex::GetArchitecture() const
+{
+   return "source";
+}
+uint8_t debDscFileIndex::GetIndexFlags() const
+{
+   return pkgCache::Flag::LocalSource;
+}
+                                                                       /*}}}*/
+// ControlFile Index - a directory with a debian/control file          /*{{{*/
+std::string debDebianSourceDirIndex::GetComponent() const
+{
+   return "local-control";
+}
+                                                                       /*}}}*/
+// String Package Index - a string of Packages file content            /*{{{*/
+std::string debStringPackageIndex::GetArchitecture() const
+{
+   return std::string();
+}
+std::string debStringPackageIndex::GetComponent() const
+{
+   return "apt-tmp-index";
+}
+uint8_t debStringPackageIndex::GetIndexFlags() const
+{
+   return pkgCache::Flag::NotSource;
+}
+const pkgIndexFile::Type *debStringPackageIndex::GetType() const
+{
+   return pkgIndexFile::Type::GetType("Debian Package Index");
+}
+debStringPackageIndex::debStringPackageIndex(std::string const &content) :
+   pkgDebianIndexRealFile("", false), d(NULL)
+{
+   char fn[1024];
+   std::string const tempdir = GetTempDir();
+   snprintf(fn, sizeof(fn), "%s/%s.XXXXXX", tempdir.c_str(), "apt-tmp-index");
+   int const fd = mkstemp(fn);
+   File = fn;
+   FileFd::Write(fd, content.data(), content.length());
+   close(fd);
+}
+debStringPackageIndex::~debStringPackageIndex()
+{
+   RemoveFile("~debStringPackageIndex", File);
 }
                                                                        /*}}}*/
 
 }
                                                                        /*}}}*/