depcache.cc 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: depcache.cc,v 1.25 2001/05/27 05:36:04 jgg Exp $
  4. /* ######################################################################
  5. Dependency Cache - Caches Dependency information.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include<config.h>
  10. #include <apt-pkg/depcache.h>
  11. #include <apt-pkg/version.h>
  12. #include <apt-pkg/versionmatch.h>
  13. #include <apt-pkg/error.h>
  14. #include <apt-pkg/sptr.h>
  15. #include <apt-pkg/algorithms.h>
  16. #include <apt-pkg/fileutl.h>
  17. #include <apt-pkg/strutl.h>
  18. #include <apt-pkg/configuration.h>
  19. #include <apt-pkg/aptconfiguration.h>
  20. #include <apt-pkg/pkgsystem.h>
  21. #include <apt-pkg/tagfile.h>
  22. #include <apt-pkg/progress.h>
  23. #include <apt-pkg/cacheset.h>
  24. #include <algorithm>
  25. #include <iostream>
  26. #include <sstream>
  27. #include <set>
  28. #include <sys/stat.h>
  29. #include <apti18n.h>
  30. /*}}}*/
  31. using std::string;
  32. // helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
  33. static bool
  34. ConfigValueInSubTree(const char* SubTree, const char *needle)
  35. {
  36. Configuration::Item const *Opts;
  37. Opts = _config->Tree(SubTree);
  38. if (Opts != 0 && Opts->Child != 0)
  39. {
  40. Opts = Opts->Child;
  41. for (; Opts != 0; Opts = Opts->Next)
  42. {
  43. if (Opts->Value.empty() == true)
  44. continue;
  45. if (strcmp(needle, Opts->Value.c_str()) == 0)
  46. return true;
  47. }
  48. }
  49. return false;
  50. }
  51. /*}}}*/
  52. pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) : /*{{{*/
  53. cache(cache), released(false)
  54. {
  55. ++cache.group_level;
  56. }
  57. void pkgDepCache::ActionGroup::release()
  58. {
  59. if(!released)
  60. {
  61. if(cache.group_level == 0)
  62. std::cerr << "W: Unbalanced action groups, expect badness" << std::endl;
  63. else
  64. {
  65. --cache.group_level;
  66. if(cache.group_level == 0)
  67. cache.MarkAndSweep();
  68. }
  69. released = true;
  70. }
  71. }
  72. pkgDepCache::ActionGroup::~ActionGroup()
  73. {
  74. release();
  75. }
  76. /*}}}*/
  77. // DepCache::pkgDepCache - Constructors /*{{{*/
  78. // ---------------------------------------------------------------------
  79. /* */
  80. pkgDepCache::pkgDepCache(pkgCache *pCache,Policy *Plcy) :
  81. group_level(0), Cache(pCache), PkgState(0), DepState(0)
  82. {
  83. DebugMarker = _config->FindB("Debug::pkgDepCache::Marker", false);
  84. DebugAutoInstall = _config->FindB("Debug::pkgDepCache::AutoInstall", false);
  85. delLocalPolicy = 0;
  86. LocalPolicy = Plcy;
  87. if (LocalPolicy == 0)
  88. delLocalPolicy = LocalPolicy = new Policy;
  89. }
  90. /*}}}*/
  91. // DepCache::~pkgDepCache - Destructor /*{{{*/
  92. // ---------------------------------------------------------------------
  93. /* */
  94. pkgDepCache::~pkgDepCache()
  95. {
  96. delete [] PkgState;
  97. delete [] DepState;
  98. delete delLocalPolicy;
  99. }
  100. /*}}}*/
  101. // DepCache::Init - Generate the initial extra structures. /*{{{*/
  102. // ---------------------------------------------------------------------
  103. /* This allocats the extension buffers and initializes them. */
  104. bool pkgDepCache::Init(OpProgress *Prog)
  105. {
  106. // Suppress mark updates during this operation (just in case) and
  107. // run a mark operation when Init terminates.
  108. ActionGroup actions(*this);
  109. delete [] PkgState;
  110. delete [] DepState;
  111. PkgState = new StateCache[Head().PackageCount];
  112. DepState = new unsigned char[Head().DependsCount];
  113. memset(PkgState,0,sizeof(*PkgState)*Head().PackageCount);
  114. memset(DepState,0,sizeof(*DepState)*Head().DependsCount);
  115. if (Prog != 0)
  116. {
  117. Prog->OverallProgress(0,2*Head().PackageCount,Head().PackageCount,
  118. _("Building dependency tree"));
  119. Prog->SubProgress(Head().PackageCount,_("Candidate versions"));
  120. }
  121. /* Set the current state of everything. In this state all of the
  122. packages are kept exactly as is. See AllUpgrade */
  123. int Done = 0;
  124. for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done)
  125. {
  126. if (Prog != 0 && Done%20 == 0)
  127. Prog->Progress(Done);
  128. // Find the proper cache slot
  129. StateCache &State = PkgState[I->ID];
  130. State.iFlags = 0;
  131. // Figure out the install version
  132. State.CandidateVer = GetCandidateVer(I);
  133. State.InstallVer = I.CurrentVer();
  134. State.Mode = ModeKeep;
  135. State.Update(I,*this);
  136. }
  137. if (Prog != 0)
  138. {
  139. Prog->OverallProgress(Head().PackageCount,2*Head().PackageCount,
  140. Head().PackageCount,
  141. _("Building dependency tree"));
  142. Prog->SubProgress(Head().PackageCount,_("Dependency generation"));
  143. }
  144. Update(Prog);
  145. if(Prog != 0)
  146. Prog->Done();
  147. return true;
  148. }
  149. /*}}}*/
  150. bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/
  151. {
  152. FileFd state_file;
  153. string const state = _config->FindFile("Dir::State::extended_states");
  154. if(RealFileExists(state)) {
  155. state_file.Open(state, FileFd::ReadOnly);
  156. off_t const file_size = state_file.Size();
  157. if(Prog != NULL)
  158. Prog->OverallProgress(0, file_size, 1,
  159. _("Reading state information"));
  160. pkgTagFile tagfile(&state_file);
  161. pkgTagSection section;
  162. off_t amt = 0;
  163. bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
  164. while(tagfile.Step(section)) {
  165. string const pkgname = section.FindS("Package");
  166. string pkgarch = section.FindS("Architecture");
  167. if (pkgarch.empty() == true)
  168. pkgarch = "any";
  169. pkgCache::PkgIterator pkg = Cache->FindPkg(pkgname, pkgarch);
  170. // Silently ignore unknown packages and packages with no actual version.
  171. if(pkg.end() == true || pkg->VersionList == 0)
  172. continue;
  173. short const reason = section.FindI("Auto-Installed", 0);
  174. if(reason > 0)
  175. {
  176. PkgState[pkg->ID].Flags |= Flag::Auto;
  177. if (unlikely(debug_autoremove))
  178. std::clog << "Auto-Installed : " << pkg.FullName() << std::endl;
  179. if (pkgarch == "any")
  180. {
  181. pkgCache::GrpIterator G = pkg.Group();
  182. for (pkg = G.NextPkg(pkg); pkg.end() != true; pkg = G.NextPkg(pkg))
  183. if (pkg->VersionList != 0)
  184. PkgState[pkg->ID].Flags |= Flag::Auto;
  185. }
  186. }
  187. amt += section.size();
  188. if(Prog != NULL)
  189. Prog->OverallProgress(amt, file_size, 1,
  190. _("Reading state information"));
  191. }
  192. if(Prog != NULL)
  193. Prog->OverallProgress(file_size, file_size, 1,
  194. _("Reading state information"));
  195. }
  196. return true;
  197. }
  198. /*}}}*/
  199. bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/
  200. {
  201. bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
  202. if(debug_autoremove)
  203. std::clog << "pkgDepCache::writeStateFile()" << std::endl;
  204. FileFd StateFile;
  205. string const state = _config->FindFile("Dir::State::extended_states");
  206. // if it does not exist, create a empty one
  207. if(!RealFileExists(state))
  208. {
  209. StateFile.Open(state, FileFd::WriteAtomic);
  210. StateFile.Close();
  211. }
  212. // open it
  213. if(!StateFile.Open(state, FileFd::ReadOnly))
  214. return _error->Error(_("Failed to open StateFile %s"),
  215. state.c_str());
  216. FILE *OutFile;
  217. string const outfile = state + ".tmp";
  218. if((OutFile = fopen(outfile.c_str(),"w")) == NULL)
  219. return _error->Error(_("Failed to write temporary StateFile %s"),
  220. outfile.c_str());
  221. // first merge with the existing sections
  222. pkgTagFile tagfile(&StateFile);
  223. pkgTagSection section;
  224. std::set<string> pkgs_seen;
  225. const char *nullreorderlist[] = {0};
  226. while(tagfile.Step(section)) {
  227. string const pkgname = section.FindS("Package");
  228. string pkgarch = section.FindS("Architecture");
  229. if (pkgarch.empty() == true)
  230. pkgarch = "native";
  231. // Silently ignore unknown packages and packages with no actual
  232. // version.
  233. pkgCache::PkgIterator pkg = Cache->FindPkg(pkgname, pkgarch);
  234. if(pkg.end() || pkg.VersionList().end())
  235. continue;
  236. StateCache const &P = PkgState[pkg->ID];
  237. bool newAuto = (P.Flags & Flag::Auto);
  238. // skip not installed or now-removed ones if requested
  239. if (InstalledOnly && (
  240. (pkg->CurrentVer == 0 && P.Mode != ModeInstall) ||
  241. (pkg->CurrentVer != 0 && P.Mode == ModeDelete)))
  242. {
  243. // The section is obsolete if it contains no other tag
  244. unsigned int const count = section.Count();
  245. if (count < 2 ||
  246. (count == 2 && section.Exists("Auto-Installed")) ||
  247. (count == 3 && section.Exists("Auto-Installed") && section.Exists("Architecture")))
  248. continue;
  249. else
  250. newAuto = false;
  251. }
  252. if(_config->FindB("Debug::pkgAutoRemove",false))
  253. std::clog << "Update existing AutoInstall info: "
  254. << pkg.FullName() << std::endl;
  255. TFRewriteData rewrite[3];
  256. rewrite[0].Tag = "Architecture";
  257. rewrite[0].Rewrite = pkg.Arch();
  258. rewrite[0].NewTag = 0;
  259. rewrite[1].Tag = "Auto-Installed";
  260. rewrite[1].Rewrite = newAuto ? "1" : "0";
  261. rewrite[1].NewTag = 0;
  262. rewrite[2].Tag = 0;
  263. TFRewrite(OutFile, section, nullreorderlist, rewrite);
  264. fprintf(OutFile,"\n");
  265. pkgs_seen.insert(pkg.FullName());
  266. }
  267. // then write the ones we have not seen yet
  268. std::ostringstream ostr;
  269. for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); ++pkg) {
  270. StateCache const &P = PkgState[pkg->ID];
  271. if(P.Flags & Flag::Auto) {
  272. if (pkgs_seen.find(pkg.FullName()) != pkgs_seen.end()) {
  273. if(debug_autoremove)
  274. std::clog << "Skipping already written " << pkg.FullName() << std::endl;
  275. continue;
  276. }
  277. // skip not installed ones if requested
  278. if (InstalledOnly && (
  279. (pkg->CurrentVer == 0 && P.Mode != ModeInstall) ||
  280. (pkg->CurrentVer != 0 && P.Mode == ModeDelete)))
  281. continue;
  282. const char* const pkgarch = pkg.Arch();
  283. if (strcmp(pkgarch, "all") == 0)
  284. continue;
  285. if(debug_autoremove)
  286. std::clog << "Writing new AutoInstall: " << pkg.FullName() << std::endl;
  287. ostr.str(string(""));
  288. ostr << "Package: " << pkg.Name()
  289. << "\nArchitecture: " << pkgarch
  290. << "\nAuto-Installed: 1\n\n";
  291. fprintf(OutFile,"%s",ostr.str().c_str());
  292. }
  293. }
  294. fclose(OutFile);
  295. // move the outfile over the real file and set permissions
  296. rename(outfile.c_str(), state.c_str());
  297. chmod(state.c_str(), 0644);
  298. return true;
  299. }
  300. /*}}}*/
  301. // DepCache::CheckDep - Checks a single dependency /*{{{*/
  302. // ---------------------------------------------------------------------
  303. /* This first checks the dependency against the main target package and
  304. then walks along the package provides list and checks if each provides
  305. will be installed then checks the provides against the dep. Res will be
  306. set to the package which was used to satisfy the dep. */
  307. bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
  308. {
  309. Res = Dep.TargetPkg();
  310. /* Check simple depends. A depends -should- never self match but
  311. we allow it anyhow because dpkg does. Technically it is a packaging
  312. bug. Conflicts may never self match */
  313. if (Dep.TargetPkg() != Dep.ParentPkg() || Dep.IsNegative() == false)
  314. {
  315. PkgIterator Pkg = Dep.TargetPkg();
  316. // Check the base package
  317. if (Type == NowVersion && Pkg->CurrentVer != 0)
  318. if (VS().CheckDep(Pkg.CurrentVer().VerStr(),Dep->CompareOp,
  319. Dep.TargetVer()) == true)
  320. return true;
  321. if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0)
  322. if (VS().CheckDep(PkgState[Pkg->ID].InstVerIter(*this).VerStr(),
  323. Dep->CompareOp,Dep.TargetVer()) == true)
  324. return true;
  325. if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0)
  326. if (VS().CheckDep(PkgState[Pkg->ID].CandidateVerIter(*this).VerStr(),
  327. Dep->CompareOp,Dep.TargetVer()) == true)
  328. return true;
  329. }
  330. if (Dep->Type == Dep::Obsoletes)
  331. return false;
  332. // Check the providing packages
  333. PrvIterator P = Dep.TargetPkg().ProvidesList();
  334. PkgIterator Pkg = Dep.ParentPkg();
  335. for (; P.end() != true; ++P)
  336. {
  337. /* Provides may never be applied against the same package (or group)
  338. if it is a conflicts. See the comment above. */
  339. if (P.OwnerPkg()->Group == Pkg->Group && Dep.IsNegative() == true)
  340. continue;
  341. // Check if the provides is a hit
  342. if (Type == NowVersion)
  343. {
  344. if (P.OwnerPkg().CurrentVer() != P.OwnerVer())
  345. continue;
  346. }
  347. if (Type == InstallVersion)
  348. {
  349. StateCache &State = PkgState[P.OwnerPkg()->ID];
  350. if (State.InstallVer != (Version *)P.OwnerVer())
  351. continue;
  352. }
  353. if (Type == CandidateVersion)
  354. {
  355. StateCache &State = PkgState[P.OwnerPkg()->ID];
  356. if (State.CandidateVer != (Version *)P.OwnerVer())
  357. continue;
  358. }
  359. // Compare the versions.
  360. if (VS().CheckDep(P.ProvideVersion(),Dep->CompareOp,Dep.TargetVer()) == true)
  361. {
  362. Res = P.OwnerPkg();
  363. return true;
  364. }
  365. }
  366. return false;
  367. }
  368. /*}}}*/
  369. // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
  370. // ---------------------------------------------------------------------
  371. /* Call with Inverse = true to preform the inverse opration */
  372. void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const Inverse)
  373. {
  374. StateCache &P = PkgState[Pkg->ID];
  375. if (Pkg->VersionList == 0)
  376. return;
  377. if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
  378. P.Keep() == true)
  379. return;
  380. // Compute the size data
  381. if (P.NewInstall() == true)
  382. {
  383. if (Inverse == false) {
  384. iUsrSize += P.InstVerIter(*this)->InstalledSize;
  385. iDownloadSize += P.InstVerIter(*this)->Size;
  386. } else {
  387. iUsrSize -= P.InstVerIter(*this)->InstalledSize;
  388. iDownloadSize -= P.InstVerIter(*this)->Size;
  389. }
  390. return;
  391. }
  392. // Upgrading
  393. if (Pkg->CurrentVer != 0 &&
  394. (P.InstallVer != (Version *)Pkg.CurrentVer() ||
  395. (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0)
  396. {
  397. if (Inverse == false) {
  398. iUsrSize -= Pkg.CurrentVer()->InstalledSize;
  399. iUsrSize += P.InstVerIter(*this)->InstalledSize;
  400. iDownloadSize += P.InstVerIter(*this)->Size;
  401. } else {
  402. iUsrSize -= P.InstVerIter(*this)->InstalledSize;
  403. iUsrSize += Pkg.CurrentVer()->InstalledSize;
  404. iDownloadSize -= P.InstVerIter(*this)->Size;
  405. }
  406. return;
  407. }
  408. // Reinstall
  409. if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack &&
  410. P.Delete() == false)
  411. {
  412. if (Inverse == false)
  413. iDownloadSize += P.InstVerIter(*this)->Size;
  414. else
  415. iDownloadSize -= P.InstVerIter(*this)->Size;
  416. return;
  417. }
  418. // Removing
  419. if (Pkg->CurrentVer != 0 && P.InstallVer == 0)
  420. {
  421. if (Inverse == false)
  422. iUsrSize -= Pkg.CurrentVer()->InstalledSize;
  423. else
  424. iUsrSize += Pkg.CurrentVer()->InstalledSize;
  425. return;
  426. }
  427. }
  428. /*}}}*/
  429. // DepCache::AddStates - Add the package to the state counter /*{{{*/
  430. // ---------------------------------------------------------------------
  431. /* This routine is tricky to use, you must make sure that it is never
  432. called twice for the same package. This means the Remove/Add section
  433. should be as short as possible and not encompass any code that will
  434. calld Remove/Add itself. Remember, dependencies can be circular so
  435. while processing a dep for Pkg it is possible that Add/Remove
  436. will be called on Pkg */
  437. void pkgDepCache::AddStates(const PkgIterator &Pkg, bool const Invert)
  438. {
  439. signed char const Add = (Invert == false) ? 1 : -1;
  440. StateCache &State = PkgState[Pkg->ID];
  441. // The Package is broken (either minimal dep or policy dep)
  442. if ((State.DepState & DepInstMin) != DepInstMin)
  443. iBrokenCount += Add;
  444. if ((State.DepState & DepInstPolicy) != DepInstPolicy)
  445. iPolicyBrokenCount += Add;
  446. // Bad state
  447. if (Pkg.State() != PkgIterator::NeedsNothing)
  448. iBadCount += Add;
  449. // Not installed
  450. if (Pkg->CurrentVer == 0)
  451. {
  452. if (State.Mode == ModeDelete &&
  453. (State.iFlags & Purge) == Purge && Pkg.Purge() == false)
  454. iDelCount += Add;
  455. if (State.Mode == ModeInstall)
  456. iInstCount += Add;
  457. return;
  458. }
  459. // Installed, no upgrade
  460. if (State.Status == 0)
  461. {
  462. if (State.Mode == ModeDelete)
  463. iDelCount += Add;
  464. else
  465. if ((State.iFlags & ReInstall) == ReInstall)
  466. iInstCount += Add;
  467. return;
  468. }
  469. // Alll 3 are possible
  470. if (State.Mode == ModeDelete)
  471. iDelCount += Add;
  472. if (State.Mode == ModeKeep)
  473. iKeepCount += Add;
  474. if (State.Mode == ModeInstall)
  475. iInstCount += Add;
  476. }
  477. /*}}}*/
  478. // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/
  479. // ---------------------------------------------------------------------
  480. /* The or group results are stored in the last item of the or group. This
  481. allows easy detection of the state of a whole or'd group. */
  482. void pkgDepCache::BuildGroupOrs(VerIterator const &V)
  483. {
  484. unsigned char Group = 0;
  485. for (DepIterator D = V.DependsList(); D.end() != true; ++D)
  486. {
  487. // Build the dependency state.
  488. unsigned char &State = DepState[D->ID];
  489. /* Invert for Conflicts. We have to do this twice to get the
  490. right sense for a conflicts group */
  491. if (D.IsNegative() == true)
  492. State = ~State;
  493. // Add to the group if we are within an or..
  494. State &= 0x7;
  495. Group |= State;
  496. State |= Group << 3;
  497. if ((D->CompareOp & Dep::Or) != Dep::Or)
  498. Group = 0;
  499. // Invert for Conflicts
  500. if (D.IsNegative() == true)
  501. State = ~State;
  502. }
  503. }
  504. /*}}}*/
  505. // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/
  506. // ---------------------------------------------------------------------
  507. /* This is used to run over a dependency list and determine the dep
  508. state of the list, filtering it through both a Min check and a Policy
  509. check. The return result will have SetMin/SetPolicy low if a check
  510. fails. It uses the DepState cache for it's computations. */
  511. unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check,
  512. unsigned char SetMin,
  513. unsigned char SetPolicy)
  514. {
  515. unsigned char Dep = 0xFF;
  516. while (D.end() != true)
  517. {
  518. // Compute a single dependency element (glob or)
  519. DepIterator Start = D;
  520. unsigned char State = 0;
  521. for (bool LastOR = true; D.end() == false && LastOR == true; ++D)
  522. {
  523. State |= DepState[D->ID];
  524. LastOR = (D->CompareOp & Dep::Or) == Dep::Or;
  525. }
  526. // Minimum deps that must be satisfied to have a working package
  527. if (Start.IsCritical() == true)
  528. if ((State & Check) != Check)
  529. Dep &= ~SetMin;
  530. // Policy deps that must be satisfied to install the package
  531. if (IsImportantDep(Start) == true &&
  532. (State & Check) != Check)
  533. Dep &= ~SetPolicy;
  534. }
  535. return Dep;
  536. }
  537. /*}}}*/
  538. // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/
  539. // ---------------------------------------------------------------------
  540. /* This is the main dependency computation bit. It computes the 3 main
  541. results for a dependencys, Now, Install and Candidate. Callers must
  542. invert the result if dealing with conflicts. */
  543. unsigned char pkgDepCache::DependencyState(DepIterator &D)
  544. {
  545. unsigned char State = 0;
  546. if (CheckDep(D,NowVersion) == true)
  547. State |= DepNow;
  548. if (CheckDep(D,InstallVersion) == true)
  549. State |= DepInstall;
  550. if (CheckDep(D,CandidateVersion) == true)
  551. State |= DepCVer;
  552. return State;
  553. }
  554. /*}}}*/
  555. // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/
  556. // ---------------------------------------------------------------------
  557. /* This determines the combined dependency representation of a package
  558. for its two states now and install. This is done by using the pre-generated
  559. dependency information. */
  560. void pkgDepCache::UpdateVerState(PkgIterator Pkg)
  561. {
  562. // Empty deps are always true
  563. StateCache &State = PkgState[Pkg->ID];
  564. State.DepState = 0xFF;
  565. // Check the Current state
  566. if (Pkg->CurrentVer != 0)
  567. {
  568. DepIterator D = Pkg.CurrentVer().DependsList();
  569. State.DepState &= VersionState(D,DepNow,DepNowMin,DepNowPolicy);
  570. }
  571. /* Check the candidate state. We do not compare against the whole as
  572. a candidate state but check the candidate version against the
  573. install states */
  574. if (State.CandidateVer != 0)
  575. {
  576. DepIterator D = State.CandidateVerIter(*this).DependsList();
  577. State.DepState &= VersionState(D,DepInstall,DepCandMin,DepCandPolicy);
  578. }
  579. // Check target state which can only be current or installed
  580. if (State.InstallVer != 0)
  581. {
  582. DepIterator D = State.InstVerIter(*this).DependsList();
  583. State.DepState &= VersionState(D,DepInstall,DepInstMin,DepInstPolicy);
  584. }
  585. }
  586. /*}}}*/
  587. // DepCache::Update - Figure out all the state information /*{{{*/
  588. // ---------------------------------------------------------------------
  589. /* This will figure out the state of all the packages and all the
  590. dependencies based on the current policy. */
  591. void pkgDepCache::Update(OpProgress *Prog)
  592. {
  593. iUsrSize = 0;
  594. iDownloadSize = 0;
  595. iDelCount = 0;
  596. iInstCount = 0;
  597. iKeepCount = 0;
  598. iBrokenCount = 0;
  599. iBadCount = 0;
  600. // Perform the depends pass
  601. int Done = 0;
  602. for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done)
  603. {
  604. if (Prog != 0 && Done%20 == 0)
  605. Prog->Progress(Done);
  606. for (VerIterator V = I.VersionList(); V.end() != true; ++V)
  607. {
  608. unsigned char Group = 0;
  609. for (DepIterator D = V.DependsList(); D.end() != true; ++D)
  610. {
  611. // Build the dependency state.
  612. unsigned char &State = DepState[D->ID];
  613. State = DependencyState(D);
  614. // Add to the group if we are within an or..
  615. Group |= State;
  616. State |= Group << 3;
  617. if ((D->CompareOp & Dep::Or) != Dep::Or)
  618. Group = 0;
  619. // Invert for Conflicts
  620. if (D.IsNegative() == true)
  621. State = ~State;
  622. }
  623. }
  624. // Compute the package dependency state and size additions
  625. AddSizes(I);
  626. UpdateVerState(I);
  627. AddStates(I);
  628. }
  629. if (Prog != 0)
  630. Prog->Progress(Done);
  631. readStateFile(Prog);
  632. }
  633. /*}}}*/
  634. // DepCache::Update - Update the deps list of a package /*{{{*/
  635. // ---------------------------------------------------------------------
  636. /* This is a helper for update that only does the dep portion of the scan.
  637. It is mainly meant to scan reverse dependencies. */
  638. void pkgDepCache::Update(DepIterator D)
  639. {
  640. // Update the reverse deps
  641. for (;D.end() != true; ++D)
  642. {
  643. unsigned char &State = DepState[D->ID];
  644. State = DependencyState(D);
  645. // Invert for Conflicts
  646. if (D.IsNegative() == true)
  647. State = ~State;
  648. RemoveStates(D.ParentPkg());
  649. BuildGroupOrs(D.ParentVer());
  650. UpdateVerState(D.ParentPkg());
  651. AddStates(D.ParentPkg());
  652. }
  653. }
  654. /*}}}*/
  655. // DepCache::Update - Update the related deps of a package /*{{{*/
  656. // ---------------------------------------------------------------------
  657. /* This is called whenever the state of a package changes. It updates
  658. all cached dependencies related to this package. */
  659. void pkgDepCache::Update(PkgIterator const &Pkg)
  660. {
  661. // Recompute the dep of the package
  662. RemoveStates(Pkg);
  663. UpdateVerState(Pkg);
  664. AddStates(Pkg);
  665. // Update the reverse deps
  666. Update(Pkg.RevDependsList());
  667. // Update the provides map for the current ver
  668. if (Pkg->CurrentVer != 0)
  669. for (PrvIterator P = Pkg.CurrentVer().ProvidesList();
  670. P.end() != true; ++P)
  671. Update(P.ParentPkg().RevDependsList());
  672. // Update the provides map for the candidate ver
  673. if (PkgState[Pkg->ID].CandidateVer != 0)
  674. for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList();
  675. P.end() != true; ++P)
  676. Update(P.ParentPkg().RevDependsList());
  677. }
  678. /*}}}*/
  679. // DepCache::MarkKeep - Put the package in the keep state /*{{{*/
  680. // ---------------------------------------------------------------------
  681. /* */
  682. bool pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
  683. unsigned long Depth)
  684. {
  685. if (IsModeChangeOk(ModeKeep, Pkg, Depth, FromUser) == false)
  686. return false;
  687. /* Reject an attempt to keep a non-source broken installed package, those
  688. must be upgraded */
  689. if (Pkg.State() == PkgIterator::NeedsUnpack &&
  690. Pkg.CurrentVer().Downloadable() == false)
  691. return false;
  692. /* We changed the soft state all the time so the UI is a bit nicer
  693. to use */
  694. StateCache &P = PkgState[Pkg->ID];
  695. // Check that it is not already kept
  696. if (P.Mode == ModeKeep)
  697. return true;
  698. if (Soft == true)
  699. P.iFlags |= AutoKept;
  700. else
  701. P.iFlags &= ~AutoKept;
  702. ActionGroup group(*this);
  703. #if 0 // reseting the autoflag here means we lose the
  704. // auto-mark information if a user selects a package for removal
  705. // but changes his mind then and sets it for keep again
  706. // - this makes sense as default when all Garbage dependencies
  707. // are automatically marked for removal (as aptitude does).
  708. // setting a package for keep then makes it no longer autoinstalled
  709. // for all other use-case this action is rather suprising
  710. if(FromUser && !P.Marked)
  711. P.Flags &= ~Flag::Auto;
  712. #endif
  713. if (DebugMarker == true)
  714. std::clog << OutputInDepth(Depth) << "MarkKeep " << Pkg << " FU=" << FromUser << std::endl;
  715. RemoveSizes(Pkg);
  716. RemoveStates(Pkg);
  717. P.Mode = ModeKeep;
  718. if (Pkg->CurrentVer == 0)
  719. P.InstallVer = 0;
  720. else
  721. P.InstallVer = Pkg.CurrentVer();
  722. AddStates(Pkg);
  723. Update(Pkg);
  724. AddSizes(Pkg);
  725. return true;
  726. }
  727. /*}}}*/
  728. // DepCache::MarkDelete - Put the package in the delete state /*{{{*/
  729. // ---------------------------------------------------------------------
  730. /* */
  731. bool pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
  732. unsigned long Depth, bool FromUser)
  733. {
  734. if (IsModeChangeOk(ModeDelete, Pkg, Depth, FromUser) == false)
  735. return false;
  736. StateCache &P = PkgState[Pkg->ID];
  737. // Check that it is not already marked for delete
  738. if ((P.Mode == ModeDelete || P.InstallVer == 0) &&
  739. (Pkg.Purge() == true || rPurge == false))
  740. return true;
  741. // check if we are allowed to remove the package
  742. if (IsDeleteOk(Pkg,rPurge,Depth,FromUser) == false)
  743. return false;
  744. P.iFlags &= ~(AutoKept | Purge);
  745. if (rPurge == true)
  746. P.iFlags |= Purge;
  747. ActionGroup group(*this);
  748. if (DebugMarker == true)
  749. std::clog << OutputInDepth(Depth) << (rPurge ? "MarkPurge " : "MarkDelete ") << Pkg << " FU=" << FromUser << std::endl;
  750. RemoveSizes(Pkg);
  751. RemoveStates(Pkg);
  752. if (Pkg->CurrentVer == 0 && (Pkg.Purge() == true || rPurge == false))
  753. P.Mode = ModeKeep;
  754. else
  755. P.Mode = ModeDelete;
  756. P.InstallVer = 0;
  757. AddStates(Pkg);
  758. Update(Pkg);
  759. AddSizes(Pkg);
  760. return true;
  761. }
  762. /*}}}*/
  763. // DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
  764. // ---------------------------------------------------------------------
  765. /* The default implementation tries to prevent deletion of install requests.
  766. dpkg holds are enforced by the private IsModeChangeOk */
  767. bool pkgDepCache::IsDeleteOk(PkgIterator const &Pkg,bool rPurge,
  768. unsigned long Depth, bool FromUser)
  769. {
  770. if (FromUser == false && Pkg->CurrentVer == 0)
  771. {
  772. StateCache &P = PkgState[Pkg->ID];
  773. if (P.InstallVer != 0 && P.Status == 2 && (P.Flags & Flag::Auto) != Flag::Auto)
  774. {
  775. if (DebugMarker == true)
  776. std::clog << OutputInDepth(Depth) << "Manual install request prevents MarkDelete of " << Pkg << std::endl;
  777. return false;
  778. }
  779. }
  780. return true;
  781. }
  782. /*}}}*/
  783. // DepCache::IsModeChangeOk - check if it is ok to change the mode /*{{{*/
  784. // ---------------------------------------------------------------------
  785. /* this is used by all Mark methods on the very first line to check sanity
  786. and prevents mode changes for packages on hold for example.
  787. If you want to check Mode specific stuff you can use the virtual public
  788. Is<Mode>Ok methods instead */
  789. char const* PrintMode(char const mode)
  790. {
  791. switch (mode)
  792. {
  793. case pkgDepCache::ModeInstall: return "Install";
  794. case pkgDepCache::ModeKeep: return "Keep";
  795. case pkgDepCache::ModeDelete: return "Delete";
  796. default: return "UNKNOWN";
  797. }
  798. }
  799. bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
  800. unsigned long const Depth, bool const FromUser)
  801. {
  802. // we are not trying to hard…
  803. if (unlikely(Depth > 100))
  804. return false;
  805. // general sanity
  806. if (unlikely(Pkg.end() == true || Pkg->VersionList == 0))
  807. return false;
  808. // the user is always right
  809. if (FromUser == true)
  810. return true;
  811. StateCache &P = PkgState[Pkg->ID];
  812. // if previous state was set by user only user can reset it
  813. if ((P.iFlags & Protected) == Protected)
  814. {
  815. if (unlikely(DebugMarker == true) && P.Mode != mode)
  816. std::clog << OutputInDepth(Depth) << "Ignore Mark" << PrintMode(mode)
  817. << " of " << Pkg << " as its mode (" << PrintMode(P.Mode)
  818. << ") is protected" << std::endl;
  819. return false;
  820. }
  821. // enforce dpkg holds
  822. else if (mode != ModeKeep && Pkg->SelectedState == pkgCache::State::Hold &&
  823. _config->FindB("APT::Ignore-Hold",false) == false)
  824. {
  825. if (unlikely(DebugMarker == true) && P.Mode != mode)
  826. std::clog << OutputInDepth(Depth) << "Hold prevents Mark" << PrintMode(mode)
  827. << " of " << Pkg << std::endl;
  828. return false;
  829. }
  830. return true;
  831. }
  832. /*}}}*/
  833. // DepCache::MarkInstall - Put the package in the install state /*{{{*/
  834. // ---------------------------------------------------------------------
  835. /* */
  836. struct CompareProviders {
  837. pkgCache::PkgIterator const Pkg;
  838. CompareProviders(pkgCache::DepIterator const &Dep) : Pkg(Dep.TargetPkg()) {};
  839. //bool operator() (APT::VersionList::iterator const &AV, APT::VersionList::iterator const &BV)
  840. bool operator() (pkgCache::VerIterator const &AV, pkgCache::VerIterator const &BV)
  841. {
  842. pkgCache::PkgIterator const A = AV.ParentPkg();
  843. pkgCache::PkgIterator const B = BV.ParentPkg();
  844. // Prefer packages in the same group as the target; e.g. foo:i386, foo:amd64
  845. if (A->Group != B->Group)
  846. {
  847. if (A->Group == Pkg->Group && B->Group != Pkg->Group)
  848. return false;
  849. else if (B->Group == Pkg->Group && A->Group != Pkg->Group)
  850. return true;
  851. }
  852. // we like essentials
  853. if ((A->Flags & pkgCache::Flag::Essential) != (B->Flags & pkgCache::Flag::Essential))
  854. {
  855. if ((A->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
  856. return false;
  857. else if ((B->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
  858. return true;
  859. }
  860. // higher priority seems like a good idea
  861. if (AV->Priority != BV->Priority)
  862. return AV->Priority < BV->Priority;
  863. // prefer native architecture
  864. if (strcmp(A.Arch(), B.Arch()) != 0)
  865. {
  866. if (strcmp(A.Arch(), A.Cache()->NativeArch()) == 0)
  867. return false;
  868. else if (strcmp(B.Arch(), B.Cache()->NativeArch()) == 0)
  869. return true;
  870. std::vector<std::string> archs = APT::Configuration::getArchitectures();
  871. for (std::vector<std::string>::const_iterator a = archs.begin(); a != archs.end(); ++a)
  872. if (*a == A.Arch())
  873. return false;
  874. else if (*a == B.Arch())
  875. return true;
  876. }
  877. // unable to decide…
  878. return A->ID < B->ID;
  879. }
  880. };
  881. bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
  882. unsigned long Depth, bool FromUser,
  883. bool ForceImportantDeps)
  884. {
  885. if (IsModeChangeOk(ModeInstall, Pkg, Depth, FromUser) == false)
  886. return false;
  887. StateCache &P = PkgState[Pkg->ID];
  888. // See if there is even any possible instalation candidate
  889. if (P.CandidateVer == 0)
  890. return false;
  891. /* Check that it is not already marked for install and that it can be
  892. installed */
  893. if ((P.InstPolicyBroken() == false && P.InstBroken() == false) &&
  894. (P.Mode == ModeInstall ||
  895. P.CandidateVer == (Version *)Pkg.CurrentVer()))
  896. {
  897. if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0)
  898. return MarkKeep(Pkg, false, FromUser, Depth+1);
  899. return true;
  900. }
  901. // check if we are allowed to install the package
  902. if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false)
  903. return false;
  904. ActionGroup group(*this);
  905. P.iFlags &= ~AutoKept;
  906. /* Target the candidate version and remove the autoflag. We reset the
  907. autoflag below if this was called recursively. Otherwise the user
  908. should have the ability to de-auto a package by changing its state */
  909. RemoveSizes(Pkg);
  910. RemoveStates(Pkg);
  911. P.Mode = ModeInstall;
  912. P.InstallVer = P.CandidateVer;
  913. if(FromUser)
  914. {
  915. // Set it to manual if it's a new install or already installed,
  916. // but only if its not marked by the autoremover (aptitude depend on this behavior)
  917. // or if we do automatic installation (aptitude never does it)
  918. if(P.Status == 2 || (Pkg->CurrentVer != 0 && (AutoInst == true || P.Marked == false)))
  919. P.Flags &= ~Flag::Auto;
  920. }
  921. else
  922. {
  923. // Set it to auto if this is a new install.
  924. if(P.Status == 2)
  925. P.Flags |= Flag::Auto;
  926. }
  927. if (P.CandidateVer == (Version *)Pkg.CurrentVer())
  928. P.Mode = ModeKeep;
  929. AddStates(Pkg);
  930. Update(Pkg);
  931. AddSizes(Pkg);
  932. if (AutoInst == false || _config->Find("APT::Solver", "internal") != "internal")
  933. return true;
  934. if (DebugMarker == true)
  935. std::clog << OutputInDepth(Depth) << "MarkInstall " << Pkg << " FU=" << FromUser << std::endl;
  936. DepIterator Dep = P.InstVerIter(*this).DependsList();
  937. for (; Dep.end() != true;)
  938. {
  939. // Grok or groups
  940. DepIterator Start = Dep;
  941. bool Result = true;
  942. unsigned Ors = 0;
  943. for (bool LastOR = true; Dep.end() == false && LastOR == true; ++Dep, ++Ors)
  944. {
  945. LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or;
  946. if ((DepState[Dep->ID] & DepInstall) == DepInstall)
  947. Result = false;
  948. }
  949. // Dep is satisfied okay.
  950. if (Result == false)
  951. continue;
  952. /* Check if this dep should be consider for install. If it is a user
  953. defined important dep and we are installed a new package then
  954. it will be installed. Otherwise we only check for important
  955. deps that have changed from the installed version
  956. */
  957. if (IsImportantDep(Start) == false)
  958. continue;
  959. /* If we are in an or group locate the first or that can
  960. succeed. We have already cached this.. */
  961. for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; --Ors)
  962. ++Start;
  963. if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer && Start.IsNegative() == false)
  964. {
  965. if(DebugAutoInstall == true)
  966. std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl;
  967. if (Start.IsCritical() == false)
  968. continue;
  969. // if the dependency was critical, we can't install it, so remove it again
  970. MarkDelete(Pkg,false,Depth + 1, false);
  971. return false;
  972. }
  973. /* Check if any ImportantDep() (but not Critical) were added
  974. * since we installed the package. Also check for deps that
  975. * were satisfied in the past: for instance, if a version
  976. * restriction in a Recommends was tightened, upgrading the
  977. * package should follow that Recommends rather than causing the
  978. * dependency to be removed. (bug #470115)
  979. */
  980. if (Pkg->CurrentVer != 0 && ForceImportantDeps == false && Start.IsCritical() == false)
  981. {
  982. bool isNewImportantDep = true;
  983. bool isPreviouslySatisfiedImportantDep = false;
  984. for (DepIterator D = Pkg.CurrentVer().DependsList(); D.end() != true; ++D)
  985. {
  986. //FIXME: Should we handle or-group better here?
  987. // We do not check if the package we look for is part of the same or-group
  988. // we might find while searching, but could that really be a problem?
  989. if (D.IsCritical() == true || IsImportantDep(D) == false ||
  990. Start.TargetPkg() != D.TargetPkg())
  991. continue;
  992. isNewImportantDep = false;
  993. while ((D->CompareOp & Dep::Or) != 0)
  994. ++D;
  995. isPreviouslySatisfiedImportantDep = (((*this)[D] & DepGNow) != 0);
  996. if (isPreviouslySatisfiedImportantDep == true)
  997. break;
  998. }
  999. if(isNewImportantDep == true)
  1000. {
  1001. if (DebugAutoInstall == true)
  1002. std::clog << OutputInDepth(Depth) << "new important dependency: "
  1003. << Start.TargetPkg().FullName() << std::endl;
  1004. }
  1005. else if(isPreviouslySatisfiedImportantDep == true)
  1006. {
  1007. if (DebugAutoInstall == true)
  1008. std::clog << OutputInDepth(Depth) << "previously satisfied important dependency on "
  1009. << Start.TargetPkg().FullName() << std::endl;
  1010. }
  1011. else
  1012. {
  1013. if (DebugAutoInstall == true)
  1014. std::clog << OutputInDepth(Depth) << "ignore old unsatisfied important dependency on "
  1015. << Start.TargetPkg().FullName() << std::endl;
  1016. continue;
  1017. }
  1018. }
  1019. /* This bit is for processing the possibilty of an install/upgrade
  1020. fixing the problem */
  1021. if (Start->Type != Dep::DpkgBreaks &&
  1022. (DepState[Start->ID] & DepCVer) == DepCVer)
  1023. {
  1024. APT::VersionList verlist;
  1025. pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this);
  1026. if (Cand.end() == false && VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == true)
  1027. verlist.insert(Cand);
  1028. for (PrvIterator Prv = Start.TargetPkg().ProvidesList(); Prv.end() != true; ++Prv)
  1029. {
  1030. pkgCache::VerIterator V = Prv.OwnerVer();
  1031. pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
  1032. if (Cand.end() == true || V != Cand ||
  1033. VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == false)
  1034. continue;
  1035. verlist.insert(Cand);
  1036. }
  1037. CompareProviders comp(Start);
  1038. APT::VersionList::iterator InstVer = std::max_element(verlist.begin(), verlist.end(), comp);
  1039. if (InstVer != verlist.end())
  1040. {
  1041. pkgCache::PkgIterator InstPkg = InstVer.ParentPkg();
  1042. if(DebugAutoInstall == true)
  1043. std::clog << OutputInDepth(Depth) << "Installing " << InstPkg.Name()
  1044. << " as " << Start.DepType() << " of " << Pkg.Name()
  1045. << std::endl;
  1046. // now check if we should consider it a automatic dependency or not
  1047. if(Pkg.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg.Section()))
  1048. {
  1049. if(DebugAutoInstall == true)
  1050. std::clog << OutputInDepth(Depth) << "Setting NOT as auto-installed (direct "
  1051. << Start.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl;
  1052. MarkInstall(InstPkg,true,Depth + 1, true);
  1053. }
  1054. else
  1055. {
  1056. // mark automatic dependency
  1057. MarkInstall(InstPkg,true,Depth + 1, false, ForceImportantDeps);
  1058. // Set the autoflag, after MarkInstall because MarkInstall unsets it
  1059. if (InstPkg->CurrentVer == 0)
  1060. PkgState[InstPkg->ID].Flags |= Flag::Auto;
  1061. }
  1062. }
  1063. continue;
  1064. }
  1065. /* For conflicts we just de-install the package and mark as auto,
  1066. Conflicts may not have or groups. For dpkg's Breaks we try to
  1067. upgrade the package. */
  1068. if (Start.IsNegative() == true)
  1069. {
  1070. SPtrArray<Version *> List = Start.AllTargets();
  1071. for (Version **I = List; *I != 0; I++)
  1072. {
  1073. VerIterator Ver(*this,*I);
  1074. PkgIterator Pkg = Ver.ParentPkg();
  1075. /* The List includes all packages providing this dependency,
  1076. even providers which are not installed, so skip them. */
  1077. if (PkgState[Pkg->ID].InstallVer == 0)
  1078. continue;
  1079. if (PkgState[Pkg->ID].CandidateVer != *I &&
  1080. Start->Type == Dep::DpkgBreaks &&
  1081. MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps) == true)
  1082. continue;
  1083. else if (MarkDelete(Pkg,false,Depth + 1, false) == false)
  1084. break;
  1085. }
  1086. continue;
  1087. }
  1088. }
  1089. return Dep.end() == true;
  1090. }
  1091. /*}}}*/
  1092. // DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
  1093. // ---------------------------------------------------------------------
  1094. /* The default implementation does nothing.
  1095. dpkg holds are enforced by the private IsModeChangeOk */
  1096. bool pkgDepCache::IsInstallOk(PkgIterator const &Pkg,bool AutoInst,
  1097. unsigned long Depth, bool FromUser)
  1098. {
  1099. return true;
  1100. }
  1101. /*}}}*/
  1102. // DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
  1103. // ---------------------------------------------------------------------
  1104. /* */
  1105. void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
  1106. {
  1107. if (unlikely(Pkg.end() == true))
  1108. return;
  1109. ActionGroup group(*this);
  1110. RemoveSizes(Pkg);
  1111. RemoveStates(Pkg);
  1112. StateCache &P = PkgState[Pkg->ID];
  1113. if (To == true)
  1114. P.iFlags |= ReInstall;
  1115. else
  1116. P.iFlags &= ~ReInstall;
  1117. AddStates(Pkg);
  1118. AddSizes(Pkg);
  1119. }
  1120. /*}}}*/
  1121. // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
  1122. // ---------------------------------------------------------------------
  1123. /* */
  1124. void pkgDepCache::SetCandidateVersion(VerIterator TargetVer)
  1125. {
  1126. pkgCache::PkgIterator Pkg = TargetVer.ParentPkg();
  1127. StateCache &P = PkgState[Pkg->ID];
  1128. if (P.CandidateVer == TargetVer)
  1129. return;
  1130. ActionGroup group(*this);
  1131. RemoveSizes(Pkg);
  1132. RemoveStates(Pkg);
  1133. if (P.CandidateVer == P.InstallVer && P.Install() == true)
  1134. P.InstallVer = (Version *)TargetVer;
  1135. P.CandidateVer = (Version *)TargetVer;
  1136. P.Update(Pkg,*this);
  1137. AddStates(Pkg);
  1138. Update(Pkg);
  1139. AddSizes(Pkg);
  1140. }
  1141. /*}}}*/
  1142. // DepCache::SetCandidateRelease - Change the candidate version /*{{{*/
  1143. // ---------------------------------------------------------------------
  1144. /* changes the candidate of a package and walks over all its dependencies
  1145. to check if it needs to change the candidate of the dependency, too,
  1146. to reach a installable versionstate */
  1147. bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer,
  1148. std::string const &TargetRel)
  1149. {
  1150. std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
  1151. return SetCandidateRelease(TargetVer, TargetRel, Changed);
  1152. }
  1153. bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer,
  1154. std::string const &TargetRel,
  1155. std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > &Changed)
  1156. {
  1157. ActionGroup group(*this);
  1158. SetCandidateVersion(TargetVer);
  1159. if (TargetRel == "installed" || TargetRel == "candidate") // both doesn't make sense in this context
  1160. return true;
  1161. pkgVersionMatch Match(TargetRel, pkgVersionMatch::Release);
  1162. // save the position of the last element we will not undo - if we have to
  1163. std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::iterator newChanged = --(Changed.end());
  1164. for (pkgCache::DepIterator D = TargetVer.DependsList(); D.end() == false; ++D)
  1165. {
  1166. if (D->Type != pkgCache::Dep::PreDepends && D->Type != pkgCache::Dep::Depends &&
  1167. ((D->Type != pkgCache::Dep::Recommends && D->Type != pkgCache::Dep::Suggests) ||
  1168. IsImportantDep(D) == false))
  1169. continue;
  1170. // walk over an or-group and check if we need to do anything
  1171. // for simpilicity no or-group is handled as a or-group including one dependency
  1172. pkgCache::DepIterator Start = D;
  1173. bool itsFine = false;
  1174. for (bool stillOr = true; stillOr == true; ++Start)
  1175. {
  1176. stillOr = (Start->CompareOp & Dep::Or) == Dep::Or;
  1177. pkgCache::PkgIterator const P = Start.TargetPkg();
  1178. // virtual packages can't be a solution
  1179. if (P.end() == true || (P->ProvidesList == 0 && P->VersionList == 0))
  1180. continue;
  1181. pkgCache::VerIterator const Cand = PkgState[P->ID].CandidateVerIter(*this);
  1182. // no versioned dependency - but is it installable?
  1183. if (Start.TargetVer() == 0 || Start.TargetVer()[0] == '\0')
  1184. {
  1185. // Check if one of the providers is installable
  1186. if (P->ProvidesList != 0)
  1187. {
  1188. pkgCache::PrvIterator Prv = P.ProvidesList();
  1189. for (; Prv.end() == false; ++Prv)
  1190. {
  1191. pkgCache::VerIterator const C = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
  1192. if (C.end() == true || C != Prv.OwnerVer() ||
  1193. (VersionState(C.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) != DepCandMin)
  1194. continue;
  1195. break;
  1196. }
  1197. if (Prv.end() == true)
  1198. continue;
  1199. }
  1200. // no providers, so check if we have an installable candidate version
  1201. else if (Cand.end() == true ||
  1202. (VersionState(Cand.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) != DepCandMin)
  1203. continue;
  1204. itsFine = true;
  1205. break;
  1206. }
  1207. if (Cand.end() == true)
  1208. continue;
  1209. // check if the current candidate is enough for the versioned dependency - and installable?
  1210. if (VS().CheckDep(P.CandVersion(), Start->CompareOp, Start.TargetVer()) == true &&
  1211. (VersionState(Cand.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) == DepCandMin)
  1212. {
  1213. itsFine = true;
  1214. break;
  1215. }
  1216. }
  1217. if (itsFine == true) {
  1218. // something in the or-group was fine, skip all other members
  1219. for (; (D->CompareOp & Dep::Or) == Dep::Or; ++D);
  1220. continue;
  1221. }
  1222. // walk again over the or-group and check each if a candidate switch would help
  1223. itsFine = false;
  1224. for (bool stillOr = true; stillOr == true; ++D)
  1225. {
  1226. stillOr = (D->CompareOp & Dep::Or) == Dep::Or;
  1227. // changing candidate will not help if the dependency is not versioned
  1228. if (D.TargetVer() == 0 || D.TargetVer()[0] == '\0')
  1229. {
  1230. if (stillOr == true)
  1231. continue;
  1232. break;
  1233. }
  1234. pkgCache::VerIterator V;
  1235. if (TargetRel == "newest")
  1236. V = D.TargetPkg().VersionList();
  1237. else
  1238. V = Match.Find(D.TargetPkg());
  1239. // check if the version from this release could satisfy the dependency
  1240. if (V.end() == true || VS().CheckDep(V.VerStr(), D->CompareOp, D.TargetVer()) == false)
  1241. {
  1242. if (stillOr == true)
  1243. continue;
  1244. break;
  1245. }
  1246. pkgCache::VerIterator oldCand = PkgState[D.TargetPkg()->ID].CandidateVerIter(*this);
  1247. if (V == oldCand)
  1248. {
  1249. // Do we already touched this Version? If so, their versioned dependencies are okay, no need to check again
  1250. for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
  1251. c != Changed.end(); ++c)
  1252. {
  1253. if (c->first->ParentPkg != V->ParentPkg)
  1254. continue;
  1255. itsFine = true;
  1256. break;
  1257. }
  1258. }
  1259. if (itsFine == false)
  1260. {
  1261. // change the candidate
  1262. Changed.push_back(make_pair(oldCand, TargetVer));
  1263. if (SetCandidateRelease(V, TargetRel, Changed) == false)
  1264. {
  1265. if (stillOr == false)
  1266. break;
  1267. // undo the candidate changing
  1268. SetCandidateVersion(oldCand);
  1269. Changed.pop_back();
  1270. continue;
  1271. }
  1272. itsFine = true;
  1273. }
  1274. // something in the or-group was fine, skip all other members
  1275. for (; (D->CompareOp & Dep::Or) == Dep::Or; ++D);
  1276. break;
  1277. }
  1278. if (itsFine == false && (D->Type == pkgCache::Dep::PreDepends || D->Type == pkgCache::Dep::Depends))
  1279. {
  1280. // undo all changes which aren't lead to a solution
  1281. for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = ++newChanged;
  1282. c != Changed.end(); ++c)
  1283. SetCandidateVersion(c->first);
  1284. Changed.erase(newChanged, Changed.end());
  1285. return false;
  1286. }
  1287. }
  1288. return true;
  1289. }
  1290. /*}}}*/
  1291. // DepCache::MarkAuto - set the Auto flag for a package /*{{{*/
  1292. // ---------------------------------------------------------------------
  1293. /* */
  1294. void pkgDepCache::MarkAuto(const PkgIterator &Pkg, bool Auto)
  1295. {
  1296. StateCache &state = PkgState[Pkg->ID];
  1297. ActionGroup group(*this);
  1298. if(Auto)
  1299. state.Flags |= Flag::Auto;
  1300. else
  1301. state.Flags &= ~Flag::Auto;
  1302. }
  1303. /*}}}*/
  1304. // StateCache::Update - Compute the various static display things /*{{{*/
  1305. // ---------------------------------------------------------------------
  1306. /* This is called whenever the Candidate version changes. */
  1307. void pkgDepCache::StateCache::Update(PkgIterator Pkg,pkgCache &Cache)
  1308. {
  1309. // Some info
  1310. VerIterator Ver = CandidateVerIter(Cache);
  1311. // Use a null string or the version string
  1312. if (Ver.end() == true)
  1313. CandVersion = "";
  1314. else
  1315. CandVersion = Ver.VerStr();
  1316. // Find the current version
  1317. CurVersion = "";
  1318. if (Pkg->CurrentVer != 0)
  1319. CurVersion = Pkg.CurrentVer().VerStr();
  1320. // Strip off the epochs for display
  1321. CurVersion = StripEpoch(CurVersion);
  1322. CandVersion = StripEpoch(CandVersion);
  1323. // Figure out if its up or down or equal
  1324. Status = Ver.CompareVer(Pkg.CurrentVer());
  1325. if (Pkg->CurrentVer == 0 || Pkg->VersionList == 0 || CandidateVer == 0)
  1326. Status = 2;
  1327. }
  1328. /*}}}*/
  1329. // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
  1330. // ---------------------------------------------------------------------
  1331. /* */
  1332. const char *pkgDepCache::StateCache::StripEpoch(const char *Ver)
  1333. {
  1334. if (Ver == 0)
  1335. return 0;
  1336. // Strip any epoch
  1337. for (const char *I = Ver; *I != 0; I++)
  1338. if (*I == ':')
  1339. return I + 1;
  1340. return Ver;
  1341. }
  1342. /*}}}*/
  1343. // Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
  1344. // ---------------------------------------------------------------------
  1345. /* The default just returns the highest available version that is not
  1346. a source and automatic. */
  1347. pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator const &Pkg)
  1348. {
  1349. /* Not source/not automatic versions cannot be a candidate version
  1350. unless they are already installed */
  1351. VerIterator Last(*(pkgCache *)this,0);
  1352. for (VerIterator I = Pkg.VersionList(); I.end() == false; ++I)
  1353. {
  1354. if (Pkg.CurrentVer() == I)
  1355. return I;
  1356. for (VerFileIterator J = I.FileList(); J.end() == false; ++J)
  1357. {
  1358. if ((J.File()->Flags & Flag::NotSource) != 0)
  1359. continue;
  1360. /* Stash the highest version of a not-automatic source, we use it
  1361. if there is nothing better */
  1362. if ((J.File()->Flags & Flag::NotAutomatic) != 0 ||
  1363. (J.File()->Flags & Flag::ButAutomaticUpgrades) != 0)
  1364. {
  1365. if (Last.end() == true)
  1366. Last = I;
  1367. continue;
  1368. }
  1369. return I;
  1370. }
  1371. }
  1372. return Last;
  1373. }
  1374. /*}}}*/
  1375. // Policy::IsImportantDep - True if the dependency is important /*{{{*/
  1376. // ---------------------------------------------------------------------
  1377. /* */
  1378. bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
  1379. {
  1380. if(Dep.IsCritical())
  1381. return true;
  1382. else if(Dep->Type == pkgCache::Dep::Recommends)
  1383. {
  1384. if (InstallRecommends)
  1385. return true;
  1386. // we suport a special mode to only install-recommends for certain
  1387. // sections
  1388. // FIXME: this is a meant as a temporarly solution until the
  1389. // recommends are cleaned up
  1390. const char *sec = Dep.ParentVer().Section();
  1391. if (sec && ConfigValueInSubTree("APT::Install-Recommends-Sections", sec))
  1392. return true;
  1393. }
  1394. else if(Dep->Type == pkgCache::Dep::Suggests)
  1395. return InstallSuggests;
  1396. return false;
  1397. }
  1398. /*}}}*/
  1399. // Policy::GetPriority - Get the priority of the package pin /*{{{*/
  1400. signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &Pkg)
  1401. { return 0; };
  1402. signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &File)
  1403. { return 0; };
  1404. /*}}}*/
  1405. pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc() /*{{{*/
  1406. {
  1407. DefaultRootSetFunc *f = new DefaultRootSetFunc;
  1408. if(f->wasConstructedSuccessfully())
  1409. return f;
  1410. else
  1411. {
  1412. delete f;
  1413. return NULL;
  1414. }
  1415. }
  1416. /*}}}*/
  1417. bool pkgDepCache::MarkFollowsRecommends()
  1418. {
  1419. return _config->FindB("APT::AutoRemove::RecommendsImportant", true);
  1420. }
  1421. bool pkgDepCache::MarkFollowsSuggests()
  1422. {
  1423. return _config->FindB("APT::AutoRemove::SuggestsImportant", true);
  1424. }
  1425. // pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
  1426. bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
  1427. {
  1428. if (_config->Find("APT::Solver", "internal") != "internal")
  1429. return true;
  1430. bool follow_recommends;
  1431. bool follow_suggests;
  1432. bool debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
  1433. // init the states
  1434. for(PkgIterator p = PkgBegin(); !p.end(); ++p)
  1435. {
  1436. PkgState[p->ID].Marked = false;
  1437. PkgState[p->ID].Garbage = false;
  1438. // debug output
  1439. if(debug_autoremove && PkgState[p->ID].Flags & Flag::Auto)
  1440. std::clog << "AutoDep: " << p.FullName() << std::endl;
  1441. }
  1442. // init vars
  1443. follow_recommends = MarkFollowsRecommends();
  1444. follow_suggests = MarkFollowsSuggests();
  1445. // do the mark part, this is the core bit of the algorithm
  1446. for(PkgIterator p = PkgBegin(); !p.end(); ++p)
  1447. {
  1448. if(!(PkgState[p->ID].Flags & Flag::Auto) ||
  1449. (p->Flags & Flag::Essential) ||
  1450. userFunc.InRootSet(p) ||
  1451. // be nice even then a required package violates the policy (#583517)
  1452. // and do the full mark process also for required packages
  1453. (p.CurrentVer().end() != true &&
  1454. p.CurrentVer()->Priority == pkgCache::State::Required))
  1455. {
  1456. // the package is installed (and set to keep)
  1457. if(PkgState[p->ID].Keep() && !p.CurrentVer().end())
  1458. MarkPackage(p, p.CurrentVer(),
  1459. follow_recommends, follow_suggests);
  1460. // the package is to be installed
  1461. else if(PkgState[p->ID].Install())
  1462. MarkPackage(p, PkgState[p->ID].InstVerIter(*this),
  1463. follow_recommends, follow_suggests);
  1464. }
  1465. }
  1466. return true;
  1467. }
  1468. /*}}}*/
  1469. // MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
  1470. void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
  1471. const pkgCache::VerIterator &ver,
  1472. bool const &follow_recommends,
  1473. bool const &follow_suggests)
  1474. {
  1475. pkgDepCache::StateCache &state = PkgState[pkg->ID];
  1476. // if we are marked already we are done
  1477. if(state.Marked)
  1478. return;
  1479. VerIterator const currver = pkg.CurrentVer();
  1480. VerIterator const instver = state.InstVerIter(*this);
  1481. #if 0
  1482. VerIterator const candver = state.CandidateVerIter(*this);
  1483. // If a package was garbage-collected but is now being marked, we
  1484. // should re-select it
  1485. // For cases when a pkg is set to upgrade and this trigger the
  1486. // removal of a no-longer used dependency. if the pkg is set to
  1487. // keep again later it will result in broken deps
  1488. if(state.Delete() && state.RemoveReason = Unused)
  1489. {
  1490. if(ver==candver)
  1491. mark_install(pkg, false, false, NULL);
  1492. else if(ver==pkg.CurrentVer())
  1493. MarkKeep(pkg, false, false);
  1494. instver=state.InstVerIter(*this);
  1495. }
  1496. #endif
  1497. // For packages that are not going to be removed, ignore versions
  1498. // other than the InstVer. For packages that are going to be
  1499. // removed, ignore versions other than the current version.
  1500. if(!(ver == instver && !instver.end()) &&
  1501. !(ver == currver && instver.end() && !ver.end()))
  1502. return;
  1503. bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove", false);
  1504. if(debug_autoremove)
  1505. {
  1506. std::clog << "Marking: " << pkg.FullName();
  1507. if(!ver.end())
  1508. std::clog << " " << ver.VerStr();
  1509. if(!currver.end())
  1510. std::clog << ", Curr=" << currver.VerStr();
  1511. if(!instver.end())
  1512. std::clog << ", Inst=" << instver.VerStr();
  1513. std::clog << std::endl;
  1514. }
  1515. state.Marked=true;
  1516. if(ver.end() == true)
  1517. return;
  1518. for(DepIterator d = ver.DependsList(); !d.end(); ++d)
  1519. {
  1520. if(d->Type == Dep::Depends ||
  1521. d->Type == Dep::PreDepends ||
  1522. (follow_recommends &&
  1523. d->Type == Dep::Recommends) ||
  1524. (follow_suggests &&
  1525. d->Type == Dep::Suggests))
  1526. {
  1527. // Try all versions of this package.
  1528. for(VerIterator V = d.TargetPkg().VersionList();
  1529. !V.end(); ++V)
  1530. {
  1531. if(_system->VS->CheckDep(V.VerStr(), d->CompareOp, d.TargetVer()))
  1532. {
  1533. if(debug_autoremove)
  1534. {
  1535. std::clog << "Following dep: " << d.ParentPkg().FullName()
  1536. << " " << d.ParentVer().VerStr() << " "
  1537. << d.DepType() << " " << d.TargetPkg().FullName();
  1538. if((d->CompareOp & ~pkgCache::Dep::Or) != pkgCache::Dep::NoOp)
  1539. {
  1540. std::clog << " (" << d.CompType() << " "
  1541. << d.TargetVer() << ")";
  1542. }
  1543. std::clog << std::endl;
  1544. }
  1545. MarkPackage(V.ParentPkg(), V,
  1546. follow_recommends, follow_suggests);
  1547. }
  1548. }
  1549. // Now try virtual packages
  1550. for(PrvIterator prv=d.TargetPkg().ProvidesList();
  1551. !prv.end(); ++prv)
  1552. {
  1553. if(_system->VS->CheckDep(prv.ProvideVersion(), d->CompareOp,
  1554. d.TargetVer()))
  1555. {
  1556. if(debug_autoremove)
  1557. {
  1558. std::clog << "Following dep: " << d.ParentPkg().FullName() << " "
  1559. << d.ParentVer().VerStr() << " "
  1560. << d.DepType() << " " << d.TargetPkg().FullName() << " ";
  1561. if((d->CompareOp & ~pkgCache::Dep::Or) != pkgCache::Dep::NoOp)
  1562. {
  1563. std::clog << " (" << d.CompType() << " "
  1564. << d.TargetVer() << ")";
  1565. }
  1566. std::clog << ", provided by "
  1567. << prv.OwnerPkg().FullName() << " "
  1568. << prv.OwnerVer().VerStr()
  1569. << std::endl;
  1570. }
  1571. MarkPackage(prv.OwnerPkg(), prv.OwnerVer(),
  1572. follow_recommends, follow_suggests);
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. /*}}}*/
  1579. bool pkgDepCache::Sweep() /*{{{*/
  1580. {
  1581. bool debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
  1582. // do the sweep
  1583. for(PkgIterator p=PkgBegin(); !p.end(); ++p)
  1584. {
  1585. StateCache &state=PkgState[p->ID];
  1586. // skip required packages
  1587. if (!p.CurrentVer().end() &&
  1588. (p.CurrentVer()->Priority == pkgCache::State::Required))
  1589. continue;
  1590. // if it is not marked and it is installed, it's garbage
  1591. if(!state.Marked && (!p.CurrentVer().end() || state.Install()))
  1592. {
  1593. state.Garbage=true;
  1594. if(debug_autoremove)
  1595. std::clog << "Garbage: " << p.FullName() << std::endl;
  1596. }
  1597. }
  1598. return true;
  1599. }
  1600. /*}}}*/