From 2ec858bc68bc2d79ec020fe24be2d76b7c5b6792 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Jul 2011 15:16:18 +0200 Subject: * 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/contrib/fileutl.cc | 11 +++++++++++ apt-pkg/contrib/fileutl.h | 1 + apt-pkg/pkgcachegen.cc | 18 ++++++++++++++---- apt-pkg/sourcelist.cc | 18 ++++++++++++++++++ apt-pkg/sourcelist.h | 3 +++ debian/changelog | 7 +++++++ 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 50019872e..85dc6f600 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -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 /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index cde288ad2..a1b177f38 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -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 * diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 9820fde81..d0ea2e6e3 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/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, 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 +930,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 Map = new MMap(CacheF,0); @@ -1152,7 +1162,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")); @@ -1189,7 +1199,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) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 851eefdfe..c96ccfd77 100644 --- a/apt-pkg/sourcelist.cc +++ b/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 const List = GetListOfFilesInDir(Parts, "list", true); + + // calculate the time + time_t mtime_sources = GetModificationTime(Main); + for (vector::const_iterator I = List.begin(); I != List.end(); I++) + mtime_sources = std::max(mtime_sources, GetModificationTime(*I)); + + return mtime_sources; +} + /*}}}*/ diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index e15314a5e..7b473ee64 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -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(); diff --git a/debian/changelog b/debian/changelog index 0f8035a78..3e1a619ac 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,13 @@ apt (0.8.15.2) unstable; urgency=high - add new DeEscapeString() similar to DeQuoteString but unescape character escapes like \0XX and \xXX (plus added 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 Tue, 12 Jul 2011 11:54:47 +0200 -- cgit v1.2.3 From 64dda04bd949ab73ca77732fcc5149cc7c2a5557 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 29 Jul 2011 13:37:33 +0200 Subject: * 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) --- apt-pkg/pkgcachegen.cc | 5 ++++- apt-pkg/pkgcachegen.h | 2 +- debian/changelog | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index d0ea2e6e3..ebcbfdd25 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -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; @@ -684,7 +687,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 diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index ff198833a..c26051182 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -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); diff --git a/debian/changelog b/debian/changelog index 3e1a619ac..a8c757233 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,10 @@ apt (0.8.15.2) unstable; urgency=high 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) -- Michael Vogt Tue, 12 Jul 2011 11:54:47 +0200 -- cgit v1.2.3 From 77de0e831a12aedde05ff6bff8fb07dcbb4074ad Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 1 Aug 2011 12:57:04 +0200 Subject: apt-pkg/pkgcachegen.cc: copy Arch to avoid segfault on cache remap --- apt-pkg/pkgcachegen.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index efd764b51..2bfb77609 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -636,7 +636,9 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress) Dynamic 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 -- cgit v1.2.3