From 4264ebebe1826781e5b863a13041a6972ace01db Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 27 Jun 2011 14:34:00 +0100 Subject: Initial commit from my GSoC project. Added a verification function (VerifyConfigure) to the configuration methods. --- apt-pkg/packagemanager.cc | 91 +++++++++++++++++++++++++++++++++++++++++++++-- apt-pkg/packagemanager.h | 4 ++- 2 files changed, 92 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index fe9f6eb68..de7f410e6 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -278,7 +278,7 @@ bool pkgPackageManager::ConfigureAll() { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && Configure(Pkg) == false) + if (ConfigurePkgs == true && VerifyConfigure(Pkg) == false) return false; List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); @@ -313,7 +313,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && Configure(Pkg) == false) + if (ConfigurePkgs == true && VerifyConfigure(Pkg) == false) return false; List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); @@ -336,6 +336,93 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); return true; +} + +// PM::VerifyConfigure - Check configuration of dependancies /*{{{*/ +// --------------------------------------------------------------------- +/* This routine checks that all a packages dependancies have been + configured, before it is going to be configured. If this gives a warning + on a virtual package, it means that the package thats providing it is not + configured*/ +bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList) +{ + // If this is true at the end, then the package should not be configured + bool error=true; + // This holds the the OR status of the previous dependancy + bool previousOr=false; + + // First iterate through the dependancies of Pkg + for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false; D++) + { + + /* If the dependancy is of type Depends or PreDepends, we need to check it, but only if it is going to be + configured at some point */ + if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) { + + /* If the previous package and this package are OR dependancies, and the previous package satisfied the dependancy + then skip this dependancy as it is not relevent, this will repeat for the next package if the situation is the + same */ + if (previousOr && !error) { // As error has not been reset, this refers to the previous dependancy + previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; + continue; + } + + // Reset error + error = true; + + // Check thorugh all possible versions of this dependancy (D) + SPtrArray VList = D.AllTargets(); + for (Version **I = VList; *I != 0; I++) + { + VerIterator DepVer(Cache,*I); + PkgIterator DepPkg = DepVer.ParentPkg(); + VerIterator DepInstallVer(Cache,Cache[DepPkg].InstallVer); + + if (DepPkg.CurrentVer() == DepVer && !List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { + clog << "Version " << DepPkg.CurrentVer() << " is installed on the system, satifying this dependancy" << endl; + error=false; + break; + } + + if (Cache[DepPkg].InstallVer == DepVer && + (List->IsFlag(DepPkg,pkgOrderList::Configured) || OList.IsFlag(DepPkg,pkgOrderList::InList))) { + clog << "Version " << DepInstallVer.VerStr() << " is going to be installed on the system, satifying this dependancy" << endl; + error=false; + break; + } + } + + /* Only worry here if this package is a OR with the next, as even though this package does not satisfy the OR + the next one might */ + if (error && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) { + _error->Error("Package %s should not be configured because package %s is not configured",Pkg.Name(),D.TargetPkg().Name()); + return false; + /* If the previous package is a OR but not this package, but there is still an error then fail as it will not + be satisfied */ + } else if (error && previousOr && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) { + _error->Error("Package %s should not be configured because package %s (or any alternatives) are not configured",Pkg.Name(),D.TargetPkg().Name()); + return false; + } + + previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; + } else { + previousOr=false; + } + } + return true; +} + +// PM::VerifyAndConfigure - Check configuration of dependancies /*{{{*/ +// --------------------------------------------------------------------- +/* This routine verifies if a package can be configured and if so + configures it */ +bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList) +{ + if (VerifyConfigure(Pkg, OList)) + return Configure(Pkg); + else + return false; + } /*}}}*/ // PM::DepAdd - Add all dependents to the oder list /*{{{*/ diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index 053b4dc13..070b9c04b 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -73,7 +73,9 @@ class pkgPackageManager : protected pkgCache::Namespace bool SmartUnPack(PkgIterator Pkg); bool SmartUnPack(PkgIterator Pkg, bool const Immediate); bool SmartRemove(PkgIterator Pkg); - bool EarlyRemove(PkgIterator Pkg); + bool EarlyRemove(PkgIterator Pkg); + bool VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList); + bool VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList); // The Actual installation implementation virtual bool Install(PkgIterator /*Pkg*/,string /*File*/) {return false;}; -- cgit v1.2.3 From b9f3f1f93323cf5982ee3d9d361a11697a1ecc74 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 27 Jun 2011 14:52:41 +0100 Subject: Fixed missing argument in VerifyConfigure call. --- apt-pkg/packagemanager.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index de7f410e6..63becb370 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -278,7 +278,7 @@ bool pkgPackageManager::ConfigureAll() { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && VerifyConfigure(Pkg) == false) + if (ConfigurePkgs == true && VerifyConfigure(Pkg,OList) == false) return false; List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); @@ -313,7 +313,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && VerifyConfigure(Pkg) == false) + if (ConfigurePkgs == true && VerifyConfigure(Pkg,OList) == false) return false; List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); -- cgit v1.2.3 From b873565f6cdffee78d3a5a84d34b7efbda127c5b Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 27 Jun 2011 14:56:07 +0100 Subject: Removed temp debug lines. --- apt-pkg/packagemanager.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 63becb370..f49df8327 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -379,14 +379,12 @@ bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList) VerIterator DepInstallVer(Cache,Cache[DepPkg].InstallVer); if (DepPkg.CurrentVer() == DepVer && !List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { - clog << "Version " << DepPkg.CurrentVer() << " is installed on the system, satifying this dependancy" << endl; error=false; break; } if (Cache[DepPkg].InstallVer == DepVer && (List->IsFlag(DepPkg,pkgOrderList::Configured) || OList.IsFlag(DepPkg,pkgOrderList::InList))) { - clog << "Version " << DepInstallVer.VerStr() << " is going to be installed on the system, satifying this dependancy" << endl; error=false; break; } -- cgit v1.2.3 From cfcdf7fe9f8c925847fe8d8a18bb0996dd9391a5 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 2 Jul 2011 15:33:25 +0100 Subject: The modification to orderlist.cc is from a patch DonKult (David) gave me, The modifications to the packagemanager should fix the test-provides-gone-with-upgrade testcase. --- apt-pkg/orderlist.cc | 6 ++++++ apt-pkg/packagemanager.cc | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index ba43bc757..6dd494027 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -1073,6 +1073,12 @@ bool pkgOrderList::CheckDep(DepIterator D) just needs one */ if (D.IsNegative() == false) { + // ignore provides by older versions of this package + if (((D.Reverse() == false && Pkg == D.ParentPkg()) || + (D.Reverse() == true && Pkg == D.TargetPkg())) && + Cache[Pkg].InstallVer != *I) + continue; + /* Try to find something that does not have the after flag set if at all possible */ if (IsFlag(Pkg,After) == true) diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index f49df8327..2219f876a 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -575,6 +575,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) } bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) { + if (Debug == true) + clog << "SmartUnPack " << Pkg.Name() << endl; + // Check if it is already unpacked if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && Cache[Pkg].Keep() == true) @@ -674,6 +677,20 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } } } + + // Check for breaks + if (End->Type == pkgCache::Dep::DpkgBreaks) { + SPtrArray VList = End.AllTargets(); + for (Version **I = VList; *I != 0; I++) + { + VerIterator Ver(Cache,*I); + PkgIterator Pkg = Ver.ParentPkg(); + // Found a break, so unpack the package + if (List->IsNow(Pkg)) { + SmartUnPack(Pkg, false); + } + } + } } // Check for reverse conflicts. -- cgit v1.2.3 From ea974eaa32b3cdeae8c8f8fe53f255f0d439bd3e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 3 Jul 2011 20:45:07 +0100 Subject: Added debug output to package manager. --- apt-pkg/packagemanager.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 2219f876a..e367b0495 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -346,6 +346,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) configured*/ bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList) { + if (Debug == true) + clog << "VerifyConfigure " << Pkg.Name() << endl; + // If this is true at the end, then the package should not be configured bool error=true; // This holds the the OR status of the previous dependancy -- cgit v1.2.3 From e2ca62725f8c511e53cf6b3abeede435a59eae3f Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 4 Jul 2011 12:12:13 +0100 Subject: Added temp debug statement. --- apt-pkg/packagemanager.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index e367b0495..ab1b13de8 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -479,6 +479,8 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) continue; } + std::clog << OutputInDepth(Depth) << Pkg.Name() << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << std::endl; + // Not the install version if (Cache[Pkg].InstallVer != *I || (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) -- cgit v1.2.3 From 4e9ccfb2ff599b7a65ecec3c2f1383636f068f0c Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 5 Jul 2011 11:30:35 +0100 Subject: Removed some debug stuff, corrected the VerifyConfigure calls to VerifyAndConfigure --- apt-pkg/packagemanager.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index ab1b13de8..f0ad74ca8 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -278,7 +278,7 @@ bool pkgPackageManager::ConfigureAll() { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && VerifyConfigure(Pkg,OList) == false) + if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false) return false; List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); @@ -313,7 +313,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && VerifyConfigure(Pkg,OList) == false) + if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false) return false; List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); @@ -346,9 +346,6 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) configured*/ bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList) { - if (Debug == true) - clog << "VerifyConfigure " << Pkg.Name() << endl; - // If this is true at the end, then the package should not be configured bool error=true; // This holds the the OR status of the previous dependancy @@ -419,7 +416,7 @@ bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList) configures it */ bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList) { - if (VerifyConfigure(Pkg, OList)) + if (VerifyConfigure(Pkg, OList)) return Configure(Pkg); else return false; @@ -472,15 +469,13 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) PkgIterator Pkg = Ver.ParentPkg(); // See if the current version is ok - if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && + if (Pkg.CurrentVer() == Ver && List->IsFlag(Pkg,pkgOrderList::Configured) == true && Pkg.State() == PkgIterator::NeedsNothing) { Bad = false; continue; } - std::clog << OutputInDepth(Depth) << Pkg.Name() << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << std::endl; - // Not the install version if (Cache[Pkg].InstallVer != *I || (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) -- cgit v1.2.3 From 55c04aa4c9f9704137822fac3a8392280667dfb6 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 5 Jul 2011 13:04:30 +0100 Subject: Changed check in the SmartUnpack method, reverted change in the DepAdd method. --- apt-pkg/packagemanager.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index f0ad74ca8..ac11b5d51 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -469,7 +469,7 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) PkgIterator Pkg = Ver.ParentPkg(); // See if the current version is ok - if (Pkg.CurrentVer() == Ver && List->IsFlag(Pkg,pkgOrderList::Configured) == true && + if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && Pkg.State() == PkgIterator::NeedsNothing) { Bad = false; @@ -685,8 +685,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); - // Found a break, so unpack the package - if (List->IsNow(Pkg)) { + // Check if it needs to be unpacked + if (List->IsFlag(Pkg,pkgOrderList::InList) && Cache[Pkg].Delete() == false) { + // Found a break, so unpack the package SmartUnPack(Pkg, false); } } -- cgit v1.2.3 From d8a982700668dd0d5ecf98c47b0ee5f224f4f8f4 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 5 Jul 2011 14:14:24 +0100 Subject: Fix for reinstallation of packages --- apt-pkg/packagemanager.cc | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 7fcaa8d41..4cba19dc0 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -475,17 +475,11 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) Bad = false; continue; } - - // Check if this package is being re-installed - if ((Cache[Pkg].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall && Cache[Pkg].InstallVer != *I && - List->IsNow(Pkg) == true && Pkg.State() == PkgIterator::NeedsNothing) { - Bad = false; - continue; - } - + // Not the install version if (Cache[Pkg].InstallVer != *I || - (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) + (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing && + (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) continue; if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == true) -- cgit v1.2.3 From 8b1f5756624cf30c59c708c102cc71d53188e737 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 5 Jul 2011 16:20:09 +0100 Subject: Flag the package in the SmartUnPack method as UnPacked while solving breakages to prevent loops. --- apt-pkg/packagemanager.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 4cba19dc0..a39e412bd 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -685,11 +685,15 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) for (Version **I = VList; *I != 0; I++) { VerIterator Ver(Cache,*I); - PkgIterator Pkg = Ver.ParentPkg(); + PkgIterator BrokenPkg = Ver.ParentPkg(); // Check if it needs to be unpacked - if (List->IsFlag(Pkg,pkgOrderList::InList) && Cache[Pkg].Delete() == false) { + if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && + !List->IsFlag(BrokenPkg,pkgOrderList::UnPacked)) { + /* FIXME Setting the flag here prevents breakage loops, that can occur if BrokenPkg (or one of the + packages it breaks) breaks Pkg */ + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); // Found a break, so unpack the package - SmartUnPack(Pkg, false); + SmartUnPack(BrokenPkg, false); } } } -- cgit v1.2.3 From a6c8798a6390b5c3a0775f8914e1cff2795e4cc1 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 6 Jul 2011 22:13:59 +0100 Subject: Added a APT::Immediate-Configure-All option to enable imediate configuration for all packages. Began adding to the SmartUnpack method to prevent dependancy loops breaking apt. --- apt-pkg/packagemanager.cc | 105 +++++++++++++++++++++++++++++++++++++++++----- apt-pkg/packagemanager.h | 1 + 2 files changed, 95 insertions(+), 11 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index a39e412bd..ad59470ac 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -167,6 +167,10 @@ bool pkgPackageManager::CreateOrderList() List = new pkgOrderList(&Cache); static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); + ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",true); + + if (Debug && ImmConfigureAll) + clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl; // Generate the list of affected packages and sort it for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) @@ -176,19 +180,23 @@ bool pkgPackageManager::CreateOrderList() continue; // Mark the package and its dependends for immediate configuration - if (((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential || + if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) && - NoImmConfigure == false) + NoImmConfigure == false) || ImmConfigureAll) { - if(Debug) + if(Debug && !ImmConfigureAll) clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl; List->Flag(I,pkgOrderList::Immediate); + + if (!ImmConfigureAll) { + continue; - // Look for other install packages to make immediate configurea - ImmediateAdd(I, true); + // Look for other install packages to make immediate configurea + ImmediateAdd(I, true); - // And again with the current version. - ImmediateAdd(I, false); + // And again with the current version. + ImmediateAdd(I, false); + } } // Not interesting @@ -467,7 +475,33 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); - + VerIterator InstallVer(Cache,Cache[Pkg].InstallVer); + + if (Debug) { + if (Ver==0) { + cout << OutputInDepth(Depth) << "Checking if the dependancy on " << Ver << " of " << Pkg.Name() << " is satisfied" << endl; + } else { + cout << OutputInDepth(Depth) << "Checking if the dependancy on " << Ver.VerStr() << " of " << Pkg.Name() << " is satisfied" << endl; + } + } + if (Debug) { + if (Pkg.CurrentVer()==0) { + cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl; + } else { + cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl; + } + } + + if (Debug) { + if (InstallVer==0) { + cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer << endl; + } else { + cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer.VerStr() << endl; + } + } + if (Debug) + cout << OutputInDepth(Depth) << " Keep " << Cache[Pkg].Keep() << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(Pkg,pkgOrderList::Configured) << endl; + // See if the current version is ok if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && Pkg.State() == PkgIterator::NeedsNothing) @@ -475,6 +509,8 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) Bad = false; continue; } + + // Keep() , if upgradable, is the package left at the install version // Not the install version if (Cache[Pkg].InstallVer != *I || @@ -591,7 +627,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name()); return true; } - + VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* See if this packages install version has any predependencies @@ -655,7 +691,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) End.TargetPkg().Name(),Pkg.Name()); Start++; } - else + else break; } @@ -693,10 +729,56 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) packages it breaks) breaks Pkg */ List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); // Found a break, so unpack the package + if (Debug) + cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; SmartUnPack(BrokenPkg, false); } } } + + // Check for dependanices that have not been unpacked, probably due to loops. + bool Bad = true; + while (End->Type == pkgCache::Dep::Depends) { + PkgIterator DepPkg; + SPtrArray VList = Start.AllTargets(); + + for (Version **I = VList; *I != 0; I++) { + VerIterator Ver(Cache,*I); + DepPkg = Ver.ParentPkg(); + + if (!Bad) continue; + + if (Debug) + cout << " Checking dep on " << DepPkg.Name() << endl; + // Check if it satisfies this dependancy + if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && + DepPkg.State() == PkgIterator::NeedsNothing) + { + Bad = false; + continue; + } + + if (Cache[DepPkg].InstallVer == *I && !List->IsNow(DepPkg)) { + Bad = false; + continue; + } + } + + if (Start==End) { + if (Bad) { + // FIXME Setting the flag here prevents a loop forming + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + // Found a break, so unpack the package + if (Debug) + cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + //SmartUnPack(DepPkg, false); + } + break; + + } else { + Start++; + } + } } // Check for reverse conflicts. @@ -728,7 +810,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) if (SmartConfigure(Pkg) == false) - return _error->Error(_("Could not perform immediate configuration on '%s'. " + //return + _error->Error(_("Could not perform immediate configuration on '%s'. " "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); return true; diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index 070b9c04b..dcc9dc2a2 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -48,6 +48,7 @@ class pkgPackageManager : protected pkgCache::Namespace pkgDepCache &Cache; pkgOrderList *List; bool Debug; + bool ImmConfigureAll; /** \brief saves packages dpkg let disappear -- cgit v1.2.3 From 9fc57a5900275aa7d32b1b433c1413d0e1a4b9e2 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 13 Jul 2011 09:12:19 +0100 Subject: More changes to the SmartUnpack method to allow imediate configuration of all packages. --- apt-pkg/packagemanager.cc | 209 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 155 insertions(+), 54 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index ad59470ac..38e0a0e1f 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -476,32 +476,32 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); VerIterator InstallVer(Cache,Cache[Pkg].InstallVer); + VerIterator CandVer(Cache,Cache[Pkg].CandidateVer); - if (Debug) { + if (Debug && false) { if (Ver==0) { - cout << OutputInDepth(Depth) << "Checking if the dependancy on " << Ver << " of " << Pkg.Name() << " is satisfied" << endl; + cout << OutputInDepth(Depth) << "Checking if " << Ver << " of " << Pkg.Name() << " satisfies this dependancy" << endl; } else { - cout << OutputInDepth(Depth) << "Checking if the dependancy on " << Ver.VerStr() << " of " << Pkg.Name() << " is satisfied" << endl; + cout << OutputInDepth(Depth) << "Checking if " << Ver.VerStr() << " of " << Pkg.Name() << " satisfies this dependancy" << endl; } - } - if (Debug) { + if (Pkg.CurrentVer()==0) { cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl; } else { cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl; } - } - - if (Debug) { + if (InstallVer==0) { cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer << endl; } else { cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer.VerStr() << endl; } - } - if (Debug) + if (CandVer != 0) + cout << " CandVer " << CandVer.VerStr() << endl; + cout << OutputInDepth(Depth) << " Keep " << Cache[Pkg].Keep() << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(Pkg,pkgOrderList::Configured) << endl; + } // See if the current version is ok if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && Pkg.State() == PkgIterator::NeedsNothing) @@ -510,10 +510,8 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) continue; } - // Keep() , if upgradable, is the package left at the install version - // Not the install version - if (Cache[Pkg].InstallVer != *I || + if ((Cache[Pkg].InstallVer != *I && Cache[Pkg].CandidateVer != *I) || (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing && (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) continue; @@ -642,7 +640,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) while (End->Type == pkgCache::Dep::PreDepends) { - if (Debug == true) + if (Debug) clog << "PreDepends order for " << Pkg.Name() << std::endl; // Look for possible ok targets. @@ -658,7 +656,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) Pkg.State() == PkgIterator::NeedsNothing) { Bad = false; - if (Debug == true) + if (Debug) clog << "Found ok package " << Pkg.Name() << endl; continue; } @@ -675,7 +673,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) continue; - if (Debug == true) + if (Debug) clog << "Trying to SmartConfigure " << Pkg.Name() << endl; Bad = !SmartConfigure(Pkg); } @@ -704,13 +702,48 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) for (Version **I = VList; *I != 0; I++) { VerIterator Ver(Cache,*I); - PkgIterator Pkg = Ver.ParentPkg(); + PkgIterator ConflictPkg = Ver.ParentPkg(); + VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer); + + if (Debug) + cout << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; + + if (Debug && false) { + if (Ver==0) { + cout << " Checking if " << Ver << " of " << ConflictPkg.Name() << " satisfies this dependancy" << endl; + } else { + cout << " Checking if " << Ver.VerStr() << " of " << ConflictPkg.Name() << " satisfies this dependancy" << endl; + } + + if (ConflictPkg.CurrentVer()==0) { + cout << " CurrentVer " << ConflictPkg.CurrentVer() << " IsNow " << List->IsNow(ConflictPkg) << " NeedsNothing " << (ConflictPkg.State() == PkgIterator::NeedsNothing) << endl; + } else { + cout << " CurrentVer " << ConflictPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(ConflictPkg) << " NeedsNothing " << (ConflictPkg.State() == PkgIterator::NeedsNothing) << endl; + } + + if (InstallVer==0) { + cout << " InstallVer " << InstallVer << endl; + } else { + cout << " InstallVer " << InstallVer.VerStr() << endl; + } + + cout << " Keep " << Cache[ConflictPkg].Keep() << " Unpacked " << List->IsFlag(ConflictPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(ConflictPkg,pkgOrderList::Configured) << endl; + cout << " Delete " << Cache[ConflictPkg].Delete() << endl; + } // See if the current version is conflicting - if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true) + if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) { - if (EarlyRemove(Pkg) == false) - return _error->Error("Internal Error, Could not early remove %s",Pkg.Name()); + if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { + cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; + /* FIXME Setting the flag here prevents breakage loops, that can occur if BrokenPkg (or one of the + packages it breaks) breaks Pkg */ + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + SmartUnPack(ConflictPkg,false); + } else { + if (EarlyRemove(ConflictPkg) == false) + return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); + } } } } @@ -733,13 +766,73 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; SmartUnPack(BrokenPkg, false); } + // Check if a package needs to be removed + if (Cache[BrokenPkg].Delete() == true) { + if (Debug) + cout << " Removing " << BrokenPkg.Name() << " to avoid break" << endl; + SmartRemove(BrokenPkg); + } } } + } + + // FIXME: Crude but effective fix, allows the SmartUnPack method to be used for packages that new to the system + if (instVer != 0) { + //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << instVer.VerStr() << endl; + + // Check for reverse conflicts. + if (CheckRConflicts(Pkg,Pkg.RevDependsList(), + instVer.VerStr()) == false) + return false; + + for (PrvIterator P = instVer.ProvidesList(); + P.end() == false; P++) + CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); + + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + + if (instVer->MultiArch == pkgCache::Version::Same) + for (PkgIterator P = Pkg.Group().PackageList(); + P.end() == false; P = Pkg.Group().NextPkg(P)) + { + if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true || + Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && + (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) + continue; + SmartUnPack(P, false); + } + } else { + VerIterator InstallVer(Cache,Cache[Pkg].InstallVer); + //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << InstallVer.VerStr() << endl; + + // Check for reverse conflicts. + if (CheckRConflicts(Pkg,Pkg.RevDependsList(), + InstallVer.VerStr()) == false) + return false; + + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + } + + if(Install(Pkg,FileNames[Pkg->ID]) == false) + return false; + + /* Because of the ordered list, most dependancies should be unpacked, + however if there is a loop this is not the case, so check for dependancies before configuring. + This is done after the package installation as it makes it easier to deal with conflicts problems */ + for (DepIterator D = instVer.DependsList(); + D.end() == false; ) + { + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start; + pkgCache::DepIterator End; + D.GlobOr(Start,End); + // Check for dependanices that have not been unpacked, probably due to loops. bool Bad = true; while (End->Type == pkgCache::Dep::Depends) { PkgIterator DepPkg; + VerIterator InstallVer; SPtrArray VList = Start.AllTargets(); for (Version **I = VList; *I != 0; I++) { @@ -747,9 +840,35 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) DepPkg = Ver.ParentPkg(); if (!Bad) continue; + + InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer); + VerIterator CandVer(Cache,Cache[DepPkg].CandidateVer); + + if (Debug && false) { + if (Ver==0) { + cout << " Checking if " << Ver << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; + } else { + cout << " Checking if " << Ver.VerStr() << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; + } + + if (DepPkg.CurrentVer()==0) { + cout << " CurrentVer " << DepPkg.CurrentVer() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; + } else { + cout << " CurrentVer " << DepPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; + } + + if (InstallVer==0) { + cout << " InstallVer " << InstallVer << endl; + } else { + cout << " InstallVer " << InstallVer.VerStr() << endl; + } + if (CandVer != 0) + cout << " CandVer " << CandVer.VerStr() << endl; - if (Debug) - cout << " Checking dep on " << DepPkg.Name() << endl; + cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << endl; + + } + // Check if it satisfies this dependancy if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && DepPkg.State() == PkgIterator::NeedsNothing) @@ -762,16 +881,23 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) Bad = false; continue; } + + } + + if (InstallVer != 0 && Bad) { + Bad = false; + // FIXME Setting the flag here prevents a loop forming + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + // Found a break, so unpack the package + if (Debug) + cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + SmartUnPack(DepPkg, false); } if (Start==End) { if (Bad) { - // FIXME Setting the flag here prevents a loop forming - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - // Found a break, so unpack the package - if (Debug) - cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; - //SmartUnPack(DepPkg, false); + //return + _error->Error("Could not satisfy dependancies for %s",Pkg.Name()); } break; @@ -781,31 +907,6 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } } - // Check for reverse conflicts. - if (CheckRConflicts(Pkg,Pkg.RevDependsList(), - instVer.VerStr()) == false) - return false; - - for (PrvIterator P = instVer.ProvidesList(); - P.end() == false; P++) - CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); - - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - - if (instVer->MultiArch == pkgCache::Version::Same) - for (PkgIterator P = Pkg.Group().PackageList(); - P.end() == false; P = Pkg.Group().NextPkg(P)) - { - if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true || - Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && - (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) - continue; - SmartUnPack(P, false); - } - - if(Install(Pkg,FileNames[Pkg->ID]) == false) - return false; - // Perform immedate configuration of the package. if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) @@ -900,7 +1001,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() PkgIterator(Cache,*I).Name()); return Failed; } - } + } return Completed; } -- cgit v1.2.3 From e2a5ff0c3398380b15a09d810effffc5eb96ea53 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 14 Jul 2011 13:26:19 +0100 Subject: More changes to make imediate configuration work for all packages, I have stolen the Loop flag from orderlist.cc as it didnt seem to use it anymore. --- apt-pkg/orderlist.cc | 4 +- apt-pkg/packagemanager.cc | 93 ++++++++++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 35 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index a17a70112..eaa5ea20a 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -1021,8 +1021,8 @@ bool pkgOrderList::AddLoop(DepIterator D) Loops[LoopCount++] = D; // Mark the packages as being part of a loop. - Flag(D.TargetPkg(),Loop); - Flag(D.ParentPkg(),Loop); + //Flag(D.TargetPkg(),Loop); + //Flag(D.ParentPkg(),Loop); return true; } /*}}}*/ diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 38e0a0e1f..601fbb484 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -167,7 +167,7 @@ bool pkgPackageManager::CreateOrderList() List = new pkgOrderList(&Cache); static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); - ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",true); + ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false); if (Debug && ImmConfigureAll) clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl; @@ -189,11 +189,9 @@ bool pkgPackageManager::CreateOrderList() List->Flag(I,pkgOrderList::Immediate); if (!ImmConfigureAll) { - continue; - // Look for other install packages to make immediate configurea ImmediateAdd(I, true); - + // And again with the current version. ImmediateAdd(I, false); } @@ -705,8 +703,11 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) PkgIterator ConflictPkg = Ver.ParentPkg(); VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer); - if (Debug) - cout << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; + // See if the current version is conflicting + if (ConflictPkg.CurrentVer() == Ver && !List->IsFlag(ConflictPkg,pkgOrderList::UnPacked)) + { + if (Debug && false) + cout << " " << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; if (Debug && false) { if (Ver==0) { @@ -727,23 +728,26 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) cout << " InstallVer " << InstallVer.VerStr() << endl; } - cout << " Keep " << Cache[ConflictPkg].Keep() << " Unpacked " << List->IsFlag(ConflictPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(ConflictPkg,pkgOrderList::Configured) << endl; + cout << " Keep " << Cache[ConflictPkg].Keep() << " Unpacked " << List->IsFlag(ConflictPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(ConflictPkg,pkgOrderList::Configured) << " Removed " << List->IsFlag(ConflictPkg,pkgOrderList::Removed) << " Loop " << List->IsFlag(ConflictPkg,pkgOrderList::Loop) << endl; cout << " Delete " << Cache[ConflictPkg].Delete() << endl; } - // See if the current version is conflicting - if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) - { - if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { - cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; - /* FIXME Setting the flag here prevents breakage loops, that can occur if BrokenPkg (or one of the - packages it breaks) breaks Pkg */ - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - SmartUnPack(ConflictPkg,false); - } else { - if (EarlyRemove(ConflictPkg) == false) - return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); - } + if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { + if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { + cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; + List->Flag(Pkg,pkgOrderList::Loop); + SmartUnPack(ConflictPkg,false); + } else { + if (EarlyRemove(ConflictPkg) == false) + return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); + } + } else { + if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) { + cout << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; + if (EarlyRemove(ConflictPkg) == false) + return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); + } + } } } } @@ -755,19 +759,42 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) { VerIterator Ver(Cache,*I); PkgIterator BrokenPkg = Ver.ParentPkg(); + VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); + + cout << " " << Pkg.Name() << " breaks " << BrokenPkg.Name() << endl; + if (Debug && false) { + if (Ver==0) { + cout << " Checking if " << Ver << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl; + } else { + cout << " Checking if " << Ver.VerStr() << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl; + } + + if (BrokenPkg.CurrentVer()==0) { + cout << " CurrentVer " << BrokenPkg.CurrentVer() << " IsNow " << List->IsNow(BrokenPkg) << " NeedsNothing " << (BrokenPkg.State() == PkgIterator::NeedsNothing) << endl; + } else { + cout << " CurrentVer " << BrokenPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(BrokenPkg) << " NeedsNothing " << (BrokenPkg.State() == PkgIterator::NeedsNothing) << endl; + } + + if (InstallVer==0) { + cout << " InstallVer " << InstallVer << endl; + } else { + cout << " InstallVer " << InstallVer.VerStr() << endl; + } + + cout << " Keep " << Cache[BrokenPkg].Keep() << " Unpacked " << List->IsFlag(BrokenPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(BrokenPkg,pkgOrderList::Configured) << " Removed " << List->IsFlag(BrokenPkg,pkgOrderList::Removed) << " Loop " << List->IsFlag(BrokenPkg,pkgOrderList::Loop) << " InList " << List->IsFlag(BrokenPkg,pkgOrderList::InList) << endl; + cout << " Delete " << Cache[BrokenPkg].Delete() << endl; + } // Check if it needs to be unpacked if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && - !List->IsFlag(BrokenPkg,pkgOrderList::UnPacked)) { - /* FIXME Setting the flag here prevents breakage loops, that can occur if BrokenPkg (or one of the - packages it breaks) breaks Pkg */ - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + !List->IsFlag(BrokenPkg,pkgOrderList::Loop) && List->IsNow(BrokenPkg)) { + List->Flag(Pkg,pkgOrderList::Loop); // Found a break, so unpack the package if (Debug) cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; SmartUnPack(BrokenPkg, false); } // Check if a package needs to be removed - if (Cache[BrokenPkg].Delete() == true) { + if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { if (Debug) cout << " Removing " << BrokenPkg.Name() << " to avoid break" << endl; SmartRemove(BrokenPkg); @@ -881,17 +908,17 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) Bad = false; continue; } - } if (InstallVer != 0 && Bad) { Bad = false; - // FIXME Setting the flag here prevents a loop forming - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); // Found a break, so unpack the package - if (Debug) - cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; - SmartUnPack(DepPkg, false); + List->Flag(Pkg,pkgOrderList::Loop); + if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + if (Debug) + cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + SmartUnPack(DepPkg, false); + } } if (Start==End) { @@ -906,7 +933,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } } } - + // Perform immedate configuration of the package. if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) @@ -947,7 +974,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) { PkgIterator Pkg(Cache,*I); - + if (List->IsNow(Pkg) == false) { if (Debug == true) -- cgit v1.2.3 From 634985f8138903d7fb1c883274be83fd2ccd64fe Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 14 Jul 2011 16:39:06 +0100 Subject: Inproved errors and warnings, will now warn if package configuration fails, but only error if the package is not configured at the end. --- apt-pkg/packagemanager.cc | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 601fbb484..874472a47 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -284,8 +284,10 @@ bool pkgPackageManager::ConfigureAll() { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false) + if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false) { + _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name()); return false; + } List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); } @@ -337,8 +339,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) } // Sanity Check - if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) - return _error->Error(_("Could not perform immediate configuration on '%s'. " + if (List->IsFlag(Pkg,pkgOrderList::Configured) == false && Debug) + _error->Error(_("Could not perform immediate configuration on '%s'. " "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); return true; @@ -494,8 +496,8 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) } else { cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer.VerStr() << endl; } - if (CandVer != 0) - cout << " CandVer " << CandVer.VerStr() << endl; + if (CandVer != 0) + cout << OutputInDepth(Depth ) << " CandVer " << CandVer.VerStr() << endl; cout << OutputInDepth(Depth) << " Keep " << Cache[Pkg].Keep() << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(Pkg,pkgOrderList::Configured) << endl; @@ -619,7 +621,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) if (SmartConfigure(Pkg) == false) - return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'. " + _error->Warning(_("Could not perform immediate configuration on already unpacked '%s'. " "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name()); return true; } @@ -847,6 +849,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) /* Because of the ordered list, most dependancies should be unpacked, however if there is a loop this is not the case, so check for dependancies before configuring. This is done after the package installation as it makes it easier to deal with conflicts problems */ + bool Bad = true; for (DepIterator D = instVer.DependsList(); D.end() == false; ) { @@ -854,9 +857,11 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) pkgCache::DepIterator Start; pkgCache::DepIterator End; D.GlobOr(Start,End); + + if (End->Type == pkgCache::Dep::Depends) + Bad = true; // Check for dependanices that have not been unpacked, probably due to loops. - bool Bad = true; while (End->Type == pkgCache::Dep::Depends) { PkgIterator DepPkg; VerIterator InstallVer; @@ -922,9 +927,10 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } if (Start==End) { - if (Bad) { - //return - _error->Error("Could not satisfy dependancies for %s",Pkg.Name()); + if (Bad && Debug) { + if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + _error->Warning("Could not satisfy dependancies for %s",Pkg.Name()); + } } break; @@ -933,13 +939,12 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } } } - + // Perform immedate configuration of the package. if (Immediate == true && - List->IsFlag(Pkg,pkgOrderList::Immediate) == true) + List->IsFlag(Pkg,pkgOrderList::Immediate) == true && !Bad) if (SmartConfigure(Pkg) == false) - //return - _error->Error(_("Could not perform immediate configuration on '%s'. " + _error->Warning(_("Could not perform immediate configuration on '%s'. " "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); return true; @@ -977,9 +982,16 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (List->IsNow(Pkg) == false) { - if (Debug == true) - clog << "Skipping already done " << Pkg.Name() << endl; + if (!List->IsFlag(Pkg,pkgOrderList::Configured)) { + if (SmartConfigure(Pkg) == false && Debug) + _error->Warning("Internal Error, Could not configure %s",Pkg.Name()); + // FIXME: The above warning message might need changing + } else { + if (Debug == true) + clog << "Skipping already done " << Pkg.Name() << endl; + } continue; + } if (List->IsMissing(Pkg) == true) -- cgit v1.2.3 From b684d8c7b15fbbebb149afac4e374b025c1b335e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 16 Jul 2011 22:10:52 +0100 Subject: Dont try to configure packages using SmartConfigure when not performing immediate configuration. --- apt-pkg/packagemanager.cc | 6 +++--- apt-pkg/packagemanager.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 874472a47..8112c7fa1 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -166,7 +166,7 @@ bool pkgPackageManager::CreateOrderList() delete List; List = new pkgOrderList(&Cache); - static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); + NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false); if (Debug && ImmConfigureAll) @@ -982,11 +982,11 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (List->IsNow(Pkg) == false) { - if (!List->IsFlag(Pkg,pkgOrderList::Configured)) { + if (!List->IsFlag(Pkg,pkgOrderList::Configured) && !NoImmConfigure) { if (SmartConfigure(Pkg) == false && Debug) _error->Warning("Internal Error, Could not configure %s",Pkg.Name()); // FIXME: The above warning message might need changing - } else { + } else { if (Debug == true) clog << "Skipping already done " << Pkg.Name() << endl; } diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index dcc9dc2a2..d4a25e982 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -48,6 +48,7 @@ class pkgPackageManager : protected pkgCache::Namespace pkgDepCache &Cache; pkgOrderList *List; bool Debug; + bool NoImmConfigure; bool ImmConfigureAll; /** \brief saves packages dpkg let disappear -- cgit v1.2.3 From 590f1923121815b36ef889033c1c416a23cbe9a2 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 27 Jul 2011 15:20:35 +0100 Subject: SmartConfigure and SmartUnPack have got smarter! The full descriptions of what they now do is in the apt-pkg/packagemanager.cc file. The short version is that they will both put the system in a state where there operation can be achived, this involves calling themselves and each other recursively. Because SmartConfigure can now configure a package and all its dependancies itself, there is no current need for DepAdd (at least in packagemanager.cc), SmartConfigure also performs the function of the short lived VerifyConfigure as it checks through all the dependancies before performing configuration. Another change is to use the ConfigureAll method in OrderInstall to clean up any packages left unconfigured during ImmConfigureAll. This is necessary to inprove the safety of ImmConfiguration and because of the new SIGINT functionality of dpkgpm.cc relies on no packages being left unconfigured between pairs of dpkg calls. While writing this commit log, I have realised that the SIGINT stuff is a prototype and not ready to be used yet as I have only tested it twice. --- apt-pkg/deb/dpkgpm.cc | 15 +- apt-pkg/deb/dpkgpm.h | 2 + apt-pkg/packagemanager.cc | 434 ++++++++++++++-------------------------------- apt-pkg/packagemanager.h | 4 +- 4 files changed, 141 insertions(+), 314 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 5fbd1801a..3dbbd7c97 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -888,7 +889,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) OpenLog(); // this loop is runs once per operation - for (vector::const_iterator I = List.begin(); I != List.end();) + for (vector::const_iterator I = List.begin(); I != List.end() && !pkgPackageManager::SigINTStop;) { // Do all actions with the same Op in one run vector::const_iterator J = I; @@ -920,7 +921,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // the argument list is split in a way that A depends on B // and they are in the same "--configure A B" run // - with the split they may now be configured in different - // runs + // runs if (J - I > (signed)MaxArgs) J = I + MaxArgs; @@ -1062,7 +1063,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) it to all processes in the group. Since dpkg ignores the signal it doesn't die but we do! So we must also ignore it */ sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN); - sighandler_t old_SIGINT = signal(SIGINT,SIG_IGN); + sighandler_t old_SIGINT = signal(SIGINT,SigINT); // ignore SIGHUP as well (debian #463030) sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN); @@ -1207,6 +1208,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Restore sig int/quit signal(SIGQUIT,old_SIGQUIT); signal(SIGINT,old_SIGINT); + signal(SIGHUP,old_SIGHUP); return _error->Errno("waitpid","Couldn't wait for subprocess"); } @@ -1247,6 +1249,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Restore sig int/quit signal(SIGQUIT,old_SIGQUIT); signal(SIGINT,old_SIGINT); + signal(SIGHUP,old_SIGHUP); if(master >= 0) @@ -1308,6 +1311,12 @@ bool pkgDPkgPM::Go(int OutStatusFd) Cache.writeStateFile(NULL); return true; } + +void SigINT(int sig) { + cout << " -- SIGINT -- " << endl; + if (_config->FindB("APT::Immediate-Configure-All",false)) + pkgPackageManager::SigINTStop = true; +} /*}}}*/ // pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index b7b5a6def..fb92c58ea 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -113,4 +113,6 @@ class pkgDPkgPM : public pkgPackageManager virtual ~pkgDPkgPM(); }; +void SigINT(int sig); + #endif diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 8112c7fa1..8bcf3d884 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -29,6 +29,8 @@ /*}}}*/ using namespace std; +bool pkgPackageManager::SigINTStop = false; + // PM::PackageManager - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -262,7 +264,8 @@ bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, // PM::ConfigureAll - Run the all out configuration /*{{{*/ // --------------------------------------------------------------------- /* This configures every package. It is assumed they are all unpacked and - that the final configuration is valid. */ + that the final configuration is valid. This is also used to catch packages + that have not been configured when using ImmConfigureAll */ bool pkgPackageManager::ConfigureAll() { pkgOrderList OList(&Cache); @@ -284,7 +287,7 @@ bool pkgPackageManager::ConfigureAll() { PkgIterator Pkg(Cache,*I); - if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false) { + if (ConfigurePkgs == true && SmartConfigure(Pkg) == false) { _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name()); return false; } @@ -297,244 +300,142 @@ bool pkgPackageManager::ConfigureAll() /*}}}*/ // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/ // --------------------------------------------------------------------- -/* This routine scheduals the configuration of the given package and all - of it's dependents. */ +/* This routine trys to put the system in a state where Pkg can be configured, + this involves checking each of Pkg's dependanies and unpacking and + configuring packages where needed. */ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { if (Debug == true) clog << "SmartConfigure " << Pkg.Name() << endl; - - pkgOrderList OList(&Cache); - - if (DepAdd(OList,Pkg) == false) - return false; - - static std::string const conf = _config->Find("PackageManager::Configure","all"); - static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); - - if (ConfigurePkgs == true) - if (OList.OrderConfigure() == false) - return false; - - // Perform the configuring - for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) - { - PkgIterator Pkg(Cache,*I); - - if (ConfigurePkgs == true && VerifyAndConfigure(Pkg,OList) == false) - return false; - List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); - } - - if (Cache[Pkg].InstVerIter(Cache)->MultiArch == pkgCache::Version::Same) - for (PkgIterator P = Pkg.Group().PackageList(); - P.end() == false; P = Pkg.Group().NextPkg(P)) - { - if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true || - Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && - (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) - continue; - SmartConfigure(P); - } - - // Sanity Check - if (List->IsFlag(Pkg,pkgOrderList::Configured) == false && Debug) - _error->Error(_("Could not perform immediate configuration on '%s'. " - "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); - - return true; -} - -// PM::VerifyConfigure - Check configuration of dependancies /*{{{*/ -// --------------------------------------------------------------------- -/* This routine checks that all a packages dependancies have been - configured, before it is going to be configured. If this gives a warning - on a virtual package, it means that the package thats providing it is not - configured*/ -bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList) -{ - // If this is true at the end, then the package should not be configured - bool error=true; - // This holds the the OR status of the previous dependancy - bool previousOr=false; - - // First iterate through the dependancies of Pkg - for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false; D++) - { - - /* If the dependancy is of type Depends or PreDepends, we need to check it, but only if it is going to be - configured at some point */ - if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) { - - /* If the previous package and this package are OR dependancies, and the previous package satisfied the dependancy - then skip this dependancy as it is not relevent, this will repeat for the next package if the situation is the - same */ - if (previousOr && !error) { // As error has not been reset, this refers to the previous dependancy - previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; - continue; - } - - // Reset error - error = true; - - // Check thorugh all possible versions of this dependancy (D) - SPtrArray VList = D.AllTargets(); - for (Version **I = VList; *I != 0; I++) - { - VerIterator DepVer(Cache,*I); - PkgIterator DepPkg = DepVer.ParentPkg(); - VerIterator DepInstallVer(Cache,Cache[DepPkg].InstallVer); - - if (DepPkg.CurrentVer() == DepVer && !List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { - error=false; - break; - } - - if (Cache[DepPkg].InstallVer == DepVer && - (List->IsFlag(DepPkg,pkgOrderList::Configured) || OList.IsFlag(DepPkg,pkgOrderList::InList))) { - error=false; - break; - } - } - - /* Only worry here if this package is a OR with the next, as even though this package does not satisfy the OR - the next one might */ - if (error && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) { - _error->Error("Package %s should not be configured because package %s is not configured",Pkg.Name(),D.TargetPkg().Name()); - return false; - /* If the previous package is a OR but not this package, but there is still an error then fail as it will not - be satisfied */ - } else if (error && previousOr && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) { - _error->Error("Package %s should not be configured because package %s (or any alternatives) are not configured",Pkg.Name(),D.TargetPkg().Name()); - return false; - } - - previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; - } else { - previousOr=false; - } - } - return true; -} - -// PM::VerifyAndConfigure - Check configuration of dependancies /*{{{*/ -// --------------------------------------------------------------------- -/* This routine verifies if a package can be configured and if so - configures it */ -bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList) -{ - if (VerifyConfigure(Pkg, OList)) - return Configure(Pkg); - else - return false; - -} - /*}}}*/ -// PM::DepAdd - Add all dependents to the oder list /*{{{*/ -// --------------------------------------------------------------------- -/* This recursively adds all dependents to the order list */ -bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) -{ - if (OList.IsFlag(Pkg,pkgOrderList::Added) == true) - return true; - if (List->IsFlag(Pkg,pkgOrderList::Configured) == true) - return true; - if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false) - return false; - - if (Debug) - std::clog << OutputInDepth(Depth) << "DepAdd: " << Pkg.Name() << std::endl; + VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); - // Put the package on the list - OList.push_back(Pkg); - OList.Flag(Pkg,pkgOrderList::Added); - Depth++; - - // Check the dependencies to see if they are all satisfied. + /* Because of the ordered list, most dependancies should be unpacked, + however if there is a loop this is not the case, so check for dependancies before configuring. + This is done after the package installation as it makes it easier to deal with conflicts problems */ bool Bad = false; - for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false;) + for (DepIterator D = instVer.DependsList(); + D.end() == false; ) { - if (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends) - { - D++; - continue; - } + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start; + pkgCache::DepIterator End; + D.GlobOr(Start,End); - // Grok or groups - Bad = true; - for (bool LastOR = true; D.end() == false && LastOR == true; D++) - { - LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; - - if (Bad == false) - continue; + if (End->Type == pkgCache::Dep::Depends) + Bad = true; - SPtrArray VList = D.AllTargets(); - for (Version **I = VList; *I != 0 && Bad == true; I++) - { + // Check for dependanices that have not been unpacked, probably due to loops. + while (End->Type == pkgCache::Dep::Depends) { + PkgIterator DepPkg; + VerIterator InstallVer; + SPtrArray VList = Start.AllTargets(); + + for (Version **I = VList; *I != 0; I++) { VerIterator Ver(Cache,*I); - PkgIterator Pkg = Ver.ParentPkg(); - VerIterator InstallVer(Cache,Cache[Pkg].InstallVer); - VerIterator CandVer(Cache,Cache[Pkg].CandidateVer); + DepPkg = Ver.ParentPkg(); + + if (!Bad) continue; + + InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer); + //VerIterator CandVer(Cache,Cache[DepPkg].CandidateVer); if (Debug && false) { if (Ver==0) { - cout << OutputInDepth(Depth) << "Checking if " << Ver << " of " << Pkg.Name() << " satisfies this dependancy" << endl; + cout << " Checking if " << Ver << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; } else { - cout << OutputInDepth(Depth) << "Checking if " << Ver.VerStr() << " of " << Pkg.Name() << " satisfies this dependancy" << endl; + cout << " Checking if " << Ver.VerStr() << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; } - - if (Pkg.CurrentVer()==0) { - cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl; + + if (DepPkg.CurrentVer()==0) { + cout << " CurrentVer " << DepPkg.CurrentVer() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; } else { - cout << OutputInDepth(Depth) << " CurrentVer " << Pkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(Pkg) << " NeedsNothing " << (Pkg.State() == PkgIterator::NeedsNothing) << endl; + cout << " CurrentVer " << DepPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; } - + if (InstallVer==0) { - cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer << endl; + cout << " InstallVer " << InstallVer << endl; } else { - cout << OutputInDepth(Depth )<< " InstallVer " << InstallVer.VerStr() << endl; + cout << " InstallVer " << InstallVer.VerStr() << endl; } - if (CandVer != 0) - cout << OutputInDepth(Depth ) << " CandVer " << CandVer.VerStr() << endl; + //if (CandVer != 0) + // cout << " CandVer " << CandVer.VerStr() << endl; - cout << OutputInDepth(Depth) << " Keep " << Cache[Pkg].Keep() << " Unpacked " << List->IsFlag(Pkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(Pkg,pkgOrderList::Configured) << endl; + cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << endl; } - // See if the current version is ok - if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && - Pkg.State() == PkgIterator::NeedsNothing) + + // Check if it satisfies this dependancy + if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && + DepPkg.State() == PkgIterator::NeedsNothing) { Bad = false; continue; } - // Not the install version - if ((Cache[Pkg].InstallVer != *I && Cache[Pkg].CandidateVer != *I) || - (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing && - (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) + if (Cache[DepPkg].InstallVer == *I) { + if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { + if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + List->Flag(Pkg,pkgOrderList::Loop); + Bad = !SmartConfigure(DepPkg); + } else { + Bad = false; + } + } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { + Bad = false; + } continue; - - if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == true) - Bad = !DepAdd(OList,Pkg,Depth); - if (List->IsFlag(Pkg,pkgOrderList::Configured) == true) - Bad = false; + } } + + if (InstallVer != 0 && Bad) { + Bad = false; + List->Flag(Pkg,pkgOrderList::Loop); + if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + if (Debug) + cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + SmartUnPack(DepPkg, true); + } + } + + if (Start==End) { + if (Bad && Debug) { + if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + _error->Warning("Could not satisfy dependancies for %s",Pkg.Name()); + } + } + break; + + } else { + Start++; + } } + } + + static std::string const conf = _config->Find("PackageManager::Configure","all"); + static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); + + if (ConfigurePkgs == true && Configure(Pkg) == false) + return false; - if (Bad == true) + List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); + + if (Cache[Pkg].InstVerIter(Cache)->MultiArch == pkgCache::Version::Same) + for (PkgIterator P = Pkg.Group().PackageList(); + P.end() == false; P = Pkg.Group().NextPkg(P)) { - if (Debug) - std::clog << OutputInDepth(Depth) << "DepAdd FAILS on: " << Pkg.Name() << std::endl; - OList.Flag(Pkg,0,pkgOrderList::Added); - OList.pop_back(); - Depth--; - return false; + if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true || + Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && + (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) + continue; + SmartConfigure(P); } - } - - Depth--; + + // Sanity Check + if (List->IsFlag(Pkg,pkgOrderList::Configured) == false && Debug) + _error->Warning(_("Could not perform immediate configuration on '%s'. " + "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); + return true; } /*}}}*/ @@ -603,7 +504,8 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg) /*}}}*/ // PM::SmartUnPack - Install helper /*{{{*/ // --------------------------------------------------------------------- -/* This performs the task of handling pre-depends. */ +/* This puts the system in a state where it can Unpack Pkg, if Pkg is allready + unpacked, or when it has been unpacked, if Immediate==true it configures it. */ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) { return SmartUnPack(Pkg, true); @@ -628,8 +530,11 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); - /* See if this packages install version has any predependencies - that are not met by 'now' packages. */ + /* PreUnpack Checks: This loop checks and attemps to rectify and problems that would prevent the package being unpacked. + It addresses: PreDepends, Conflicts, Obsoletes and DpkgBreaks. Any resolutions that do not require it should + avoid configuration (calling SmartUnpack with Immediate=true), this is because any loops before Pkg is unpacked + can cause problems. This will be either dealt with if the package is configured as a dependancy of + Pkg (if and when Pkg is configured), or by the ConfigureAll call at the end of the for loop in OrderInstall. */ for (DepIterator D = instVer.DependsList(); D.end() == false; ) { @@ -763,7 +668,6 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) PkgIterator BrokenPkg = Ver.ParentPkg(); VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); - cout << " " << Pkg.Name() << " breaks " << BrokenPkg.Name() << endl; if (Debug && false) { if (Ver==0) { cout << " Checking if " << Ver << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl; @@ -793,6 +697,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) // Found a break, so unpack the package if (Debug) cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; + /* */ SmartUnPack(BrokenPkg, false); } // Check if a package needs to be removed @@ -846,106 +751,13 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) if(Install(Pkg,FileNames[Pkg->ID]) == false) return false; - /* Because of the ordered list, most dependancies should be unpacked, - however if there is a loop this is not the case, so check for dependancies before configuring. - This is done after the package installation as it makes it easier to deal with conflicts problems */ - bool Bad = true; - for (DepIterator D = instVer.DependsList(); - D.end() == false; ) - { - // Compute a single dependency element (glob or) - pkgCache::DepIterator Start; - pkgCache::DepIterator End; - D.GlobOr(Start,End); - - if (End->Type == pkgCache::Dep::Depends) - Bad = true; - - // Check for dependanices that have not been unpacked, probably due to loops. - while (End->Type == pkgCache::Dep::Depends) { - PkgIterator DepPkg; - VerIterator InstallVer; - SPtrArray VList = Start.AllTargets(); - - for (Version **I = VList; *I != 0; I++) { - VerIterator Ver(Cache,*I); - DepPkg = Ver.ParentPkg(); - - if (!Bad) continue; - - InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer); - VerIterator CandVer(Cache,Cache[DepPkg].CandidateVer); - - if (Debug && false) { - if (Ver==0) { - cout << " Checking if " << Ver << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; - } else { - cout << " Checking if " << Ver.VerStr() << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; - } - - if (DepPkg.CurrentVer()==0) { - cout << " CurrentVer " << DepPkg.CurrentVer() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; - } else { - cout << " CurrentVer " << DepPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; - } - - if (InstallVer==0) { - cout << " InstallVer " << InstallVer << endl; - } else { - cout << " InstallVer " << InstallVer.VerStr() << endl; - } - if (CandVer != 0) - cout << " CandVer " << CandVer.VerStr() << endl; - - cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << endl; - - } - - // Check if it satisfies this dependancy - if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && - DepPkg.State() == PkgIterator::NeedsNothing) - { - Bad = false; - continue; - } - - if (Cache[DepPkg].InstallVer == *I && !List->IsNow(DepPkg)) { - Bad = false; - continue; - } - } - - if (InstallVer != 0 && Bad) { - Bad = false; - // Found a break, so unpack the package - List->Flag(Pkg,pkgOrderList::Loop); - if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { - if (Debug) - cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; - SmartUnPack(DepPkg, false); - } - } - - if (Start==End) { - if (Bad && Debug) { - if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { - _error->Warning("Could not satisfy dependancies for %s",Pkg.Name()); - } - } - break; - - } else { - Start++; - } - } - } + if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) { - // Perform immedate configuration of the package. - if (Immediate == true && - List->IsFlag(Pkg,pkgOrderList::Immediate) == true && !Bad) - if (SmartConfigure(Pkg) == false) - _error->Warning(_("Could not perform immediate configuration on '%s'. " - "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); + // Perform immedate configuration of the package. + if (SmartConfigure(Pkg) == false) + _error->Warning(_("Could not perform immediate configuration on '%s'. " + "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); + } return true; } @@ -1025,6 +837,12 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (SmartUnPack(Pkg) == false) return Failed; DoneSomething = true; + + if (ImmConfigureAll) { + /* ConfigureAll here to pick up and packages left unconfigured becuase they were unpacked in the + "PreUnpack Checks" section */ + ConfigureAll(); + } } // Final run through the configure phase diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index d4a25e982..e1878ce46 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -42,6 +42,7 @@ class pkgPackageManager : protected pkgCache::Namespace public: enum OrderResult {Completed,Failed,Incomplete}; + static bool SigINTStop; protected: string *FileNames; @@ -59,7 +60,6 @@ class pkgPackageManager : protected pkgCache::Namespace */ std::set disappearedPkgs; - bool DepAdd(pkgOrderList &Order,PkgIterator P,int Depth = 0); void ImmediateAdd(PkgIterator P, bool UseInstallVer, unsigned const int &Depth = 0); virtual OrderResult OrderInstall(); bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver); @@ -76,8 +76,6 @@ class pkgPackageManager : protected pkgCache::Namespace bool SmartUnPack(PkgIterator Pkg, bool const Immediate); bool SmartRemove(PkgIterator Pkg); bool EarlyRemove(PkgIterator Pkg); - bool VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList); - bool VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList); // The Actual installation implementation virtual bool Install(PkgIterator /*Pkg*/,string /*File*/) {return false;}; -- cgit v1.2.3 From 1cecd4376cebdd0225ee91707b7630bc35959474 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 31 Jul 2011 16:26:39 +0100 Subject: Only allow interupts when using, Immediate-Configure-All. TODO for dpkgpm: Useful messages about the interupt, what was done to what packages and what was not done to what packages. Only fail when the system is in a clean state, at the moment it will fail either a configure or install run. --- apt-pkg/deb/dpkgpm.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 3dbbd7c97..479126658 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -889,7 +889,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) OpenLog(); // this loop is runs once per operation - for (vector::const_iterator I = List.begin(); I != List.end() && !pkgPackageManager::SigINTStop;) + for (vector::const_iterator I = List.begin(); I != List.end();) { // Do all actions with the same Op in one run vector::const_iterator J = I; @@ -921,7 +921,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // the argument list is split in a way that A depends on B // and they are in the same "--configure A B" run // - with the split they may now be configured in different - // runs + // runs, using Immediate-Configure-All can help prevent this. if (J - I > (signed)MaxArgs) J = I + MaxArgs; @@ -1064,6 +1064,9 @@ bool pkgDPkgPM::Go(int OutStatusFd) it doesn't die but we do! So we must also ignore it */ sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN); sighandler_t old_SIGINT = signal(SIGINT,SigINT); + + // Check here for any SIGINT + if (pkgPackageManager::SigINTStop) break; // ignore SIGHUP as well (debian #463030) sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN); @@ -1102,7 +1105,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) sigprocmask(SIG_SETMASK, &original_sigmask, 0); } } - // Fork dpkg pid_t Child; _config->Set("APT::Keep-Fds::",fd[1]); -- cgit v1.2.3 From 17182c0c66630c2fcba938edb5b27668f7495854 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 1 Aug 2011 12:27:10 +0100 Subject: Only stop on SigInt if the system state is right (still needs more testing). More inprovements to the package manager to prevent packages from being configured twice. --- apt-pkg/deb/dpkgpm.cc | 4 ++-- apt-pkg/packagemanager.cc | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 479126658..68d9ca1de 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1066,7 +1066,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) sighandler_t old_SIGINT = signal(SIGINT,SigINT); // Check here for any SIGINT - if (pkgPackageManager::SigINTStop) break; + if (pkgPackageManager::SigINTStop && + (I->Op == Item::Install || I->Op == Item::Remove || I->Op == Item::Purge)) break; // ignore SIGHUP as well (debian #463030) sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN); @@ -1315,7 +1316,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) } void SigINT(int sig) { - cout << " -- SIGINT -- " << endl; if (_config->FindB("APT::Immediate-Configure-All",false)) pkgPackageManager::SigINTStop = true; } diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 8bcf3d884..324b7ffba 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -286,6 +286,10 @@ bool pkgPackageManager::ConfigureAll() for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) { PkgIterator Pkg(Cache,*I); + + /* Check if the package has been configured, this can happen if SmartConfigure + calls its self */ + if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue; if (ConfigurePkgs == true && SmartConfigure(Pkg) == false) { _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name()); @@ -415,6 +419,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) static std::string const conf = _config->Find("PackageManager::Configure","all"); static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); + if (List->IsFlag(Pkg,pkgOrderList::Configured)) + return _error->Error("Internal configure error on '%s'. ",Pkg.Name(),1); + if (ConfigurePkgs == true && Configure(Pkg) == false) return false; @@ -577,6 +584,11 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) if (Cache[Pkg].InstallVer != *I || (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) continue; + + if (List->IsFlag(Pkg,pkgOrderList::Configured)) { + Bad = false; + continue; + } if (Debug) clog << "Trying to SmartConfigure " << Pkg.Name() << endl; -- cgit v1.2.3 From 11b87a08ee6952c5b66b14842283df3ea26b90ac Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 2 Aug 2011 10:29:11 +0100 Subject: Inproved the SIGINT stop in the dpkgpm, not perfect yet but it should work when using Immediate-Configure-All. --- apt-pkg/deb/dpkgpm.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 68d9ca1de..57361ccdc 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -954,6 +954,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) snprintf(status_fd_buf,sizeof(status_fd_buf),"%i", fd[1]); Args[n++] = status_fd_buf; Size += strlen(Args[n-1]); + + unsigned long const Op = I->Op; switch (I->Op) { @@ -1066,9 +1068,10 @@ bool pkgDPkgPM::Go(int OutStatusFd) sighandler_t old_SIGINT = signal(SIGINT,SigINT); // Check here for any SIGINT - if (pkgPackageManager::SigINTStop && - (I->Op == Item::Install || I->Op == Item::Remove || I->Op == Item::Purge)) break; - + if (pkgPackageManager::SigINTStop && (Op == Item::Remove || Op == Item::Purge || Op == Item::Install)) + break; + + // ignore SIGHUP as well (debian #463030) sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN); @@ -1290,6 +1293,9 @@ bool pkgDPkgPM::Go(int OutStatusFd) } } CloseLog(); + + if (pkgPackageManager::SigINTStop) + _error->Warning(_("Operation was interrupted before it could finish")); if (RunScripts("DPkg::Post-Invoke") == false) return false; -- cgit v1.2.3 From b9f668796339b7581f49ee6d42c53dc10049e5c2 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 7 Aug 2011 16:35:36 +0100 Subject: Fixed a bug on line 623, I picked this up after seeing SmartUnpack trying to remove packages once they were confiured to solve Conflicts with the previous version! Luckily EarlyRemove is sane, and properly checks, so I think this was just cosmetic. Also fixed a bug on line 374 with SmartUnpack not checking if a dependancy has been removed, this bug was definately harmful. --- apt-pkg/packagemanager.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 324b7ffba..b3c3d2591 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -344,7 +344,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer); //VerIterator CandVer(Cache,Cache[DepPkg].CandidateVer); - if (Debug && false) { + if (Debug) { if (Ver==0) { cout << " Checking if " << Ver << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; } else { @@ -365,13 +365,13 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) //if (CandVer != 0) // cout << " CandVer " << CandVer.VerStr() << endl; - cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << endl; + cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << " Removed " << List->IsFlag(DepPkg,pkgOrderList::Removed) << endl; } // Check if it satisfies this dependancy if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && - DepPkg.State() == PkgIterator::NeedsNothing) + !List->IsFlag(DepPkg,pkgOrderList::Removed) && DepPkg.State() == PkgIterator::NeedsNothing) { Bad = false; continue; @@ -623,7 +623,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer); // See if the current version is conflicting - if (ConflictPkg.CurrentVer() == Ver && !List->IsFlag(ConflictPkg,pkgOrderList::UnPacked)) + if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) { if (Debug && false) cout << " " << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; @@ -653,7 +653,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { - cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; + if (Debug) + cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; List->Flag(Pkg,pkgOrderList::Loop); SmartUnPack(ConflictPkg,false); } else { @@ -662,7 +663,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } } else { if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) { - cout << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; + if (Debug) + cout << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; if (EarlyRemove(ConflictPkg) == false) return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); } -- cgit v1.2.3 From c7c7d3e8f12e68cd14470eec47db516c9b784cbe Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 7 Aug 2011 20:26:31 +0100 Subject: Improved errors and messages in general and improved the comments. Removed quite a bit of code I used while learning about how apt handles things. Added some extra checks and warnings relevent for Immediate Configuration. Removed a wierd section I put in to prevent a segfault at 724+, this appears no longer to be needed. --- apt-pkg/packagemanager.cc | 195 +++++++++++++++------------------------------- 1 file changed, 63 insertions(+), 132 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index b3c3d2591..d956c001e 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -292,7 +292,11 @@ bool pkgPackageManager::ConfigureAll() if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue; if (ConfigurePkgs == true && SmartConfigure(Pkg) == false) { - _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name()); + if (ImmConfigureAll) + _error->Error(_("Could not perform immediate configuration on '%s'. " + "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); + else + _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name()); return false; } @@ -304,19 +308,26 @@ bool pkgPackageManager::ConfigureAll() /*}}}*/ // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/ // --------------------------------------------------------------------- -/* This routine trys to put the system in a state where Pkg can be configured, - this involves checking each of Pkg's dependanies and unpacking and - configuring packages where needed. */ +/* This function tries to put the system in a state where Pkg can be configured. + This involves checking each of Pkg's dependanies and unpacking and + configuring packages where needed. + + Note on failure: This method can fail, without causing any problems. + This can happen when using Immediate-Configure-All, SmartUnPack may call + SmartConfigure, it may fail because of a complex dependancy situation, but + a error will only be reported if ConfigureAll fails. This is why some of the + messages this function reports on failure (return false;) as just warnings + only shown when debuging*/ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { - if (Debug == true) + if (Debug) clog << "SmartConfigure " << Pkg.Name() << endl; VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* Because of the ordered list, most dependancies should be unpacked, - however if there is a loop this is not the case, so check for dependancies before configuring. - This is done after the package installation as it makes it easier to deal with conflicts problems */ + however if there is a loop (A depends on B, B depends on A) this will not + be the case, so check for dependancies before configuring. */ bool Bad = false; for (DepIterator D = instVer.DependsList(); D.end() == false; ) @@ -335,63 +346,39 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) VerIterator InstallVer; SPtrArray VList = Start.AllTargets(); + // Check through each version of each package that could satisfy this dependancy for (Version **I = VList; *I != 0; I++) { VerIterator Ver(Cache,*I); DepPkg = Ver.ParentPkg(); - - if (!Bad) continue; - InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer); - //VerIterator CandVer(Cache,Cache[DepPkg].CandidateVer); - - if (Debug) { - if (Ver==0) { - cout << " Checking if " << Ver << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; - } else { - cout << " Checking if " << Ver.VerStr() << " of " << DepPkg.Name() << " satisfies this dependancy" << endl; - } - - if (DepPkg.CurrentVer()==0) { - cout << " CurrentVer " << DepPkg.CurrentVer() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; - } else { - cout << " CurrentVer " << DepPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(DepPkg) << " NeedsNothing " << (DepPkg.State() == PkgIterator::NeedsNothing) << endl; - } - - if (InstallVer==0) { - cout << " InstallVer " << InstallVer << endl; - } else { - cout << " InstallVer " << InstallVer.VerStr() << endl; - } - //if (CandVer != 0) - // cout << " CandVer " << CandVer.VerStr() << endl; - - cout << " Keep " << Cache[DepPkg].Keep() << " Unpacked " << List->IsFlag(DepPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(DepPkg,pkgOrderList::Configured) << " Removed " << List->IsFlag(DepPkg,pkgOrderList::Removed) << endl; - - } - - // Check if it satisfies this dependancy + + // Check if the current version of the package is avalible and will satisfy this dependancy if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && !List->IsFlag(DepPkg,pkgOrderList::Removed) && DepPkg.State() == PkgIterator::NeedsNothing) { Bad = false; - continue; + break; } + // Check if the version that is going to be installed will satisfy the dependancy if (Cache[DepPkg].InstallVer == *I) { if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { + /* Check for a loop to prevent one forming + If A depends on B and B depends on A, SmartConfigure will + just hop between them if this is not checked */ if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { List->Flag(Pkg,pkgOrderList::Loop); - Bad = !SmartConfigure(DepPkg); - } else { - Bad = false; + // If SmartConfigure was succesfull, Bad is false, so break + if (!(Bad = !SmartConfigure(DepPkg))) break; } } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { Bad = false; + break; } - continue; } } + /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */ if (InstallVer != 0 && Bad) { Bad = false; List->Flag(Pkg,pkgOrderList::Loop); @@ -409,12 +396,17 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) } } break; - } else { Start++; } } } + + if (Bad) { + if (Debug) + _error->Warning(_("Could not configure '%s'. "),Pkg.Name()); + return false; + } static std::string const conf = _config->Find("PackageManager::Configure","all"); static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); @@ -439,9 +431,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) } // Sanity Check - if (List->IsFlag(Pkg,pkgOrderList::Configured) == false && Debug) - _error->Warning(_("Could not perform immediate configuration on '%s'. " - "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); + if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) + return _error->Error(_("Could not configure '%s'. "),Pkg.Name()); return true; } @@ -519,7 +510,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) } bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) { - if (Debug == true) + if (Debug) clog << "SmartUnPack " << Pkg.Name() << endl; // Check if it is already unpacked @@ -537,11 +528,12 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); - /* PreUnpack Checks: This loop checks and attemps to rectify and problems that would prevent the package being unpacked. - It addresses: PreDepends, Conflicts, Obsoletes and DpkgBreaks. Any resolutions that do not require it should - avoid configuration (calling SmartUnpack with Immediate=true), this is because any loops before Pkg is unpacked - can cause problems. This will be either dealt with if the package is configured as a dependancy of - Pkg (if and when Pkg is configured), or by the ConfigureAll call at the end of the for loop in OrderInstall. */ + /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked. + It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should + avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with + complex dependancy structures, trying to configure some packages while breaking the loops can complicate things . + This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), + or by the ConfigureAll call at the end of the for loop in OrderInstall. */ for (DepIterator D = instVer.DependsList(); D.end() == false; ) { @@ -624,33 +616,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) // See if the current version is conflicting if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) - { - if (Debug && false) - cout << " " << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; - - if (Debug && false) { - if (Ver==0) { - cout << " Checking if " << Ver << " of " << ConflictPkg.Name() << " satisfies this dependancy" << endl; - } else { - cout << " Checking if " << Ver.VerStr() << " of " << ConflictPkg.Name() << " satisfies this dependancy" << endl; - } - - if (ConflictPkg.CurrentVer()==0) { - cout << " CurrentVer " << ConflictPkg.CurrentVer() << " IsNow " << List->IsNow(ConflictPkg) << " NeedsNothing " << (ConflictPkg.State() == PkgIterator::NeedsNothing) << endl; - } else { - cout << " CurrentVer " << ConflictPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(ConflictPkg) << " NeedsNothing " << (ConflictPkg.State() == PkgIterator::NeedsNothing) << endl; - } - - if (InstallVer==0) { - cout << " InstallVer " << InstallVer << endl; - } else { - cout << " InstallVer " << InstallVer.VerStr() << endl; - } - - cout << " Keep " << Cache[ConflictPkg].Keep() << " Unpacked " << List->IsFlag(ConflictPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(ConflictPkg,pkgOrderList::Configured) << " Removed " << List->IsFlag(ConflictPkg,pkgOrderList::Removed) << " Loop " << List->IsFlag(ConflictPkg,pkgOrderList::Loop) << endl; - cout << " Delete " << Cache[ConflictPkg].Delete() << endl; - } - + { + /* If a loop is not present or has not yet been detected, attempt to unpack packages + to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { if (Debug) @@ -682,28 +650,6 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) PkgIterator BrokenPkg = Ver.ParentPkg(); VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); - if (Debug && false) { - if (Ver==0) { - cout << " Checking if " << Ver << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl; - } else { - cout << " Checking if " << Ver.VerStr() << " of " << BrokenPkg.Name() << " satisfies this dependancy" << endl; - } - - if (BrokenPkg.CurrentVer()==0) { - cout << " CurrentVer " << BrokenPkg.CurrentVer() << " IsNow " << List->IsNow(BrokenPkg) << " NeedsNothing " << (BrokenPkg.State() == PkgIterator::NeedsNothing) << endl; - } else { - cout << " CurrentVer " << BrokenPkg.CurrentVer().VerStr() << " IsNow " << List->IsNow(BrokenPkg) << " NeedsNothing " << (BrokenPkg.State() == PkgIterator::NeedsNothing) << endl; - } - - if (InstallVer==0) { - cout << " InstallVer " << InstallVer << endl; - } else { - cout << " InstallVer " << InstallVer.VerStr() << endl; - } - - cout << " Keep " << Cache[BrokenPkg].Keep() << " Unpacked " << List->IsFlag(BrokenPkg,pkgOrderList::UnPacked) << " Configured " << List->IsFlag(BrokenPkg,pkgOrderList::Configured) << " Removed " << List->IsFlag(BrokenPkg,pkgOrderList::Removed) << " Loop " << List->IsFlag(BrokenPkg,pkgOrderList::Loop) << " InList " << List->IsFlag(BrokenPkg,pkgOrderList::InList) << endl; - cout << " Delete " << Cache[BrokenPkg].Delete() << endl; - } // Check if it needs to be unpacked if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && !List->IsFlag(BrokenPkg,pkgOrderList::Loop) && List->IsNow(BrokenPkg)) { @@ -711,7 +657,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) // Found a break, so unpack the package if (Debug) cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; - /* */ + SmartUnPack(BrokenPkg, false); } // Check if a package needs to be removed @@ -724,43 +670,27 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } } - // FIXME: Crude but effective fix, allows the SmartUnPack method to be used for packages that new to the system - if (instVer != 0) { - //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << instVer.VerStr() << endl; - - // Check for reverse conflicts. - if (CheckRConflicts(Pkg,Pkg.RevDependsList(), + // Check for reverse conflicts. + if (CheckRConflicts(Pkg,Pkg.RevDependsList(), instVer.VerStr()) == false) - return false; + return false; - for (PrvIterator P = instVer.ProvidesList(); + for (PrvIterator P = instVer.ProvidesList(); P.end() == false; P++) CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - if (instVer->MultiArch == pkgCache::Version::Same) - for (PkgIterator P = Pkg.Group().PackageList(); - P.end() == false; P = Pkg.Group().NextPkg(P)) - { - if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true || + if (instVer->MultiArch == pkgCache::Version::Same) + for (PkgIterator P = Pkg.Group().PackageList(); + P.end() == false; P = Pkg.Group().NextPkg(P)) + { + if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true || Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) - continue; + continue; SmartUnPack(P, false); - } - - } else { - VerIterator InstallVer(Cache,Cache[Pkg].InstallVer); - //cout << "Check for reverse conflicts on " << Pkg.Name() << " " << InstallVer.VerStr() << endl; - - // Check for reverse conflicts. - if (CheckRConflicts(Pkg,Pkg.RevDependsList(), - InstallVer.VerStr()) == false) - return false; - - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - } + } if(Install(Pkg,FileNames[Pkg->ID]) == false) return false; @@ -855,7 +785,8 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (ImmConfigureAll) { /* ConfigureAll here to pick up and packages left unconfigured becuase they were unpacked in the "PreUnpack Checks" section */ - ConfigureAll(); + if (!ConfigureAll()) + return Failed; } } -- cgit v1.2.3 From e7ecc2183ced0503c4f9662339f5ab98dc1606ee Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 9 Aug 2011 17:10:09 +0100 Subject: More inproved comments about loops. --- apt-pkg/orderlist.cc | 2 ++ apt-pkg/orderlist.h | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index eaa5ea20a..1e412ead5 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -1023,6 +1023,8 @@ bool pkgOrderList::AddLoop(DepIterator D) // Mark the packages as being part of a loop. //Flag(D.TargetPkg(),Loop); //Flag(D.ParentPkg(),Loop); + /* This is currently disabled because the Loop flag is being used for + loop management in the package manager. Check the orderlist.h file for more info */ return true; } /*}}}*/ diff --git a/apt-pkg/orderlist.h b/apt-pkg/orderlist.h index bbceb3879..2f5c6d0d1 100644 --- a/apt-pkg/orderlist.h +++ b/apt-pkg/orderlist.h @@ -74,7 +74,12 @@ class pkgOrderList : protected pkgCache::Namespace typedef Package **iterator; - // State flags + /* State flags + The Loop flag can be set on a package that is currently being processed by either SmartConfigure or + SmartUnPack. This allows the package manager to tell when a loop has been formed as it will try to + SmartUnPack or SmartConfigure a package with the Loop flag set. It will then either stop (as it knows + that the operation is unnecessary as its already in process), or in the case of the conflicts resolution + in SmartUnPack, use EarlyRemove to resolve the situation. */ enum Flags {Added = (1 << 0), AddPending = (1 << 1), Immediate = (1 << 2), Loop = (1 << 3), UnPacked = (1 << 4), Configured = (1 << 5), @@ -89,6 +94,7 @@ class pkgOrderList : protected pkgCache::Namespace void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;}; inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;}; inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;}; + // IsNow will return true if the Pkg has been not been either configured or unpacked inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;}; bool IsMissing(PkgIterator Pkg); void WipeFlags(unsigned long F); -- cgit v1.2.3 From cbea0578989754f70874bf49946b84bf4f7a567e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 11 Aug 2011 15:35:54 +0100 Subject: Added a RmFlag function to remvoe the loop flag, this should prevent any errors or wierd behaviour because of the loop flag being used at mutiple stages in both SmartUnpack and SmartConfigure. --- apt-pkg/orderlist.h | 2 ++ apt-pkg/packagemanager.cc | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/orderlist.h b/apt-pkg/orderlist.h index 2f5c6d0d1..4e5ea1654 100644 --- a/apt-pkg/orderlist.h +++ b/apt-pkg/orderlist.h @@ -94,6 +94,8 @@ class pkgOrderList : protected pkgCache::Namespace void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;}; inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;}; inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;}; + // RmFlag removes a flag from a package + inline void RmFlag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] &= ~F;}; // IsNow will return true if the Pkg has been not been either configured or unpacked inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;}; bool IsMissing(PkgIterator Pkg); diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index d956c001e..722cbfa86 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -369,7 +369,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { List->Flag(Pkg,pkgOrderList::Loop); // If SmartConfigure was succesfull, Bad is false, so break - if (!(Bad = !SmartConfigure(DepPkg))) break; + Bad = !SmartConfigure(DepPkg); + List->RmFlag(Pkg,pkgOrderList::Loop); + if (!Bad) break; } } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { Bad = false; @@ -381,11 +383,12 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */ if (InstallVer != 0 && Bad) { Bad = false; - List->Flag(Pkg,pkgOrderList::Loop); if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + List->Flag(Pkg,pkgOrderList::Loop); if (Debug) cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; SmartUnPack(DepPkg, true); + //List->Flag(Pkg,~pkgOrderList::Loop); } } @@ -616,15 +619,18 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) // See if the current version is conflicting if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) - { + { + cout << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; /* If a loop is not present or has not yet been detected, attempt to unpack packages to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { if (Debug) cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; - List->Flag(Pkg,pkgOrderList::Loop); + List->Flag(Pkg,pkgOrderList::Loop); SmartUnPack(ConflictPkg,false); + // Remove loop to allow it to be used later if needed + List->RmFlag(Pkg,pkgOrderList::Loop); } else { if (EarlyRemove(ConflictPkg) == false) return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); @@ -659,6 +665,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; SmartUnPack(BrokenPkg, false); + List->RmFlag(Pkg,pkgOrderList::Loop); } // Check if a package needs to be removed if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { -- cgit v1.2.3 From e844b947ab5c988fb6d6f8e5ebfa4e0eda856541 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 12 Aug 2011 10:38:19 +0100 Subject: Small fix for loop handeling. --- apt-pkg/packagemanager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 722cbfa86..2fe98b101 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -388,7 +388,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) if (Debug) cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; SmartUnPack(DepPkg, true); - //List->Flag(Pkg,~pkgOrderList::Loop); + List->RmFlag(Pkg,pkgOrderList::Loop); } } -- cgit v1.2.3 From 987d8d0315a315c74827ee2160671a30f5bc4e14 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 12 Aug 2011 12:22:17 +0100 Subject: Inproved debug with versioning --- apt-pkg/packagemanager.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 2fe98b101..8fc571f2f 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -320,9 +320,11 @@ bool pkgPackageManager::ConfigureAll() only shown when debuging*/ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { - if (Debug) - clog << "SmartConfigure " << Pkg.Name() << endl; - + if (Debug) { + VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); + clog << "SmartConfigure " << Pkg.Name() << InstallVer.VerStr() << endl; + } + VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* Because of the ordered list, most dependancies should be unpacked, @@ -513,8 +515,14 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) } bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) { - if (Debug) - clog << "SmartUnPack " << Pkg.Name() << endl; + if (Debug) { + clog << "SmartUnPack " << Pkg.Name(); + VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); + if (Pkg.CurrentVer() == 0) + cout << "(install version " << InstallVer.VerStr() << ")" << endl; + else + cout << "(replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")" << endl; + } // Check if it is already unpacked if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && -- cgit v1.2.3 From a99d02a86c5c25c4a36f06aa44c01709de8219c4 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 12 Aug 2011 16:36:25 +0100 Subject: Added code to allow SmartConfigure to be called mutiple times on the same package to ensure all dependancies are satisfied. --- apt-pkg/packagemanager.cc | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 8fc571f2f..7a0f11d85 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -324,7 +324,10 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); clog << "SmartConfigure " << Pkg.Name() << InstallVer.VerStr() << endl; } - + + // If this is true, only check and correct and dependancies without the Loop flag + bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); + VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* Because of the ordered list, most dependancies should be unpacked, @@ -365,16 +368,19 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) // Check if the version that is going to be installed will satisfy the dependancy if (Cache[DepPkg].InstallVer == *I) { if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { + if (PkgLoop && List->IsFlag(DepPkg,pkgOrderList::Loop)) { + // This dependancy has already been dealt with by another SmartConfigure on Pkg + Bad = false; + break; + } /* Check for a loop to prevent one forming If A depends on B and B depends on A, SmartConfigure will just hop between them if this is not checked */ - if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { - List->Flag(Pkg,pkgOrderList::Loop); - // If SmartConfigure was succesfull, Bad is false, so break - Bad = !SmartConfigure(DepPkg); - List->RmFlag(Pkg,pkgOrderList::Loop); - if (!Bad) break; - } + List->Flag(Pkg,pkgOrderList::Loop); + // If SmartConfigure was succesfull, Bad is false, so break + Bad = !SmartConfigure(DepPkg); + List->RmFlag(Pkg,pkgOrderList::Loop); + if (!Bad) break; } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { Bad = false; break; @@ -389,7 +395,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) List->Flag(Pkg,pkgOrderList::Loop); if (Debug) cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; - SmartUnPack(DepPkg, true); + SmartUnPack(DepPkg, false); List->RmFlag(Pkg,pkgOrderList::Loop); } } @@ -412,6 +418,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) _error->Warning(_("Could not configure '%s'. "),Pkg.Name()); return false; } + + if (PkgLoop) return true; static std::string const conf = _config->Find("PackageManager::Configure","all"); static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); -- cgit v1.2.3 From 165ff1df10fd5960b5f31ce4e3eaa8d41a8e7b67 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 13 Aug 2011 17:29:49 +0100 Subject: Fix a bug introduced in Rev.2159 on line 398, also fix another potential bug. --- apt-pkg/packagemanager.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 7a0f11d85..ee4798911 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -322,7 +322,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) { if (Debug) { VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); - clog << "SmartConfigure " << Pkg.Name() << InstallVer.VerStr() << endl; + clog << "SmartConfigure " << Pkg.Name() << " " << InstallVer.VerStr() << endl; } // If this is true, only check and correct and dependancies without the Loop flag @@ -391,11 +391,11 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */ if (InstallVer != 0 && Bad) { Bad = false; - if (!List->IsFlag(DepPkg,pkgOrderList::Loop)) { + if (List->IsNow(DepPkg) && !List->IsFlag(DepPkg,pkgOrderList::Loop)) { List->Flag(Pkg,pkgOrderList::Loop); if (Debug) cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; - SmartUnPack(DepPkg, false); + SmartUnPack(DepPkg, true); List->RmFlag(Pkg,pkgOrderList::Loop); } } @@ -527,9 +527,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) clog << "SmartUnPack " << Pkg.Name(); VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); if (Pkg.CurrentVer() == 0) - cout << "(install version " << InstallVer.VerStr() << ")" << endl; + cout << " (install version " << InstallVer.VerStr() << ")" << endl; else - cout << "(replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")" << endl; + cout << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")" << endl; } // Check if it is already unpacked -- cgit v1.2.3 From 940f21606bc8d82366d554a9cfa025511a2b2bc4 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 14 Aug 2011 18:41:38 +0100 Subject: Applied DonKult (David)'s excellent fix for inproving the loop management. Now both SmartConfigure and SmartUnPack can be called mutiple times on the same package, this is to make sure that when loops are broken all packages that are required are kept in the same dpkg run. --- apt-pkg/packagemanager.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index ee4798911..4c827af6d 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -536,14 +536,11 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && Cache[Pkg].Keep() == true) { - List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - if (Immediate == true && - List->IsFlag(Pkg,pkgOrderList::Immediate) == true) - if (SmartConfigure(Pkg) == false) - _error->Warning(_("Could not perform immediate configuration on already unpacked '%s'. " - "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name()); - return true; + cout << "SmartUnPack called on Package " << Pkg.Name() << " but its unpacked" << endl; + return false; } + + bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); @@ -674,7 +671,11 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) // Check if it needs to be unpacked if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && - !List->IsFlag(BrokenPkg,pkgOrderList::Loop) && List->IsNow(BrokenPkg)) { + List->IsNow(BrokenPkg)) { + if (PkgLoop && List->IsFlag(BrokenPkg,pkgOrderList::Loop)) { + // This dependancy has already been dealt with by another SmartUnPack on Pkg + break; + } List->Flag(Pkg,pkgOrderList::Loop); // Found a break, so unpack the package if (Debug) @@ -702,6 +703,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) P.end() == false; P++) CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); + if (PkgLoop) return true; + List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); if (instVer->MultiArch == pkgCache::Version::Same) -- cgit v1.2.3 From d41d0e0113208aa1752344a13e8a962a1ad4f76e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 15 Aug 2011 22:31:09 +0100 Subject: Fixed a bug where SmartUnPack would be called with Immediate=true (to resolve dependancies in SmartConfigure) yet Pkg would not be immediately configured. This was because SmartUnPack still required the immediate flag to be set on Pkg. Also inproved the debuging adding indented output for SmartUnPack and SmartConfigure and specifying in the output if SmartConfigure or SmartUnPack was called just to Correct something (PkgLoop = true) or not. --- apt-pkg/packagemanager.cc | 75 +++++++++++++++++++++++++---------------------- apt-pkg/packagemanager.h | 4 +-- 2 files changed, 42 insertions(+), 37 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 4c827af6d..53bb507b6 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -291,7 +291,7 @@ bool pkgPackageManager::ConfigureAll() calls its self */ if (List->IsFlag(Pkg,pkgOrderList::Configured)) continue; - if (ConfigurePkgs == true && SmartConfigure(Pkg) == false) { + if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) { if (ImmConfigureAll) _error->Error(_("Could not perform immediate configuration on '%s'. " "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); @@ -318,16 +318,19 @@ bool pkgPackageManager::ConfigureAll() a error will only be reported if ConfigureAll fails. This is why some of the messages this function reports on failure (return false;) as just warnings only shown when debuging*/ -bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) +bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) { + // If this is true, only check and correct and dependancies without the Loop flag + bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); + if (Debug) { VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); - clog << "SmartConfigure " << Pkg.Name() << " " << InstallVer.VerStr() << endl; + clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.Name() << " (" << InstallVer.VerStr() << ")"; + if (PkgLoop) + clog << " (Only Correct Dependancies)"; + clog << endl; } - // If this is true, only check and correct and dependancies without the Loop flag - bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); - VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* Because of the ordered list, most dependancies should be unpacked, @@ -378,7 +381,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) just hop between them if this is not checked */ List->Flag(Pkg,pkgOrderList::Loop); // If SmartConfigure was succesfull, Bad is false, so break - Bad = !SmartConfigure(DepPkg); + Bad = !SmartConfigure(DepPkg, Depth + 1); List->RmFlag(Pkg,pkgOrderList::Loop); if (!Bad) break; } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { @@ -394,8 +397,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) if (List->IsNow(DepPkg) && !List->IsFlag(DepPkg,pkgOrderList::Loop)) { List->Flag(Pkg,pkgOrderList::Loop); if (Debug) - cout << " Unpacking " << DepPkg.Name() << " to avoid loop" << endl; - SmartUnPack(DepPkg, true); + cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + SmartUnPack(DepPkg, true, Depth + 1); List->RmFlag(Pkg,pkgOrderList::Loop); } } @@ -440,7 +443,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) continue; - SmartConfigure(P); + SmartConfigure(P, (Depth +1)); } // Sanity Check @@ -519,29 +522,32 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg) unpacked, or when it has been unpacked, if Immediate==true it configures it. */ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg) { - return SmartUnPack(Pkg, true); + return SmartUnPack(Pkg, true, 0); } -bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) +bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth) { + bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); + if (Debug) { - clog << "SmartUnPack " << Pkg.Name(); + clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.Name(); VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); if (Pkg.CurrentVer() == 0) - cout << " (install version " << InstallVer.VerStr() << ")" << endl; + cout << " (install version " << InstallVer.VerStr() << ")"; else - cout << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")" << endl; + cout << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")"; + if (PkgLoop) + cout << " (Only Perform PreUnpack Checks)"; + cout << endl; } // Check if it is already unpacked if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && Cache[Pkg].Keep() == true) { - cout << "SmartUnPack called on Package " << Pkg.Name() << " but its unpacked" << endl; + cout << OutputInDepth(Depth) << "SmartUnPack called on Package " << Pkg.Name() << " but its unpacked" << endl; return false; } - bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); - VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked. @@ -561,7 +567,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) while (End->Type == pkgCache::Dep::PreDepends) { if (Debug) - clog << "PreDepends order for " << Pkg.Name() << std::endl; + clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.Name() << std::endl; // Look for possible ok targets. SPtrArray VList = Start.AllTargets(); @@ -577,7 +583,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) { Bad = false; if (Debug) - clog << "Found ok package " << Pkg.Name() << endl; + clog << OutputInDepth(Depth) << "Found ok package " << Pkg.Name() << endl; continue; } } @@ -599,8 +605,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } if (Debug) - clog << "Trying to SmartConfigure " << Pkg.Name() << endl; - Bad = !SmartConfigure(Pkg); + clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.Name() << endl; + Bad = !SmartConfigure(Pkg, Depth + 1); } /* If this or element did not match then continue on to the @@ -633,15 +639,15 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) // See if the current version is conflicting if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) { - cout << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; + cout << OutputInDepth(Depth) << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; /* If a loop is not present or has not yet been detected, attempt to unpack packages to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { if (Debug) - cout << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; + cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; List->Flag(Pkg,pkgOrderList::Loop); - SmartUnPack(ConflictPkg,false); + SmartUnPack(ConflictPkg,false, Depth + 1); // Remove loop to allow it to be used later if needed List->RmFlag(Pkg,pkgOrderList::Loop); } else { @@ -651,7 +657,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) } else { if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) { if (Debug) - cout << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; + cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; if (EarlyRemove(ConflictPkg) == false) return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); } @@ -679,15 +685,15 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) List->Flag(Pkg,pkgOrderList::Loop); // Found a break, so unpack the package if (Debug) - cout << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; - SmartUnPack(BrokenPkg, false); + SmartUnPack(BrokenPkg, false, Depth + 1); List->RmFlag(Pkg,pkgOrderList::Loop); } // Check if a package needs to be removed if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { if (Debug) - cout << " Removing " << BrokenPkg.Name() << " to avoid break" << endl; + cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid break" << endl; SmartRemove(BrokenPkg); } } @@ -715,16 +721,15 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer && (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)) continue; - SmartUnPack(P, false); + SmartUnPack(P, false, Depth + 1); } if(Install(Pkg,FileNames[Pkg->ID]) == false) return false; - if (Immediate == true && List->IsFlag(Pkg,pkgOrderList::Immediate) == true) { - + if (Immediate == true) { // Perform immedate configuration of the package. - if (SmartConfigure(Pkg) == false) + if (SmartConfigure(Pkg, Depth + 1) == false) _error->Warning(_("Could not perform immediate configuration on '%s'. " "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); } @@ -765,7 +770,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (List->IsNow(Pkg) == false) { if (!List->IsFlag(Pkg,pkgOrderList::Configured) && !NoImmConfigure) { - if (SmartConfigure(Pkg) == false && Debug) + if (SmartConfigure(Pkg, 0) == false && Debug) _error->Warning("Internal Error, Could not configure %s",Pkg.Name()); // FIXME: The above warning message might need changing } else { @@ -804,7 +809,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() return Failed; } else - if (SmartUnPack(Pkg) == false) + if (SmartUnPack(Pkg,List->IsFlag(Pkg,pkgOrderList::Immediate),0) == false) return Failed; DoneSomething = true; diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index e1878ce46..96dc5f236 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -70,10 +70,10 @@ class pkgPackageManager : protected pkgCache::Namespace // Install helpers bool ConfigureAll(); - bool SmartConfigure(PkgIterator Pkg); + bool SmartConfigure(PkgIterator Pkg, int const Depth); //FIXME: merge on abi break bool SmartUnPack(PkgIterator Pkg); - bool SmartUnPack(PkgIterator Pkg, bool const Immediate); + bool SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth); bool SmartRemove(PkgIterator Pkg); bool EarlyRemove(PkgIterator Pkg); -- cgit v1.2.3 From b57257d2993aaf8c0cf9d6f0ea8ebd0208112bc5 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 16 Aug 2011 18:00:01 +0100 Subject: Fixed a problem where the loop flag would be removed prematurely. SmartConfigure xserver-xorg-video-apm (1:1.2.3-0ubuntu1) SmartConfigure xserver-xorg-core (2:1.9.0-0ubuntu7.3) <- Loop flag set on xserver-xorg-core SmartConfigure xserver-xorg (1:7.5+6ubuntu3) SmartConfigure xserver-xorg-core (2:1.9.0-0ubuntu7.3) (Only Correct Dependancies) <- Loop flag removed prematurely SmartConfigure libpciaccess0 (0.12.0-1) SmartConfigure libpixman-1-0 (0.18.4-1) SmartConfigure xserver-xorg-video-all (1:7.5+6ubuntu3) SmartConfigure xserver-xorg-video-apm (1:1.2.3-0ubuntu1) (Only Correct Dependancies) SmartConfigure xserver-xorg-core (2:1.9.0-0ubuntu7.3) <- Incorrectly detects first run as no loop flag Also applied this fix to the SmartUnpack method. --- apt-pkg/packagemanager.cc | 49 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 53bb507b6..b5d353602 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -371,18 +371,27 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) // Check if the version that is going to be installed will satisfy the dependancy if (Cache[DepPkg].InstallVer == *I) { if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { - if (PkgLoop && List->IsFlag(DepPkg,pkgOrderList::Loop)) { + if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop) { // This dependancy has already been dealt with by another SmartConfigure on Pkg Bad = false; break; + } else if (List->IsFlag(Pkg,pkgOrderList::Loop)) { + /* Check for a loop to prevent one forming + If A depends on B and B depends on A, SmartConfigure will + just hop between them if this is not checked. Dont remove the + loop flag after finishing however as loop is already set. + This means that there is another SmartConfigure call for this + package and it will remove the loop flag */ + Bad = !SmartConfigure(DepPkg, Depth + 1); + } else { + /* Check for a loop to prevent one forming + If A depends on B and B depends on A, SmartConfigure will + just hop between them if this is not checked */ + List->Flag(Pkg,pkgOrderList::Loop); + Bad = !SmartConfigure(DepPkg, Depth + 1); + List->RmFlag(Pkg,pkgOrderList::Loop); } - /* Check for a loop to prevent one forming - If A depends on B and B depends on A, SmartConfigure will - just hop between them if this is not checked */ - List->Flag(Pkg,pkgOrderList::Loop); // If SmartConfigure was succesfull, Bad is false, so break - Bad = !SmartConfigure(DepPkg, Depth + 1); - List->RmFlag(Pkg,pkgOrderList::Loop); if (!Bad) break; } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { Bad = false; @@ -678,18 +687,28 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Check if it needs to be unpacked if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && List->IsNow(BrokenPkg)) { - if (PkgLoop && List->IsFlag(BrokenPkg,pkgOrderList::Loop)) { + if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) { // This dependancy has already been dealt with by another SmartUnPack on Pkg break; - } - List->Flag(Pkg,pkgOrderList::Loop); - // Found a break, so unpack the package - if (Debug) - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; + } else if (List->IsFlag(Pkg,pkgOrderList::Loop)) { + /* Found a break, so unpack the package, but dont remove loop as already set. + This means that there is another SmartUnPack call for this + package and it will remove the loop flag. */ + if (Debug) + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; + + SmartUnPack(BrokenPkg, false, Depth + 1); + } else { + List->Flag(Pkg,pkgOrderList::Loop); + // Found a break, so unpack the package + if (Debug) + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; - SmartUnPack(BrokenPkg, false, Depth + 1); - List->RmFlag(Pkg,pkgOrderList::Loop); + SmartUnPack(BrokenPkg, false, Depth + 1); + List->RmFlag(Pkg,pkgOrderList::Loop); + } } + // Check if a package needs to be removed if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { if (Debug) -- cgit v1.2.3