]> git.saurik.com Git - apt.git/commitdiff
merged from lp:~mvo/apt/mvo
authorMichael Vogt <michael.vogt@ubuntu.com>
Mon, 1 Aug 2011 11:57:28 +0000 (13:57 +0200)
committerMichael Vogt <michael.vogt@ubuntu.com>
Mon, 1 Aug 2011 11:57:28 +0000 (13:57 +0200)
apt-pkg/contrib/fileutl.cc
apt-pkg/contrib/fileutl.h
apt-pkg/pkgcachegen.cc
apt-pkg/pkgcachegen.h
apt-pkg/sourcelist.cc
apt-pkg/sourcelist.h
debian/changelog

index 50019872e3d3e16fbe81df2698025644e5eac4b3..85dc6f6006a7ed963dd017459b8c19e65bf442ac 100644 (file)
@@ -446,6 +446,17 @@ string SafeGetCWD()
    return S;
 }
                                                                        /*}}}*/
+// GetModificationTime - Get the mtime of the given file or -1 on error /*{{{*/
+// ---------------------------------------------------------------------
+/* We return / on failure. */
+time_t GetModificationTime(string const &Path)
+{
+   struct stat St;
+   if (stat(Path.c_str(), &St) < 0)
+      return -1;
+   return  St.st_mtime;
+}
+                                                                       /*}}}*/
 // flNotDir - Strip the directory from the filename                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
index cde288ad20e7787dc2993a07844f42a5d918fd92..a1b177f385364e1b7c3dc0fa5923913c84a9a5f6 100644 (file)
@@ -97,6 +97,7 @@ bool FileExists(string File);
 bool RealFileExists(string File);
 bool DirectoryExists(string const &Path) __attrib_const;
 bool CreateDirectory(string const &Parent, string const &Path);
+time_t GetModificationTime(string const &Path);
 
 /** \brief Ensure the existence of the given Path
  *
index 8f9737e265e9de696b225cd7f6867e47e177d775..2bfb776095f4a1deda5190d2a073bf450eb209dd 100644 (file)
@@ -105,6 +105,9 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
    if (oldMap == newMap)
       return;
 
+   if (_config->FindB("Debug::pkgCacheGen", false))
+      std::clog << "Remaping from " << oldMap << " to " << newMap << std::endl;
+
    Cache.ReMap(false);
 
    CurrentFile += (pkgCache::PackageFile*) newMap - (pkgCache::PackageFile*) oldMap;
@@ -633,7 +636,9 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
            Dynamic<pkgCache::VerIterator> DynV(V);
            for (; V.end() != true; V++)
            {
-              char const * const Arch = P.Arch();
+               // copy P.Arch() into a string here as a cache remap
+               // in NewDepends() later may alter the pointer location
+              string Arch = P.Arch() == NULL ? "" : P.Arch();
               map_ptrloc *OldDepLast = NULL;
               /* MultiArch handling introduces a lot of implicit Dependencies:
                - MultiArch: same → Co-Installable if they have the same version
@@ -684,7 +689,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
                                   string const &Version,
                                   unsigned int const &Op,
                                   unsigned int const &Type,
-                                  map_ptrloc *OldDepLast)
+                                  map_ptrloc* &OldDepLast)
 {
    void const * const oldMap = Map.Data();
    // Get a structure
@@ -915,8 +920,11 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
 /* This just verifies that each file in the list of index files exists,
    has matching attributes with the cache and the cache does not have
    any extra files. */
-static bool CheckValidity(const string &CacheFile, FileIterator Start, 
-                          FileIterator End,MMap **OutMap = 0)
+static bool CheckValidity(const string &CacheFile, 
+                          pkgSourceList &List,
+                          FileIterator Start, 
+                          FileIterator End,
+                          MMap **OutMap = 0)
 {
    bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
    // No file, certainly invalid
@@ -927,6 +935,13 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start,
       return false;
    }
 
