- VerIterator Ver(Cache,*I);
- PkgIterator BrokenPkg = Ver.ParentPkg();
- VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer);
-
- // Check if it needs to be unpacked
- if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false &&
- List->IsNow(BrokenPkg)) {
- if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) {
- // This dependancy has already been dealt with by another SmartUnPack on Pkg
- break;
- } 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);
- }
- }
-
- // Check if a package needs to be removed
- if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) {
- if (Debug)
- cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid break" << endl;
- SmartRemove(BrokenPkg);
+ SPtrArray<Version *> VList = End.AllTargets();
+ for (Version **I = VList; *I != 0; ++I)
+ {
+ VerIterator Ver(Cache,*I);
+ PkgIterator BrokenPkg = Ver.ParentPkg();
+ if (BrokenPkg.CurrentVer() != Ver)
+ {
+ if (Debug)
+ std::clog << OutputInDepth(Depth) << " Ignore not-installed version " << Ver.VerStr() << " of " << Pkg.FullName() << " for " << End << std::endl;
+ continue;
+ }
+
+ // Check if it needs to be unpacked
+ if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false &&
+ List->IsNow(BrokenPkg))
+ {
+ if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop)
+ {
+ // This dependancy has already been dealt with by another SmartUnPack on Pkg
+ break;
+ }
+ else
+ {
+ // Found a break, so see if we can unpack the package to avoid it
+ // but do not set loop if another SmartUnPack already deals with it
+ // Also, avoid it if the package we would unpack pre-depends on this one
+ VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer);
+ bool circle = false;
+ for (pkgCache::DepIterator D = InstallVer.DependsList(); D.end() == false; ++D)
+ {
+ if (D->Type != pkgCache::Dep::PreDepends)
+ continue;
+ SPtrArray<Version *> VL = D.AllTargets();
+ for (Version **I = VL; *I != 0; ++I)
+ {
+ VerIterator V(Cache,*I);
+ PkgIterator P = V.ParentPkg();
+ // we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers
+ if (P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V))
+ continue;
+ circle = true;
+ break;
+ }
+ if (circle == true)
+ break;
+ }
+ if (circle == true)
+ {
+ if (Debug)
+ clog << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl;
+ continue;
+ }
+ else
+ {
+ if (Debug)
+ {
+ clog << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End;
+ if (PkgLoop == true)
+ clog << " (Looping)";
+ clog << std::endl;
+ }
+ if (PkgLoop == false)
+ List->Flag(Pkg,pkgOrderList::Loop);
+ if (SmartUnPack(BrokenPkg, false, Depth + 1) == true)
+ {
+ if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) == false)
+ Changed = true;
+ }
+ if (PkgLoop == false)
+ List->RmFlag(Pkg,pkgOrderList::Loop);
+ }
+ }
+ }
+ // Check if a package needs to be removed
+ else if (Cache[BrokenPkg].Delete() == true && List->IsFlag(BrokenPkg,pkgOrderList::Configured) == false)
+ {
+ if (Debug)
+ clog << OutputInDepth(Depth) << " Removing " << BrokenPkg.FullName() << " to avoid " << End << endl;
+ SmartRemove(BrokenPkg);
+ }