+
+ // Check for dependanices that have not been unpacked, probably due to loops.
+ bool Bad = true;
+ while (End->Type == pkgCache::Dep::Depends) {
+ PkgIterator DepPkg;
+ SPtrArray<Version *> 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++;
+ }
+ }