#include <apt-pkg/acquire-item.h>
#include <apt-pkg/algorithms.h>
#include <apt-pkg/configuration.h>
-#include <apt-pkg/sptr.h>
#include <apt-pkg/macros.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
// ---------------------------------------------------------------------
/* */
pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache),
- List(NULL), Res(Incomplete)
+ List(NULL), Res(Incomplete), d(NULL)
{
FileNames = new string[Cache.Head().PackageCount];
Debug = _config->FindB("Debug::pkgPackageManager",false);
return true;
}
/*}}}*/
+// PM::CheckRBreaks - Look for reverse breaks /*{{{*/
+bool pkgPackageManager::CheckRBreaks(PkgIterator const &Pkg, DepIterator D,
+ const char * const Ver)
+{
+ for (;D.end() == false; ++D)
+ {
+ if (D->Type != pkgCache::Dep::DpkgBreaks)
+ continue;
+
+ PkgIterator const DP = D.ParentPkg();
+ if (Cache[DP].Delete() == false)
+ continue;
+
+ // Ignore self conflicts, ignore conflicts from irrelevant versions
+ if (D.IsIgnorable(Pkg) || D.ParentVer() != DP.CurrentVer())
+ continue;
+
+ if (Cache.VS().CheckDep(Ver, D->CompareOp, D.TargetVer()) == false)
+ continue;
+
+ // no earlyremove() here as user has already agreed to the permanent removal
+ if (SmartRemove(DP) == false)
+ return _error->Error("Internal Error, Could not early remove %s (%d)",DP.FullName().c_str(), 4);
+ }
+ return true;
+}
+ /*}}}*/
// PM::ConfigureAll - Run the all out configuration /*{{{*/
// ---------------------------------------------------------------------
/* This configures every package. It is assumed they are all unpacked and
std::list<DepIterator> needConfigure;
do
{
+ // Check each dependency and see if anything needs to be done
+ // so that it can be configured
Changed = false;
for (DepIterator D = instVer.DependsList(); D.end() == false; )
{
continue;
Bad = true;
- // Check for dependencies that have not been unpacked, probably due to loops.
+ // the first pass checks if we its all good, i.e. if we have
+ // to do anything at all
for (DepIterator Cur = Start; true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
- for (Version **I = VList; *I != 0; ++I)
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
// Check if the current version of the package is available and will satisfy this dependency
if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
- DepPkg.State() == PkgIterator::NeedsNothing)
+ DepPkg.State() == PkgIterator::NeedsNothing &&
+ (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
{
Bad = false;
break;
if (PkgLoop == true)
{
if (Debug)
- std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl;
- Bad = false;
+ std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
+ if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
+ Bad = false;
+ else if (Debug)
+ std::clog << ", but it isn't unpacked yet";
+ if (Debug)
+ std::clog << std::endl;
+ }
+ }
+
+ if (Cur == End || Bad == false)
+ break;
+ }
+
+ // this dependency is in a good state, so we can stop
+ if (Bad == false)
+ {
+ if (Debug)
+ std::clog << OutputInDepth(Depth) << "Found ok dep " << Start.TargetPkg() << std::endl;
+ continue;
+ }
+
+ // Check for dependencies that have not been unpacked,
+ // probably due to loops.
+ for (DepIterator Cur = Start; true; ++Cur)
+ {
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
+
+ for (Version **I = VList.get(); *I != 0; ++I)
+ {
+ VerIterator Ver(Cache,*I);
+ PkgIterator DepPkg = Ver.ParentPkg();
+
+ // Check if the current version of the package is available and will satisfy this dependency
+ if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true &&
+ List->IsFlag(DepPkg,pkgOrderList::Removed) == false &&
+ DepPkg.State() == PkgIterator::NeedsNothing &&
+ (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
+ continue;
+
+ // Check if the version that is going to be installed will satisfy the dependency
+ if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false)
+ continue;
+
+ if (PkgLoop == true)
+ {
+ if (Debug)
+ std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure";
+ if (List->IsFlag(DepPkg,pkgOrderList::UnPacked))
+ Bad = false;
+ else if (Debug)
+ std::clog << ", but it isn't unpacked yet";
+ if (Debug)
+ std::clog << std::endl;
}
else
{
if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
return false;
}
+ // at this point we either unpacked a Dep or we are in a loop,
+ // no need to unpack a second one
break;
}
return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack (1) for %s, aborting", Pkg.FullName().c_str());
} while (Changed == true);
+ // now go over anything that needs configuring
Bad = false, Changed = false, i = 0;
do
{
// Search for dependencies which are unpacked but aren't configured yet (maybe loops)
for (DepIterator Cur = Start; true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
- for (Version **I = VList; *I != 0; ++I)
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
if (Bad == true)
return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str());
+ // Check for reverse conflicts.
+ if (CheckRBreaks(Pkg,Pkg.RevDependsList(), instVer.VerStr()) == false)
+ return false;
+
+ for (PrvIterator P = instVer.ProvidesList(); P.end() == false; ++P)
+ if (Pkg->Group != P.OwnerPkg()->Group)
+ CheckRBreaks(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
+
if (PkgLoop) return true;
static std::string const conf = _config->Find("PackageManager::Configure","all");
// Look for easy targets: packages that are already okay
for (DepIterator Cur = Start; Bad == true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
- for (Version **I = VList; *I != 0; ++I)
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator Pkg = Ver.ParentPkg();
// See if the current version is ok
if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true &&
- Pkg.State() == PkgIterator::NeedsNothing)
+ Pkg.State() == PkgIterator::NeedsNothing &&
+ (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
{
Bad = false;
if (Debug)
// Look for something that could be configured.
for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
- for (Version **I = VList; *I != 0; ++I)
+ std::unique_ptr<Version *[]> VList(Cur.AllTargets());
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
// Not the install version
- if (Cache[DepPkg].InstallVer != *I ||
- (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing))
+ if (Cache[DepPkg].InstallVer != *I)
+ continue;
+
+ if (Cache[DepPkg].Keep() == true && DepPkg.State() == PkgIterator::NeedsNothing &&
+ (Cache[DepPkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall)
continue;
if (List->IsFlag(DepPkg,pkgOrderList::Configured))
// check if it needs unpack or if if configure is enough
if (List->IsFlag(DepPkg,pkgOrderList::UnPacked) == false)
{
+ // two packages pre-depending on each other can't be handled sanely
+ if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop)
+ {
+ // this isn't an error as there is potential for something else to satisfy it
+ // (like a provides or an or-group member)
+ if (Debug)
+ clog << OutputInDepth(Depth) << "Unpack loop detected between " << DepPkg.FullName() << " and " << Pkg.FullName() << endl;
+ continue;
+ }
+
if (Debug)
clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << DepPkg.FullName() << endl;
if (NonLoopingSmart(UNPACK_IMMEDIATE, Pkg, DepPkg, Depth, PkgLoop, &Bad, &Changed) == false)
End->Type == pkgCache::Dep::Obsoletes ||
End->Type == pkgCache::Dep::DpkgBreaks)
{
- SPtrArray<Version *> VList = End.AllTargets();
- for (Version **I = VList; *I != 0; ++I)
+ std::unique_ptr<Version *[]> VList(End.AllTargets());
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator ConflictPkg = Ver.ParentPkg();
clog << OutputInDepth(Depth) << "Because of conflict knot, removing " << ConflictPkg.FullName() << " temporarily" << endl;
}
if (EarlyRemove(ConflictPkg, &End) == false)
- return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str());
+ return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 3);
SomethingBad = true;
continue;
}
// but if it fails ignore this failure and look for alternative ways of solving
if (Debug)
{
- clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << End << std::endl;
+ clog << OutputInDepth(Depth) << "Avoidance unpack of " << ConflictPkg.FullName() << " failed for " << End << " ignoring:" << std::endl;
_error->DumpErrors(std::clog);
}
_error->RevertToStack();
if (Debug)
clog << OutputInDepth(Depth) << "So temprorary remove/deconfigure " << ConflictPkg.FullName() << " to satisfy " << End << endl;
if (EarlyRemove(ConflictPkg, &End) == false)
- return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str());
+ return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 2);
}
}
else
clog << OutputInDepth(Depth) << "Removing " << ConflictPkg.FullName() << " now to avoid " << End << endl;
// no earlyremove() here as user has already agreed to the permanent removal
if (SmartRemove(Pkg) == false)
- return _error->Error("Internal Error, Could not early remove %s (1)",ConflictPkg.FullName().c_str());
+ return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 1);
}
}
}
// PM::DoInstallPostFork - compat /*{{{*/
// ---------------------------------------------------------------------
/*}}}*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
pkgPackageManager::OrderResult
pkgPackageManager::DoInstallPostFork(int statusFd)
{
if(goResult == false)
return Failed;
- return Res;
-};
-#else
-pkgPackageManager::OrderResult
-pkgPackageManager::DoInstallPostFork(int statusFd)
-{
- bool goResult = Go(statusFd);
- if(goResult == false)
- return Failed;
-
return Res;
}
-#endif
/*}}}*/
// PM::DoInstall - Does the installation /*{{{*/
// ---------------------------------------------------------------------
/* compat */
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
pkgPackageManager::OrderResult
pkgPackageManager::DoInstall(int statusFd)
{
delete progress;
return res;
}
-#else
-pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
-{
- if(DoInstallPreFork() == Failed)
- return Failed;
-
- return DoInstallPostFork(statusFd);
-}
-#endif
/*}}}*/
// PM::DoInstall - Does the installation /*{{{*/
// ---------------------------------------------------------------------
/* This uses the filenames in FileNames and the information in the
DepCache to perform the installation of packages.*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
pkgPackageManager::OrderResult
pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
{
return DoInstallPostFork(progress);
}
-#endif
/*}}}*/