X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b0d408547734100bf86781615f546487ecf390d9..610e13842a3718128c03454c5dfcbde49d323281:/apt-pkg/sourcelist.cc?ds=sidebyside

diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index eef0ee709..82d2ed3c6 100644
--- a/apt-pkg/sourcelist.cc
+++ b/apt-pkg/sourcelist.cc
@@ -11,6 +11,7 @@
 #include<config.h>
 
 #include <apt-pkg/sourcelist.h>
+#include <apt-pkg/cmndline.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
@@ -20,6 +21,7 @@
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/debindexfile.h>
 
 #include <ctype.h>
 #include <stddef.h>
@@ -107,6 +109,8 @@ bool pkgSourceList::Type::ParseStanza(vector<metaIndex *> &List,	/*{{{*/
    mapping.insert(std::make_pair("Valid-Until-Min", std::make_pair("valid-until-min", false)));
    mapping.insert(std::make_pair("Valid-Until-Max", std::make_pair("valid-until-max", false)));
    mapping.insert(std::make_pair("Signed-By", std::make_pair("signed-by", false)));
+   mapping.insert(std::make_pair("PDiffs", std::make_pair("pdiffs", false)));
+   mapping.insert(std::make_pair("By-Hash", std::make_pair("by-hash", false)));
 
    for (std::map<char const * const, std::pair<char const * const, bool> >::const_iterator m = mapping.begin(); m != mapping.end(); ++m)
       if (Tags.Exists(m->first))
@@ -118,6 +122,12 @@ bool pkgSourceList::Type::ParseStanza(vector<metaIndex *> &List,	/*{{{*/
 	 Options[m->second.first] = option;
       }
 
+   {
+      std::string entry;
+      strprintf(entry, "%s:%i", Fd.Name().c_str(), i);
+      Options["sourceslist-entry"] = entry;
+   }
+
    // now create one item per suite/section
    string Suite = Tags.FindS("Suites");
    Suite = SubstVar(Suite,"$(ARCH)",_config->Find("APT::Architecture"));
@@ -185,6 +195,11 @@ bool pkgSourceList::Type::ParseLine(vector<metaIndex *> &List,
    // Parse option field if it exists
    // e.g.: [ option1=value1 option2=value2 ]
    map<string, string> Options;
+   {
+      std::string entry;
+      strprintf(entry, "%s:%i", File.c_str(), CurLine);
+      Options["sourceslist-entry"] = entry;
+   }
    if (Buffer != 0 && Buffer[0] == '[')
    {
       ++Buffer; // ignore the [
@@ -274,6 +289,10 @@ pkgSourceList::~pkgSourceList()
 {
    for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I)
       delete *I;
+   SrcList.clear();
+   for (auto  F = VolatileFiles.begin(); F != VolatileFiles.end(); ++F)
+      delete (*F);
+   VolatileFiles.clear();
 }
 									/*}}}*/
 // SourceList::ReadMainList - Read the main source list from etc	/*{{{*/
@@ -317,7 +336,7 @@ void pkgSourceList::Reset()
 {
    for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I)
       delete *I;
-   SrcList.erase(SrcList.begin(),SrcList.end());
+   SrcList.clear();
 }
 									/*}}}*/
 // SourceList::Read - Parse the sourcelist file				/*{{{*/
@@ -339,7 +358,7 @@ bool pkgSourceList::ReadAppend(string const &File)
    else
       return ParseFileOldStyle(File);
 }
-
+									/*}}}*/
 // SourceList::ReadFileOldStyle - Read Traditional style sources.list 	/*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -380,7 +399,7 @@ bool pkgSourceList::ParseFileOldStyle(std::string const &File)
 	 continue;
 
       // Grok it
-      std::string const LineType = Buffer.substr(0, Buffer.find(' '));
+      std::string const LineType = Buffer.substr(0, Buffer.find_first_of(" \t\v"));
       if (LineType.empty() || LineType == Buffer)
 	 return _error->Error(_("Malformed line %u in source list %s (type)"),CurLine,File.c_str());
 