+   if (List.GetLastModifiedTime() < GetModificationTime(CacheFile))
+   {
+      if (Debug == true)
+        std::clog << "sources.list is newer than the cache" << std::endl;
+      return false;
+   }
+
    // Map it
    FileFd CacheF(CacheFile,FileFd::ReadOnly);
    SPtr<MMap> Map = new MMap(CacheF,0);
@@ -1152,7 +1167,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
       Progress->OverallProgress(0,1,1,_("Reading package lists"));
 
    // Cache is OK, Fin.
-   if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true)
+   if (CheckValidity(CacheFile, List, Files.begin(),Files.end(),OutMap) == true)
    {
       if (Progress != NULL)
         Progress->OverallProgress(1,1,1,_("Reading package lists"));
@@ -1205,7 +1220,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    // Lets try the source cache.
    unsigned long CurrentSize = 0;
    unsigned long TotalSize = 0;
-   if (CheckValidity(SrcCacheFile,Files.begin(),
+   if (CheckValidity(SrcCacheFile, List, Files.begin(),
                     Files.begin()+EndOfSource) == true)
    {
       if (Debug == true)
index ff198833a801f9cd601e25980ff5470d303b5128..c260511826ab36dc94472aedc3b66d713d982712 100644 (file)
@@ -75,7 +75,7 @@ class pkgCacheGenerator                                                       /*{{{*/
    bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
    bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
                   string const &Version, unsigned int const &Op,
-                  unsigned int const &Type, map_ptrloc *OldDepLast);
+                  unsigned int const &Type, map_ptrloc* &OldDepLast);
    unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next);
    map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
 
index 851eefdfe7547c1090172685fd74cd3787fabeae..c96ccfd77e5adf3af1843ac58b7276d6045d62d6 100644 (file)
@@ -341,4 +341,22 @@ bool pkgSourceList::ReadSourceDir(string Dir)
 
 }
                                                                        /*}}}*/
+// GetLastModified()                                           /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+time_t pkgSourceList::GetLastModifiedTime()
+{
+   // go over the parts
+   string Main = _config->FindFile("Dir::Etc::sourcelist");
+   string Parts = _config->FindDir("Dir::Etc::sourceparts");
+   vector<string> const 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;
+}
+                                                                       /*}}}*/
 
index e15314a5e796fbd87a7eb1ded8101e6790bbdc8e..7b473ee64b453187a4f72a91267bfb5f586b7451 100644 (file)
@@ -92,6 +92,9 @@ class pkgSourceList
                  pkgIndexFile *&Found) const;
    bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
    
+   // query last-modified time
+   time_t GetLastModifiedTime();
+
    pkgSourceList();
    pkgSourceList(string File);
    ~pkgSourceList();      
index 8797117a7209dc27bfaaa862af4fc902d208b43a..75ac0832821f6b91474bf9a58d90ee28c86943c7 100644 (file)
@@ -1,3 +1,20 @@
+apt (0.8.15.5.6) UNRELEASED; urgency=low
+
+  * apt-pkg/contrib/fileutl.{cc,h}:
+    - add GetModificationTime() helper
+  * apt-pkg/pkgcachegen.cc:
+    - regenerate the cache if the sources.list changes to ensure
+      that changes in the ordering there will be honored by apt
+  * apt-pkg/sourcelist.{cc,h}:
+    - add pkgSourceList::GetLastModifiedTime() helper
+  * apt-pkg/pkgcachegen.{cc,h}:
+    - use ref-to-ptr semantic in NewDepends() to ensure that the   
+      libapt does not segfault if the cache is remapped in between
+      (LP: #812862)
+    - fix crash when P.Arch() was used but the cache got remapped
+
+ -- Michael Vogt <mvo@debian.org>  Tue, 12 Jul 2011 11:54:47 +0200
+
 apt (0.8.15.5) unstable; urgency=low
 
   [ David Kalnischkies ]