From de6221c9d5f99a276628bcf45fb28537e46e7660 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 27 May 2014 17:49:53 +0200 Subject: Do not try to cast a pkgDepCache::Policy to a pkgCache Fix incorrect cast in pkgDepCache::Policy::GetCandidateVer() Reported-By: clang -fsanitize=address -fno-omit-frame-pointer --- apt-pkg/depcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 19a6e0d7e..aa96ac58f 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1678,7 +1678,7 @@ pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator const &Pk { /* Not source/not automatic versions cannot be a candidate version unless they are already installed */ - VerIterator Last(*(pkgCache *)this,0); + VerIterator Last; for (VerIterator I = Pkg.VersionList(); I.end() == false; ++I) { -- cgit v1.2.3 From e41d3d7e25754f858b6dfe4dd841f4749f7f3ab1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 Jun 2014 22:46:37 +0200 Subject: do not revert candidate for protected packages In commit 21b3eac8 I promoted the check for installable dependencies to a pre-install check, which also reverts to a known good candidate (the installed version) if it fails. This revert was done even for user requested candidate switches which disabled our Broken detection so that install requests which are impossible to satisfy do not fail anymore, but print an (incomplete) solution proposal and then exit successfully. Closes: 745046 --- apt-pkg/depcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index aa96ac58f..c25672d1c 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1374,7 +1374,7 @@ bool pkgDepCache::IsInstallOkDependenciesSatisfiableByCandidates(PkgIterator con // the dependency is critical, but can't be installed, so discard the candidate // as the problemresolver will trip over it otherwise trying to install it (#735967) - if (Pkg->CurrentVer != 0) + if (Pkg->CurrentVer != 0 && (PkgState[Pkg->ID].iFlags & Protected) != Protected) SetCandidateVersion(Pkg.CurrentVer()); return false; } -- cgit v1.2.3 From 7a66977486804d46d5860f568cbd80f54f0c42d0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 13 Jun 2014 08:35:32 +0200 Subject: remove the Section member from package struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A version belongs to a section and has hence a section member of its own. A package on the other hand can have multiple versions from different sections. This was "solved" by using the section which was parsed first as order of sources.list defines, but that is obviously a horribly unpredictable thing. We therefore directly remove this struct member to free some space and mark the access method as deprecated, which is told to return the section of the 'newest' known version, which is at least predictable, but possible not what it returned before – but nobody knows. Users are way better of with the Section() as returned by the version they are dealing with. It is likely the same for all versions of a package, but in the few cases it isn't, it is important (like packages moving from main/* to contrib/* or into oldlibs …). --- apt-pkg/depcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index c25672d1c..492d16029 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1225,7 +1225,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, continue; } // now check if we should consider it a automatic dependency or not - if(InstPkg->CurrentVer == 0 && Pkg->Section != 0 && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg.Section())) + if(InstPkg->CurrentVer == 0 && InstVer->Section != 0 && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", InstVer.Section())) { if(DebugAutoInstall == true) std::clog << OutputInDepth(Depth) << "Setting NOT as auto-installed (direct " -- cgit v1.2.3 From fb4c76436a88a04d1d9b7e9622e431ed8ab708a6 Mon Sep 17 00:00:00 2001 From: Warren He Date: Fri, 29 Aug 2014 11:15:30 +0200 Subject: initialize iPolicyBrokenCount in DepCache::Update All other counters are correctly initialized here, expect this one. The practical effect is low as in apt we usually just do "!= 0" checks, but only correct counters are good counters. Closes: 758397 --- apt-pkg/depcache.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index c25672d1c..42e31396b 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -663,10 +663,11 @@ void pkgDepCache::Update(OpProgress *Prog) { iUsrSize = 0; iDownloadSize = 0; - iDelCount = 0; iInstCount = 0; + iDelCount = 0; iKeepCount = 0; iBrokenCount = 0; + iPolicyBrokenCount = 0; iBadCount = 0; // Perform the depends pass -- cgit v1.2.3 From 107d054ba954d05965f793f560468c6c453cc2a5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 3 Oct 2014 00:20:57 +0200 Subject: implement MarkAndSweep in cc instead of header Having it in the header exposes some implementation details, namely private methods and will cause problems for us if we ever want to change the actions. Git-Dch: Ignore --- apt-pkg/depcache.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 16282df21..1332f3ee2 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1961,3 +1961,17 @@ bool pkgDepCache::Sweep() /*{{{*/ return true; } /*}}}*/ +// DepCache::MarkAndSweep /*{{{*/ +bool pkgDepCache::MarkAndSweep(InRootSetFunc &rootFunc) +{ + return MarkRequired(rootFunc) && Sweep(); +} +bool pkgDepCache::MarkAndSweep() +{ + std::auto_ptr f(GetRootSetFunc()); + if(f.get() != NULL) + return MarkAndSweep(*f.get()); + else + return false; +} + /*}}}*/ -- cgit v1.2.3 From 1b671a9ba2e42e43f4cb1be86dc052823cf6961f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 14 Nov 2014 17:52:39 +0100 Subject: create directory for extended_states if needed Unlikely perhaps, but there is no guarantee that the directory we want to drop the file into actually exists, so create it if we must. --- apt-pkg/depcache.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 1332f3ee2..25c945ebb 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -237,9 +237,11 @@ bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly) /*{{ FileFd StateFile; string const state = _config->FindFile("Dir::State::extended_states"); + if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), flNotFile(state)) == false) + return false; // if it does not exist, create a empty one - if(!RealFileExists(state)) + if(!RealFileExists(state)) { StateFile.Open(state, FileFd::WriteAtomic); StateFile.Close(); -- cgit v1.2.3 From 98c9c26c123aa1ef6ad01b0bb60c782b920ce3b3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 9 May 2015 12:39:22 +0200 Subject: show non-matching m-a:same versions in debug message Slightly rewriting the code to ensure we only use two sources for the versions as it could otherwise be confusing to look at. --- apt-pkg/depcache.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 25c945ebb..73c5bb320 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1315,14 +1315,18 @@ bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, GrpIterator const Grp = Pkg.Group(); for (PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) { - // not installed or version synced: fine by definition + // not installed or self-check: fine by definition + if (P->CurrentVer == 0 || P == Pkg) + continue; + + // not having a candidate or being in sync // (simple string-compare as stuff like '1' == '0:1-0' can't happen here) - if (P->CurrentVer == 0 || strcmp(Pkg.CandVersion(), P.CandVersion()) == 0) + VerIterator CV = PkgState[P->ID].CandidateVerIter(*this); + if (CV.end() == true || strcmp(Pkg.CandVersion(), CV.VerStr()) == 0) continue; + // packages losing M-A:same can be out-of-sync - VerIterator CV = PkgState[P->ID].CandidateVerIter(*this); - if (unlikely(CV.end() == true) || - (CV->MultiArch & pkgCache::Version::Same) != pkgCache::Version::Same) + if ((CV->MultiArch & pkgCache::Version::Same) != pkgCache::Version::Same) continue; // not downloadable means the package is obsolete, so allow out-of-sync @@ -1332,7 +1336,8 @@ bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, PkgState[Pkg->ID].iFlags |= AutoKept; if (unlikely(DebugMarker == true)) std::clog << OutputInDepth(Depth) << "Ignore MarkInstall of " << Pkg - << " as its M-A:same siblings are not version-synced" << std::endl; + << " as it is not in sync with its M-A:same sibling " << P + << " (" << Pkg.CandVersion() << " != " << CV.VerStr() << ")" << std::endl; return false; } -- cgit v1.2.3 From 88593886a42025d51d76051da5929b044e42efee Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 11 May 2015 15:08:08 +0200 Subject: rewrite all TFRewrite instances to use the new pkgTagSection::Write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it is mostly busywork to rewrite all instances it actually fixes bugs as the data storage used by the new method is std::string rather than a char*, the later mostly created by c_str() from a std::string which the caller has to ensure keeps in scope – something apt-ftparchive actually didn't ensure and relied on copy-on-write behavior instead which c++11 forbids and hence the new default gcc abi doesn't use it. --- apt-pkg/depcache.cc | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 73c5bb320..b73c336db 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -252,17 +251,14 @@ bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly) /*{{ return _error->Error(_("Failed to open StateFile %s"), state.c_str()); - FILE *OutFile; - string const outfile = state + ".tmp"; - if((OutFile = fopen(outfile.c_str(),"w")) == NULL) - return _error->Error(_("Failed to write temporary StateFile %s"), - outfile.c_str()); + FileFd OutFile(state, FileFd::ReadWrite | FileFd::Atomic); + if (OutFile.IsOpen() == false || OutFile.Failed() == true) + return _error->Error(_("Failed to write temporary StateFile %s"), state.c_str()); // first merge with the existing sections pkgTagFile tagfile(&StateFile); pkgTagSection section; std::set pkgs_seen; - const char *nullreorderlist[] = {0}; while(tagfile.Step(section)) { string const pkgname = section.FindS("Package"); string pkgarch = section.FindS("Architecture"); @@ -271,7 +267,7 @@ bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly) /*{{ // Silently ignore unknown packages and packages with no actual // version. pkgCache::PkgIterator pkg = Cache->FindPkg(pkgname, pkgarch); - if(pkg.end() || pkg.VersionList().end()) + if(pkg.end() || pkg.VersionList().end()) continue; StateCache const &P = PkgState[pkg->ID]; bool newAuto = (P.Flags & Flag::Auto); @@ -292,21 +288,17 @@ bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly) /*{{ if(_config->FindB("Debug::pkgAutoRemove",false)) std::clog << "Update existing AutoInstall info: " << pkg.FullName() << std::endl; - TFRewriteData rewrite[3]; - rewrite[0].Tag = "Architecture"; - rewrite[0].Rewrite = pkg.Arch(); - rewrite[0].NewTag = 0; - rewrite[1].Tag = "Auto-Installed"; - rewrite[1].Rewrite = newAuto ? "1" : "0"; - rewrite[1].NewTag = 0; - rewrite[2].Tag = 0; - TFRewrite(OutFile, section, nullreorderlist, rewrite); - fprintf(OutFile,"\n"); + + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Rewrite("Architecture", pkg.Arch())); + rewrite.push_back(pkgTagSection::Tag::Rewrite("Auto-Installed", newAuto ? "1" : "0")); + section.Write(OutFile, NULL, rewrite); + if (OutFile.Write("\n", 1) == false) + return false; pkgs_seen.insert(pkg.FullName()); } - + // then write the ones we have not seen yet - std::ostringstream ostr; for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); ++pkg) { StateCache const &P = PkgState[pkg->ID]; if(P.Flags & Flag::Auto) { @@ -325,19 +317,17 @@ bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly) /*{{ continue; if(debug_autoremove) std::clog << "Writing new AutoInstall: " << pkg.FullName() << std::endl; - ostr.str(string("")); - ostr << "Package: " << pkg.Name() - << "\nArchitecture: " << pkgarch - << "\nAuto-Installed: 1\n\n"; - fprintf(OutFile,"%s",ostr.str().c_str()); + std::string stanza = "Package: "; + stanza.append(pkg.Name()) + .append("\nArchitecture: ").append(pkgarch) + .append("\nAuto-Installed: 1\n\n"); + if (OutFile.Write(stanza.c_str(), stanza.length()) == false) + return false; } } - fclose(OutFile); - - // move the outfile over the real file and set permissions - rename(outfile.c_str(), state.c_str()); + if (OutFile.Close() == false) + return false; chmod(state.c_str(), 0644); - return true; } /*}}}*/ -- cgit v1.2.3