@@ -399,16 +418,16 @@ bool pkgSourceList::ParseFileOldStyle(std::string const &File)
 /* Returns: the number of stanzas parsed*/
 bool pkgSourceList::ParseFileDeb822(string const &File)
 {
-   pkgUserTagSection Tags;
    unsigned int i = 1;
 
    // see if we can read the file
    FileFd Fd(File, FileFd::ReadOnly);
-   pkgTagFile Sources(&Fd);
-   if (_error->PendingError() == true)
+   pkgTagFile Sources(&Fd, pkgTagFile::SUPPORT_COMMENTS);
+   if (Fd.IsOpen() == false || Fd.Failed())
       return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str());
 
    // read step by step
+   pkgTagSection Tags;
    while (Sources.Step(Tags) == true)
    {
       if(Tags.Exists("Types") == false)
@@ -436,26 +455,26 @@ bool pkgSourceList::ParseFileDeb822(string const &File)
 }
 									/*}}}*/
 // SourceList::FindIndex - Get the index associated with a file		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
+static bool FindInIndexFileContainer(std::vector<pkgIndexFile *> const &Cont, pkgCache::PkgFileIterator const &File, pkgIndexFile *&Found)
+{
+   auto const J = std::find_if(Cont.begin(), Cont.end(), [&File](pkgIndexFile const * const J) {
+	 return J->FindInCache(*File.Cache()) == File;
+   });
+   if (J != Cont.end())
+   {
+      Found = (*J);
+      return true;
+   }
+   return false;
+}
 bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File,
 			      pkgIndexFile *&Found) const
 {
    for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I)
-   {
-      vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
-      for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
-	   J != Indexes->end(); ++J)
-      {
-         if ((*J)->FindInCache(*File.Cache()) == File)
-         {
-            Found = (*J);
-            return true;
-         }
-      }
-   }
+      if (FindInIndexFileContainer(*(*I)->GetIndexFiles(), File, Found))
+	 return true;
 
-   return false;
+   return FindInIndexFileContainer(VolatileFiles, File, Found);
 }
 									/*}}}*/
 // SourceList::GetIndexes - Load the index files into the downloader	/*{{{*/
@@ -504,11 +523,59 @@ time_t pkgSourceList::GetLastModifiedTime()
       List = GetListOfFilesInDir(Parts, "list", true);
 
    // calculate the time
-   time_t mtime_sources = GetModificationTime(Main);
-   for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I)
-      mtime_sources = std::max(mtime_sources, GetModificationTime(*I));
-
-   return mtime_sources;
+   std::vector<time_t> modtimes;
+   modtimes.reserve(1 + List.size());
+   modtimes.push_back(GetModificationTime(Main));
+   std::transform(List.begin(), List.end(), std::back_inserter(modtimes), GetModificationTime);
+   auto const maxmtime = std::max_element(modtimes.begin(), modtimes.end());
+   return *maxmtime;
 }
 									/*}}}*/
+std::vector<pkgIndexFile*> pkgSourceList::GetVolatileFiles() const	/*{{{*/
+{
+   return VolatileFiles;
+}
+									/*}}}*/
+void pkgSourceList::AddVolatileFile(pkgIndexFile * const File)		/*{{{*/
+{
+   if (File != nullptr)
+      VolatileFiles.push_back(File);
+}
+									/*}}}*/
+bool pkgSourceList::AddVolatileFile(std::string const &File)		/*{{{*/
+{
+   // Note: FileExists matches directories and links, too!
+   if (File.empty() || FileExists(File) == false)
+      return false;
+
+   std::string const ext = flExtension(File);
+   if (ext == "deb")
+      AddVolatileFile(new debDebPkgFileIndex(File));
+   else if (ext == "dsc")
+      AddVolatileFile(new debDscFileIndex(File));
+   else if (FileExists(flCombine(File, "debian/control")))
+      AddVolatileFile(new debDscFileIndex(flCombine(File, "debian/control")));
+   else
+      return false;
 
+   return true;
+}
+									/*}}}*/
+void pkgSourceList::AddVolatileFiles(CommandLine &CmdL, std::vector<const char*> * const VolatileCmdL)/*{{{*/
+{
+   std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const * const I) {
+      if (I != nullptr && (I[0] == '/' || (I[0] == '.' && ((I[1] == '.' && I[2] == '/') || I[1] == '/'))))
+      {
+	 if (AddVolatileFile(I))
+	 {
+	    if (VolatileCmdL != nullptr)
+	       VolatileCmdL->push_back(I);
+	 }
+	 else
+	    _error->Error(_("Unsupported file %s given on commandline"), I);
+	 return true;
+      }
+      return false;
+   });
+}
+									/*}}}*/