Quellcode durchsuchen

* 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

Michael Vogt vor 15 Jahren
Ursprung
Commit
2ec858bc68
6 geänderte Dateien mit 54 neuen und 4 gelöschten Zeilen
  1. 11 0
      apt-pkg/contrib/fileutl.cc
  2. 1 0
      apt-pkg/contrib/fileutl.h
  3. 14 4
      apt-pkg/pkgcachegen.cc
  4. 18 0
      apt-pkg/sourcelist.cc
  5. 3 0
      apt-pkg/sourcelist.h
  6. 7 0
      debian/changelog

+ 11 - 0
apt-pkg/contrib/fileutl.cc

@@ -446,6 +446,17 @@ string SafeGetCWD()
    return S;
    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			/*{{{*/
 // flNotDir - Strip the directory from the filename			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */

+ 1 - 0
apt-pkg/contrib/fileutl.h

@@ -97,6 +97,7 @@ bool FileExists(string File);
 bool RealFileExists(string File);
 bool RealFileExists(string File);
 bool DirectoryExists(string const &Path) __attrib_const;
 bool DirectoryExists(string const &Path) __attrib_const;
 bool CreateDirectory(string const &Parent, string const &Path);
 bool CreateDirectory(string const &Parent, string const &Path);
+time_t GetModificationTime(string const &Path);
 
 
 /** \brief Ensure the existence of the given Path
 /** \brief Ensure the existence of the given Path
  *
  *

+ 14 - 4
apt-pkg/pkgcachegen.cc

@@ -915,8 +915,11 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
 /* This just verifies that each file in the list of index files exists,
 /* 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
    has matching attributes with the cache and the cache does not have
    any extra files. */
    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);
    bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
    // No file, certainly invalid
    // No file, certainly invalid
@@ -927,6 +930,13 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start,
       return false;
       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
    // Map it
    FileFd CacheF(CacheFile,FileFd::ReadOnly);
    FileFd CacheF(CacheFile,FileFd::ReadOnly);
    SPtr<MMap> Map = new MMap(CacheF,0);
    SPtr<MMap> Map = new MMap(CacheF,0);
@@ -1152,7 +1162,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
       Progress->OverallProgress(0,1,1,_("Reading package lists"));
       Progress->OverallProgress(0,1,1,_("Reading package lists"));
 
 
    // Cache is OK, Fin.
    // 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)
       if (Progress != NULL)
 	 Progress->OverallProgress(1,1,1,_("Reading package lists"));
 	 Progress->OverallProgress(1,1,1,_("Reading package lists"));
@@ -1189,7 +1199,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    // Lets try the source cache.
    // Lets try the source cache.
    unsigned long CurrentSize = 0;
    unsigned long CurrentSize = 0;
    unsigned long TotalSize = 0;
    unsigned long TotalSize = 0;
-   if (CheckValidity(SrcCacheFile,Files.begin(),
+   if (CheckValidity(SrcCacheFile, List, Files.begin(),
 		     Files.begin()+EndOfSource) == true)
 		     Files.begin()+EndOfSource) == true)
    {
    {
       if (Debug == true)
       if (Debug == true)

+ 18 - 0
apt-pkg/sourcelist.cc

@@ -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;
+}
+									/*}}}*/
 
 

+ 3 - 0
apt-pkg/sourcelist.h

@@ -92,6 +92,9 @@ class pkgSourceList
 		  pkgIndexFile *&Found) const;
 		  pkgIndexFile *&Found) const;
    bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
    bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
    
    
+   // query last-modified time
+   time_t GetLastModifiedTime();
+
    pkgSourceList();
    pkgSourceList();
    pkgSourceList(string File);
    pkgSourceList(string File);
    ~pkgSourceList();      
    ~pkgSourceList();      

+ 7 - 0
debian/changelog

@@ -10,6 +10,13 @@ apt (0.8.15.2) unstable; urgency=high
     - add new DeEscapeString() similar to DeQuoteString but
     - add new DeEscapeString() similar to DeQuoteString but
       unescape character escapes like \0XX and \xXX (plus added
       unescape character escapes like \0XX and \xXX (plus added
       test)
       test)
+  * 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
 
 
  -- Michael Vogt <mvo@debian.org>  Tue, 12 Jul 2011 11:54:47 +0200
  -- Michael Vogt <mvo@debian.org>  Tue, 12 Jul 2011 11:54:47 +0200