depcache.cc 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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. #ifdef __GNUG__
  10. #pragma implementation "apt-pkg/depcache.h"
  11. #endif
  12. #include <apt-pkg/depcache.h>
  13. #include <apt-pkg/version.h>
  14. #include <apt-pkg/error.h>
  15. #include <apt-pkg/sptr.h>
  16. #include <apt-pkg/algorithms.h>
  17. #include <apt-pkg/fileutl.h>
  18. #include <apt-pkg/configuration.h>
  19. #include <apt-pkg/pkgsystem.h>
  20. #include <apt-pkg/tagfile.h>
  21. #include <iostream>
  22. #include <sstream>
  23. #include <set>
  24. #include <apti18n.h>
  25. pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) :
  26. cache(cache), released(false)
  27. {
  28. ++cache.group_level;
  29. }
  30. void pkgDepCache::ActionGroup::release()
  31. {
  32. if(!released)
  33. {
  34. if(cache.group_level == 0)
  35. std::cerr << "W: Unbalanced action groups, expect badness" << std::endl;
  36. else
  37. {
  38. --cache.group_level;
  39. if(cache.group_level == 0)
  40. cache.MarkAndSweep();
  41. }
  42. released = false;
  43. }
  44. }
  45. pkgDepCache::ActionGroup::~ActionGroup()
  46. {
  47. release();
  48. }
  49. // DepCache::pkgDepCache - Constructors /*{{{*/
  50. // ---------------------------------------------------------------------
  51. /* */
  52. pkgDepCache::pkgDepCache(pkgCache *pCache,Policy *Plcy) :
  53. group_level(0), Cache(pCache), PkgState(0), DepState(0)
  54. {
  55. delLocalPolicy = 0;
  56. LocalPolicy = Plcy;
  57. if (LocalPolicy == 0)
  58. delLocalPolicy = LocalPolicy = new Policy;
  59. }
  60. /*}}}*/
  61. // DepCache::~pkgDepCache - Destructor /*{{{*/
  62. // ---------------------------------------------------------------------
  63. /* */
  64. pkgDepCache::~pkgDepCache()
  65. {
  66. delete [] PkgState;
  67. delete [] DepState;
  68. delete delLocalPolicy;
  69. }
  70. /*}}}*/
  71. // DepCache::Init - Generate the initial extra structures. /*{{{*/
  72. // ---------------------------------------------------------------------
  73. /* This allocats the extension buffers and initializes them. */
  74. bool pkgDepCache::Init(OpProgress *Prog)
  75. {
  76. // Suppress mark updates during this operation (just in case) and
  77. // run a mark operation when Init terminates.
  78. ActionGroup actions(*this);
  79. delete [] PkgState;
  80. delete [] DepState;
  81. PkgState = new StateCache[Head().PackageCount];
  82. DepState = new unsigned char[Head().DependsCount];
  83. memset(PkgState,0,sizeof(*PkgState)*Head().PackageCount);
  84. memset(DepState,0,sizeof(*DepState)*Head().DependsCount);
  85. if (Prog != 0)
  86. {
  87. Prog->OverallProgress(0,2*Head().PackageCount,Head().PackageCount,
  88. _("Building dependency tree"));
  89. Prog->SubProgress(Head().PackageCount,_("Candidate versions"));
  90. }
  91. /* Set the current state of everything. In this state all of the
  92. packages are kept exactly as is. See AllUpgrade */
  93. int Done = 0;
  94. for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
  95. {
  96. if (Prog != 0)
  97. Prog->Progress(Done);
  98. // Find the proper cache slot
  99. StateCache &State = PkgState[I->ID];
  100. State.iFlags = 0;
  101. // Figure out the install version
  102. State.CandidateVer = GetCandidateVer(I);
  103. State.InstallVer = I.CurrentVer();
  104. State.Mode = ModeKeep;
  105. State.Update(I,*this);
  106. }
  107. if (Prog != 0)
  108. {
  109. Prog->OverallProgress(Head().PackageCount,2*Head().PackageCount,
  110. Head().PackageCount,
  111. _("Building dependency tree"));
  112. Prog->SubProgress(Head().PackageCount,_("Dependency generation"));
  113. }
  114. Update(Prog);
  115. if(Prog != 0)
  116. Prog->Done();
  117. return true;
  118. }
  119. /*}}}*/
  120. bool pkgDepCache::readStateFile(OpProgress *Prog)
  121. {
  122. FileFd state_file;
  123. string state = _config->FindDir("Dir::State") + "extended_states";
  124. if(FileExists(state)) {
  125. state_file.Open(state, FileFd::ReadOnly);
  126. int file_size = state_file.Size();
  127. if(Prog != NULL)
  128. Prog->OverallProgress(0, file_size, 1,
  129. _("Reading state information"));
  130. pkgTagFile tagfile(&state_file);
  131. pkgTagSection section;
  132. int amt=0;
  133. while(tagfile.Step(section)) {
  134. string pkgname = section.FindS("Package");
  135. pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname);
  136. // Silently ignore unknown packages and packages with no actual
  137. // version.
  138. if(!pkg.end() && !pkg.VersionList().end()) {
  139. short reason = section.FindI("Auto-Installed", 0);
  140. if(reason > 0)
  141. PkgState[pkg->ID].Flags |= Flag::Auto;
  142. if(_config->FindB("Debug::pkgAutoRemove",false))
  143. std::cout << "Auto-Installed : " << pkgname << std::endl;
  144. amt+=section.size();
  145. if(Prog != NULL)
  146. Prog->OverallProgress(amt, file_size, 1,
  147. _("Reading state information"));
  148. }
  149. if(Prog != NULL)
  150. Prog->OverallProgress(file_size, file_size, 1,
  151. _("Reading state information"));
  152. }
  153. }
  154. return true;
  155. }
  156. bool pkgDepCache::writeStateFile(OpProgress *prog)
  157. {
  158. if(_config->FindB("Debug::pkgAutoRemove",false))
  159. std::clog << "pkgDepCache::writeStateFile()" << std::endl;
  160. FileFd StateFile;
  161. string state = _config->FindDir("Dir::State") + "extended_states";
  162. // if it does not exist, create a empty one
  163. if(!FileExists(state))
  164. {
  165. StateFile.Open(state, FileFd::WriteEmpty);
  166. StateFile.Close();
  167. }
  168. // open it
  169. if(!StateFile.Open(state, FileFd::ReadOnly))
  170. return _error->Error(_("Failed to open StateFile %s"),
  171. state.c_str());
  172. FILE *OutFile;
  173. string outfile = state + ".tmp";
  174. if((OutFile = fopen(outfile.c_str(),"w")) == NULL)
  175. return _error->Error(_("Failed to write temporary StateFile %s"),
  176. outfile.c_str());
  177. // first merge with the existing sections
  178. pkgTagFile tagfile(&StateFile);
  179. pkgTagSection section;
  180. std::set<string> pkgs_seen;
  181. const char *nullreorderlist[] = {0};
  182. while(tagfile.Step(section)) {
  183. string pkgname = section.FindS("Package");
  184. // Silently ignore unknown packages and packages with no actual
  185. // version.
  186. pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname);
  187. if(pkg.end() || pkg.VersionList().end())
  188. continue;
  189. bool oldAuto = section.FindI("Auto-Installed");
  190. bool newAuto = (PkgState[pkg->ID].Flags & Flag::Auto);
  191. if(_config->FindB("Debug::pkgAutoRemove",false))
  192. std::clog << "Update exisiting AutoInstall info: "
  193. << pkg.Name() << std::endl;
  194. TFRewriteData rewrite[2];
  195. rewrite[0].Tag = "Auto-Installed";
  196. rewrite[0].Rewrite = newAuto ? "1" : "0";
  197. rewrite[0].NewTag = 0;
  198. rewrite[1].Tag = 0;
  199. TFRewrite(OutFile, section, nullreorderlist, rewrite);
  200. fprintf(OutFile,"\n");
  201. pkgs_seen.insert(pkgname);
  202. }
  203. // then write the ones we have not seen yet
  204. std::ostringstream ostr;
  205. for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); pkg++) {
  206. if(PkgState[pkg->ID].Flags & Flag::Auto) {
  207. if (pkgs_seen.find(pkg.Name()) != pkgs_seen.end()) {
  208. if(_config->FindB("Debug::pkgAutoRemove",false))
  209. std::clog << "Skipping already written " << pkg.Name() << std::endl;
  210. continue;
  211. }
  212. if(_config->FindB("Debug::pkgAutoRemove",false))
  213. std::clog << "Writing new AutoInstall: "
  214. << pkg.Name() << std::endl;
  215. ostr.str(string(""));
  216. ostr << "Package: " << pkg.Name()
  217. << "\nAuto-Installed: 1\n\n";
  218. fprintf(OutFile,ostr.str().c_str());
  219. fprintf(OutFile,"\n");
  220. }
  221. }
  222. fclose(OutFile);
  223. // move the outfile over the real file
  224. rename(outfile.c_str(), state.c_str());
  225. return true;
  226. }
  227. // DepCache::CheckDep - Checks a single dependency /*{{{*/
  228. // ---------------------------------------------------------------------
  229. /* This first checks the dependency against the main target package and
  230. then walks along the package provides list and checks if each provides
  231. will be installed then checks the provides against the dep. Res will be
  232. set to the package which was used to satisfy the dep. */
  233. bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
  234. {
  235. Res = Dep.TargetPkg();
  236. /* Check simple depends. A depends -should- never self match but
  237. we allow it anyhow because dpkg does. Technically it is a packaging
  238. bug. Conflicts may never self match */
  239. if (Dep.TargetPkg() != Dep.ParentPkg() ||
  240. (Dep->Type != Dep::Conflicts && Dep->Type != Dep::Obsoletes))
  241. {
  242. PkgIterator Pkg = Dep.TargetPkg();
  243. // Check the base package
  244. if (Type == NowVersion && Pkg->CurrentVer != 0)
  245. if (VS().CheckDep(Pkg.CurrentVer().VerStr(),Dep->CompareOp,
  246. Dep.TargetVer()) == true)
  247. return true;
  248. if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0)
  249. if (VS().CheckDep(PkgState[Pkg->ID].InstVerIter(*this).VerStr(),
  250. Dep->CompareOp,Dep.TargetVer()) == true)
  251. return true;
  252. if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0)
  253. if (VS().CheckDep(PkgState[Pkg->ID].CandidateVerIter(*this).VerStr(),
  254. Dep->CompareOp,Dep.TargetVer()) == true)
  255. return true;
  256. }
  257. if (Dep->Type == Dep::Obsoletes)
  258. return false;
  259. // Check the providing packages
  260. PrvIterator P = Dep.TargetPkg().ProvidesList();
  261. PkgIterator Pkg = Dep.ParentPkg();
  262. for (; P.end() != true; P++)
  263. {
  264. /* Provides may never be applied against the same package if it is
  265. a conflicts. See the comment above. */
  266. if (P.OwnerPkg() == Pkg && Dep->Type == Dep::Conflicts)
  267. continue;
  268. // Check if the provides is a hit
  269. if (Type == NowVersion)
  270. {
  271. if (P.OwnerPkg().CurrentVer() != P.OwnerVer())
  272. continue;
  273. }
  274. if (Type == InstallVersion)
  275. {
  276. StateCache &State = PkgState[P.OwnerPkg()->ID];
  277. if (State.InstallVer != (Version *)P.OwnerVer())
  278. continue;
  279. }
  280. if (Type == CandidateVersion)
  281. {
  282. StateCache &State = PkgState[P.OwnerPkg()->ID];
  283. if (State.CandidateVer != (Version *)P.OwnerVer())
  284. continue;
  285. }
  286. // Compare the versions.
  287. if (VS().CheckDep(P.ProvideVersion(),Dep->CompareOp,Dep.TargetVer()) == true)
  288. {
  289. Res = P.OwnerPkg();
  290. return true;
  291. }
  292. }
  293. return false;
  294. }
  295. /*}}}*/
  296. // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
  297. // ---------------------------------------------------------------------
  298. /* Call with Mult = -1 to preform the inverse opration */
  299. void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult)
  300. {
  301. StateCache &P = PkgState[Pkg->ID];
  302. if (Pkg->VersionList == 0)
  303. return;
  304. if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
  305. P.Keep() == true)
  306. return;
  307. // Compute the size data
  308. if (P.NewInstall() == true)
  309. {
  310. iUsrSize += (signed)(Mult*P.InstVerIter(*this)->InstalledSize);
  311. iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size);
  312. return;
  313. }
  314. // Upgrading
  315. if (Pkg->CurrentVer != 0 &&
  316. (P.InstallVer != (Version *)Pkg.CurrentVer() ||
  317. (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0)
  318. {
  319. iUsrSize += (signed)(Mult*((signed)P.InstVerIter(*this)->InstalledSize -
  320. (signed)Pkg.CurrentVer()->InstalledSize));
  321. iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size);
  322. return;
  323. }
  324. // Reinstall
  325. if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack &&
  326. P.Delete() == false)
  327. {
  328. iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size);
  329. return;
  330. }
  331. // Removing
  332. if (Pkg->CurrentVer != 0 && P.InstallVer == 0)
  333. {
  334. iUsrSize -= (signed)(Mult*Pkg.CurrentVer()->InstalledSize);
  335. return;
  336. }
  337. }
  338. /*}}}*/
  339. // DepCache::AddStates - Add the package to the state counter /*{{{*/
  340. // ---------------------------------------------------------------------
  341. /* This routine is tricky to use, you must make sure that it is never
  342. called twice for the same package. This means the Remove/Add section
  343. should be as short as possible and not encompass any code that will
  344. calld Remove/Add itself. Remember, dependencies can be circular so
  345. while processing a dep for Pkg it is possible that Add/Remove
  346. will be called on Pkg */
  347. void pkgDepCache::AddStates(const PkgIterator &Pkg,int Add)
  348. {
  349. StateCache &State = PkgState[Pkg->ID];
  350. // The Package is broken
  351. if ((State.DepState & DepInstMin) != DepInstMin)
  352. iBrokenCount += Add;
  353. // Bad state
  354. if (Pkg.State() != PkgIterator::NeedsNothing)
  355. iBadCount += Add;
  356. // Not installed
  357. if (Pkg->CurrentVer == 0)
  358. {
  359. if (State.Mode == ModeDelete &&
  360. (State.iFlags | Purge) == Purge && Pkg.Purge() == false)
  361. iDelCount += Add;
  362. if (State.Mode == ModeInstall)
  363. iInstCount += Add;
  364. return;
  365. }
  366. // Installed, no upgrade
  367. if (State.Status == 0)
  368. {
  369. if (State.Mode == ModeDelete)
  370. iDelCount += Add;
  371. else
  372. if ((State.iFlags & ReInstall) == ReInstall)
  373. iInstCount += Add;
  374. return;
  375. }
  376. // Alll 3 are possible
  377. if (State.Mode == ModeDelete)
  378. iDelCount += Add;
  379. if (State.Mode == ModeKeep)
  380. iKeepCount += Add;
  381. if (State.Mode == ModeInstall)
  382. iInstCount += Add;
  383. }
  384. /*}}}*/
  385. // DepCache::BuildGroupOrs - Generate the Or group dep data /*{{{*/
  386. // ---------------------------------------------------------------------
  387. /* The or group results are stored in the last item of the or group. This
  388. allows easy detection of the state of a whole or'd group. */
  389. void pkgDepCache::BuildGroupOrs(VerIterator const &V)
  390. {
  391. unsigned char Group = 0;
  392. for (DepIterator D = V.DependsList(); D.end() != true; D++)
  393. {
  394. // Build the dependency state.
  395. unsigned char &State = DepState[D->ID];
  396. /* Invert for Conflicts. We have to do this twice to get the
  397. right sense for a conflicts group */
  398. if (D->Type == Dep::Conflicts || D->Type == Dep::Obsoletes)
  399. State = ~State;
  400. // Add to the group if we are within an or..
  401. State &= 0x7;
  402. Group |= State;
  403. State |= Group << 3;
  404. if ((D->CompareOp & Dep::Or) != Dep::Or)
  405. Group = 0;
  406. // Invert for Conflicts
  407. if (D->Type == Dep::Conflicts || D->Type == Dep::Obsoletes)
  408. State = ~State;
  409. }
  410. }
  411. /*}}}*/
  412. // DepCache::VersionState - Perform a pass over a dependency list /*{{{*/
  413. // ---------------------------------------------------------------------
  414. /* This is used to run over a dependency list and determine the dep
  415. state of the list, filtering it through both a Min check and a Policy
  416. check. The return result will have SetMin/SetPolicy low if a check
  417. fails. It uses the DepState cache for it's computations. */
  418. unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check,
  419. unsigned char SetMin,
  420. unsigned char SetPolicy)
  421. {
  422. unsigned char Dep = 0xFF;
  423. while (D.end() != true)
  424. {
  425. // Compute a single dependency element (glob or)
  426. DepIterator Start = D;
  427. unsigned char State = 0;
  428. for (bool LastOR = true; D.end() == false && LastOR == true; D++)
  429. {
  430. State |= DepState[D->ID];
  431. LastOR = (D->CompareOp & Dep::Or) == Dep::Or;
  432. }
  433. // Minimum deps that must be satisfied to have a working package
  434. if (Start.IsCritical() == true)
  435. if ((State & Check) != Check)
  436. Dep &= ~SetMin;
  437. // Policy deps that must be satisfied to install the package
  438. if (IsImportantDep(Start) == true &&
  439. (State & Check) != Check)
  440. Dep &= ~SetPolicy;
  441. }
  442. return Dep;
  443. }
  444. /*}}}*/
  445. // DepCache::DependencyState - Compute the 3 results for a dep /*{{{*/
  446. // ---------------------------------------------------------------------
  447. /* This is the main dependency computation bit. It computes the 3 main
  448. results for a dependencys, Now, Install and Candidate. Callers must
  449. invert the result if dealing with conflicts. */
  450. unsigned char pkgDepCache::DependencyState(DepIterator &D)
  451. {
  452. unsigned char State = 0;
  453. if (CheckDep(D,NowVersion) == true)
  454. State |= DepNow;
  455. if (CheckDep(D,InstallVersion) == true)
  456. State |= DepInstall;
  457. if (CheckDep(D,CandidateVersion) == true)
  458. State |= DepCVer;
  459. return State;
  460. }
  461. /*}}}*/
  462. // DepCache::UpdateVerState - Compute the Dep member of the state /*{{{*/
  463. // ---------------------------------------------------------------------
  464. /* This determines the combined dependency representation of a package
  465. for its two states now and install. This is done by using the pre-generated
  466. dependency information. */
  467. void pkgDepCache::UpdateVerState(PkgIterator Pkg)
  468. {
  469. // Empty deps are always true
  470. StateCache &State = PkgState[Pkg->ID];
  471. State.DepState = 0xFF;
  472. // Check the Current state
  473. if (Pkg->CurrentVer != 0)
  474. {
  475. DepIterator D = Pkg.CurrentVer().DependsList();
  476. State.DepState &= VersionState(D,DepNow,DepNowMin,DepNowPolicy);
  477. }
  478. /* Check the candidate state. We do not compare against the whole as
  479. a candidate state but check the candidate version against the
  480. install states */
  481. if (State.CandidateVer != 0)
  482. {
  483. DepIterator D = State.CandidateVerIter(*this).DependsList();
  484. State.DepState &= VersionState(D,DepInstall,DepCandMin,DepCandPolicy);
  485. }
  486. // Check target state which can only be current or installed
  487. if (State.InstallVer != 0)
  488. {
  489. DepIterator D = State.InstVerIter(*this).DependsList();
  490. State.DepState &= VersionState(D,DepInstall,DepInstMin,DepInstPolicy);
  491. }
  492. }
  493. /*}}}*/
  494. // DepCache::Update - Figure out all the state information /*{{{*/
  495. // ---------------------------------------------------------------------
  496. /* This will figure out the state of all the packages and all the
  497. dependencies based on the current policy. */
  498. void pkgDepCache::Update(OpProgress *Prog)
  499. {
  500. iUsrSize = 0;
  501. iDownloadSize = 0;
  502. iDelCount = 0;
  503. iInstCount = 0;
  504. iKeepCount = 0;
  505. iBrokenCount = 0;
  506. iBadCount = 0;
  507. // Perform the depends pass
  508. int Done = 0;
  509. for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
  510. {
  511. if (Prog != 0 && Done%20 == 0)
  512. Prog->Progress(Done);
  513. for (VerIterator V = I.VersionList(); V.end() != true; V++)
  514. {
  515. unsigned char Group = 0;
  516. for (DepIterator D = V.DependsList(); D.end() != true; D++)
  517. {
  518. // Build the dependency state.
  519. unsigned char &State = DepState[D->ID];
  520. State = DependencyState(D);
  521. // Add to the group if we are within an or..
  522. Group |= State;
  523. State |= Group << 3;
  524. if ((D->CompareOp & Dep::Or) != Dep::Or)
  525. Group = 0;
  526. // Invert for Conflicts
  527. if (D->Type == Dep::Conflicts || D->Type == Dep::Obsoletes)
  528. State = ~State;
  529. }
  530. }
  531. // Compute the pacakge dependency state and size additions
  532. AddSizes(I);
  533. UpdateVerState(I);
  534. AddStates(I);
  535. }
  536. if (Prog != 0)
  537. Prog->Progress(Done);
  538. readStateFile(Prog);
  539. }
  540. /*}}}*/
  541. // DepCache::Update - Update the deps list of a package /*{{{*/
  542. // ---------------------------------------------------------------------
  543. /* This is a helper for update that only does the dep portion of the scan.
  544. It is mainly meant to scan reverse dependencies. */
  545. void pkgDepCache::Update(DepIterator D)
  546. {
  547. // Update the reverse deps
  548. for (;D.end() != true; D++)
  549. {
  550. unsigned char &State = DepState[D->ID];
  551. State = DependencyState(D);
  552. // Invert for Conflicts
  553. if (D->Type == Dep::Conflicts || D->Type == Dep::Obsoletes)
  554. State = ~State;
  555. RemoveStates(D.ParentPkg());
  556. BuildGroupOrs(D.ParentVer());
  557. UpdateVerState(D.ParentPkg());
  558. AddStates(D.ParentPkg());
  559. }
  560. }
  561. /*}}}*/
  562. // DepCache::Update - Update the related deps of a package /*{{{*/
  563. // ---------------------------------------------------------------------
  564. /* This is called whenever the state of a package changes. It updates
  565. all cached dependencies related to this package. */
  566. void pkgDepCache::Update(PkgIterator const &Pkg)
  567. {
  568. // Recompute the dep of the package
  569. RemoveStates(Pkg);
  570. UpdateVerState(Pkg);
  571. AddStates(Pkg);
  572. // Update the reverse deps
  573. Update(Pkg.RevDependsList());
  574. // Update the provides map for the current ver
  575. if (Pkg->CurrentVer != 0)
  576. for (PrvIterator P = Pkg.CurrentVer().ProvidesList();
  577. P.end() != true; P++)
  578. Update(P.ParentPkg().RevDependsList());
  579. // Update the provides map for the candidate ver
  580. if (PkgState[Pkg->ID].CandidateVer != 0)
  581. for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList();
  582. P.end() != true; P++)
  583. Update(P.ParentPkg().RevDependsList());
  584. }
  585. /*}}}*/
  586. // DepCache::MarkKeep - Put the package in the keep state /*{{{*/
  587. // ---------------------------------------------------------------------
  588. /* */
  589. void pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser)
  590. {
  591. // Simplifies other routines.
  592. if (Pkg.end() == true)
  593. return;
  594. /* Reject an attempt to keep a non-source broken installed package, those
  595. must be upgraded */
  596. if (Pkg.State() == PkgIterator::NeedsUnpack &&
  597. Pkg.CurrentVer().Downloadable() == false)
  598. return;
  599. /** \todo Can this be moved later in the method? */
  600. ActionGroup group(*this);
  601. /* We changed the soft state all the time so the UI is a bit nicer
  602. to use */
  603. StateCache &P = PkgState[Pkg->ID];
  604. if (Soft == true)
  605. P.iFlags |= AutoKept;
  606. else
  607. P.iFlags &= ~AutoKept;
  608. // Check that it is not already kept
  609. if (P.Mode == ModeKeep)
  610. return;
  611. // We dont even try to keep virtual packages..
  612. if (Pkg->VersionList == 0)
  613. return;
  614. #if 0 // reseting the autoflag here means we lose the
  615. // auto-mark information if a user selects a package for removal
  616. // but changes his mind then and sets it for keep again
  617. // - this makes sense as default when all Garbage dependencies
  618. // are automatically marked for removal (as aptitude does).
  619. // setting a package for keep then makes it no longer autoinstalled
  620. // for all other use-case this action is rather suprising
  621. if(FromUser && !P.Marked)
  622. P.Flags &= ~Flag::Auto;
  623. #endif
  624. RemoveSizes(Pkg);
  625. RemoveStates(Pkg);
  626. P.Mode = ModeKeep;
  627. if (Pkg->CurrentVer == 0)
  628. P.InstallVer = 0;
  629. else
  630. P.InstallVer = Pkg.CurrentVer();
  631. AddStates(Pkg);
  632. Update(Pkg);
  633. AddSizes(Pkg);
  634. }
  635. /*}}}*/
  636. // DepCache::MarkDelete - Put the package in the delete state /*{{{*/
  637. // ---------------------------------------------------------------------
  638. /* */
  639. void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge)
  640. {
  641. // Simplifies other routines.
  642. if (Pkg.end() == true)
  643. return;
  644. ActionGroup group(*this);
  645. // Check that it is not already marked for delete
  646. StateCache &P = PkgState[Pkg->ID];
  647. P.iFlags &= ~(AutoKept | Purge);
  648. if (rPurge == true)
  649. P.iFlags |= Purge;
  650. if ((P.Mode == ModeDelete || P.InstallVer == 0) &&
  651. (Pkg.Purge() == true || rPurge == false))
  652. return;
  653. // We dont even try to delete virtual packages..
  654. if (Pkg->VersionList == 0)
  655. return;
  656. RemoveSizes(Pkg);
  657. RemoveStates(Pkg);
  658. if (Pkg->CurrentVer == 0 && (Pkg.Purge() == true || rPurge == false))
  659. P.Mode = ModeKeep;
  660. else
  661. P.Mode = ModeDelete;
  662. P.InstallVer = 0;
  663. AddStates(Pkg);
  664. Update(Pkg);
  665. AddSizes(Pkg);
  666. }
  667. /*}}}*/
  668. // DepCache::MarkInstall - Put the package in the install state /*{{{*/
  669. // ---------------------------------------------------------------------
  670. /* */
  671. void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
  672. unsigned long Depth, bool FromUser)
  673. {
  674. if (Depth > 100)
  675. return;
  676. // Simplifies other routines.
  677. if (Pkg.end() == true)
  678. return;
  679. ActionGroup group(*this);
  680. /* Check that it is not already marked for install and that it can be
  681. installed */
  682. StateCache &P = PkgState[Pkg->ID];
  683. P.iFlags &= ~AutoKept;
  684. if (P.InstBroken() == false && (P.Mode == ModeInstall ||
  685. P.CandidateVer == (Version *)Pkg.CurrentVer()))
  686. {
  687. if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0)
  688. MarkKeep(Pkg, false, FromUser);
  689. return;
  690. }
  691. // See if there is even any possible instalation candidate
  692. if (P.CandidateVer == 0)
  693. return;
  694. // We dont even try to install virtual packages..
  695. if (Pkg->VersionList == 0)
  696. return;
  697. /* Target the candidate version and remove the autoflag. We reset the
  698. autoflag below if this was called recursively. Otherwise the user
  699. should have the ability to de-auto a package by changing its state */
  700. RemoveSizes(Pkg);
  701. RemoveStates(Pkg);
  702. P.Mode = ModeInstall;
  703. P.InstallVer = P.CandidateVer;
  704. if(FromUser)
  705. {
  706. // Set it to manual if it's a new install or cancelling the
  707. // removal of a garbage package.
  708. if(P.Status == 2 || (!Pkg.CurrentVer().end() && !P.Marked))
  709. P.Flags &= ~Flag::Auto;
  710. }
  711. else
  712. {
  713. // Set it to auto if this is a new install.
  714. if(P.Status == 2)
  715. P.Flags |= Flag::Auto;
  716. }
  717. if (P.CandidateVer == (Version *)Pkg.CurrentVer())
  718. P.Mode = ModeKeep;
  719. AddStates(Pkg);
  720. Update(Pkg);
  721. AddSizes(Pkg);
  722. if (AutoInst == false)
  723. return;
  724. DepIterator Dep = P.InstVerIter(*this).DependsList();
  725. for (; Dep.end() != true;)
  726. {
  727. // Grok or groups
  728. DepIterator Start = Dep;
  729. bool Result = true;
  730. unsigned Ors = 0;
  731. for (bool LastOR = true; Dep.end() == false && LastOR == true; Dep++,Ors++)
  732. {
  733. LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or;
  734. if ((DepState[Dep->ID] & DepInstall) == DepInstall)
  735. Result = false;
  736. }
  737. // Dep is satisfied okay.
  738. if (Result == false)
  739. continue;
  740. /* Check if this dep should be consider for install. If it is a user
  741. defined important dep and we are installed a new package then
  742. it will be installed. Otherwise we only worry about critical deps */
  743. if (IsImportantDep(Start) == false)
  744. continue;
  745. if (Pkg->CurrentVer != 0 && Start.IsCritical() == false)
  746. continue;
  747. /* If we are in an or group locate the first or that can
  748. succeed. We have already cached this.. */
  749. for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; Ors--)
  750. Start++;
  751. /* This bit is for processing the possibilty of an install/upgrade
  752. fixing the problem */
  753. SPtrArray<Version *> List = Start.AllTargets();
  754. if ((DepState[Start->ID] & DepCVer) == DepCVer)
  755. {
  756. // Right, find the best version to install..
  757. Version **Cur = List;
  758. PkgIterator P = Start.TargetPkg();
  759. PkgIterator InstPkg(*Cache,0);
  760. // See if there are direct matches (at the start of the list)
  761. for (; *Cur != 0 && (*Cur)->ParentPkg == P.Index(); Cur++)
  762. {
  763. PkgIterator Pkg(*Cache,Cache->PkgP + (*Cur)->ParentPkg);
  764. if (PkgState[Pkg->ID].CandidateVer != *Cur)
  765. continue;
  766. InstPkg = Pkg;
  767. break;
  768. }
  769. // Select the highest priority providing package
  770. if (InstPkg.end() == true)
  771. {
  772. pkgPrioSortList(*Cache,Cur);
  773. for (; *Cur != 0; Cur++)
  774. {
  775. PkgIterator Pkg(*Cache,Cache->PkgP + (*Cur)->ParentPkg);
  776. if (PkgState[Pkg->ID].CandidateVer != *Cur)
  777. continue;
  778. InstPkg = Pkg;
  779. break;
  780. }
  781. }
  782. if (InstPkg.end() == false)
  783. {
  784. if(_config->FindB("Debug::pkgDepCache::AutoInstall",false) == true)
  785. std::clog << "Installing " << InstPkg.Name()
  786. << " as dep of " << Pkg.Name()
  787. << std::endl;
  788. // now check if we should consider it a automatic dependency or not
  789. string sec = _config->Find("APT::Never-MarkAuto-Section","");
  790. if(Pkg.Section() && (string(Pkg.Section()) == sec))
  791. {
  792. if(_config->FindB("Debug::pkgDepCache::AutoInstall",false) == true)
  793. std::clog << "Setting NOT as auto-installed because its a direct dep of a package in section " << sec << std::endl;
  794. MarkInstall(InstPkg,true,Depth + 1, true);
  795. }
  796. else
  797. {
  798. // mark automatic dependency
  799. MarkInstall(InstPkg,true,Depth + 1, false);
  800. // Set the autoflag, after MarkInstall because MarkInstall unsets it
  801. if (P->CurrentVer == 0)
  802. PkgState[InstPkg->ID].Flags |= Flag::Auto;
  803. }
  804. }
  805. continue;
  806. }
  807. /* For conflicts we just de-install the package and mark as auto,
  808. Conflicts may not have or groups */
  809. if (Start->Type == Dep::Conflicts || Start->Type == Dep::Obsoletes)
  810. {
  811. for (Version **I = List; *I != 0; I++)
  812. {
  813. VerIterator Ver(*this,*I);
  814. PkgIterator Pkg = Ver.ParentPkg();
  815. MarkDelete(Pkg);
  816. }
  817. continue;
  818. }
  819. }
  820. }
  821. /*}}}*/
  822. // DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
  823. // ---------------------------------------------------------------------
  824. /* */
  825. void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
  826. {
  827. ActionGroup group(*this);
  828. RemoveSizes(Pkg);
  829. RemoveStates(Pkg);
  830. StateCache &P = PkgState[Pkg->ID];
  831. if (To == true)
  832. P.iFlags |= ReInstall;
  833. else
  834. P.iFlags &= ~ReInstall;
  835. AddStates(Pkg);
  836. AddSizes(Pkg);
  837. }
  838. /*}}}*/
  839. // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
  840. // ---------------------------------------------------------------------
  841. /* */
  842. void pkgDepCache::SetCandidateVersion(VerIterator TargetVer)
  843. {
  844. ActionGroup group(*this);
  845. pkgCache::PkgIterator Pkg = TargetVer.ParentPkg();
  846. StateCache &P = PkgState[Pkg->ID];
  847. RemoveSizes(Pkg);
  848. RemoveStates(Pkg);
  849. if (P.CandidateVer == P.InstallVer)
  850. P.InstallVer = (Version *)TargetVer;
  851. P.CandidateVer = (Version *)TargetVer;
  852. P.Update(Pkg,*this);
  853. AddStates(Pkg);
  854. Update(Pkg);
  855. AddSizes(Pkg);
  856. }
  857. void pkgDepCache::MarkAuto(const PkgIterator &Pkg, bool Auto)
  858. {
  859. StateCache &state = PkgState[Pkg->ID];
  860. ActionGroup group(*this);
  861. if(Auto)
  862. state.Flags |= Flag::Auto;
  863. else
  864. state.Flags &= ~Flag::Auto;
  865. }
  866. /*}}}*/
  867. // StateCache::Update - Compute the various static display things /*{{{*/
  868. // ---------------------------------------------------------------------
  869. /* This is called whenever the Candidate version changes. */
  870. void pkgDepCache::StateCache::Update(PkgIterator Pkg,pkgCache &Cache)
  871. {
  872. // Some info
  873. VerIterator Ver = CandidateVerIter(Cache);
  874. // Use a null string or the version string
  875. if (Ver.end() == true)
  876. CandVersion = "";
  877. else
  878. CandVersion = Ver.VerStr();
  879. // Find the current version
  880. CurVersion = "";
  881. if (Pkg->CurrentVer != 0)
  882. CurVersion = Pkg.CurrentVer().VerStr();
  883. // Strip off the epochs for display
  884. CurVersion = StripEpoch(CurVersion);
  885. CandVersion = StripEpoch(CandVersion);
  886. // Figure out if its up or down or equal
  887. Status = Ver.CompareVer(Pkg.CurrentVer());
  888. if (Pkg->CurrentVer == 0 || Pkg->VersionList == 0 || CandidateVer == 0)
  889. Status = 2;
  890. }
  891. /*}}}*/
  892. // StateCache::StripEpoch - Remove the epoch specifier from the version /*{{{*/
  893. // ---------------------------------------------------------------------
  894. /* */
  895. const char *pkgDepCache::StateCache::StripEpoch(const char *Ver)
  896. {
  897. if (Ver == 0)
  898. return 0;
  899. // Strip any epoch
  900. for (const char *I = Ver; *I != 0; I++)
  901. if (*I == ':')
  902. return I + 1;
  903. return Ver;
  904. }
  905. /*}}}*/
  906. // Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
  907. // ---------------------------------------------------------------------
  908. /* The default just returns the highest available version that is not
  909. a source and automatic. */
  910. pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator Pkg)
  911. {
  912. /* Not source/not automatic versions cannot be a candidate version
  913. unless they are already installed */
  914. VerIterator Last(*(pkgCache *)this,0);
  915. for (VerIterator I = Pkg.VersionList(); I.end() == false; I++)
  916. {
  917. if (Pkg.CurrentVer() == I)
  918. return I;
  919. for (VerFileIterator J = I.FileList(); J.end() == false; J++)
  920. {
  921. if ((J.File()->Flags & Flag::NotSource) != 0)
  922. continue;
  923. /* Stash the highest version of a not-automatic source, we use it
  924. if there is nothing better */
  925. if ((J.File()->Flags & Flag::NotAutomatic) != 0)
  926. {
  927. if (Last.end() == true)
  928. Last = I;
  929. continue;
  930. }
  931. return I;
  932. }
  933. }
  934. return Last;
  935. }
  936. /*}}}*/
  937. // Policy::IsImportantDep - True if the dependency is important /*{{{*/
  938. // ---------------------------------------------------------------------
  939. /* */
  940. bool pkgDepCache::Policy::IsImportantDep(DepIterator Dep)
  941. {
  942. return Dep.IsCritical();
  943. }
  944. /*}}}*/
  945. pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc()
  946. : constructedSuccessfully(false)
  947. {
  948. Configuration::Item const *Opts;
  949. Opts = _config->Tree("APT::NeverAutoRemove");
  950. if (Opts != 0 && Opts->Child != 0)
  951. {
  952. Opts = Opts->Child;
  953. for (; Opts != 0; Opts = Opts->Next)
  954. {
  955. if (Opts->Value.empty() == true)
  956. continue;
  957. regex_t *p = new regex_t;
  958. if(regcomp(p,Opts->Value.c_str(),
  959. REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
  960. {
  961. regfree(p);
  962. delete p;
  963. _error->Error("Regex compilation error for APT::NeverAutoRemove");
  964. return;
  965. }
  966. rootSetRegexp.push_back(p);
  967. }
  968. }
  969. constructedSuccessfully = true;
  970. }
  971. pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc()
  972. {
  973. for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
  974. {
  975. regfree(rootSetRegexp[i]);
  976. delete rootSetRegexp[i];
  977. }
  978. }
  979. bool pkgDepCache::DefaultRootSetFunc::InRootSet(const pkgCache::PkgIterator &pkg)
  980. {
  981. for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
  982. if (regexec(rootSetRegexp[i], pkg.Name(), 0, 0, 0) == 0)
  983. return true;
  984. return false;
  985. }
  986. pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc()
  987. {
  988. DefaultRootSetFunc *f = new DefaultRootSetFunc;
  989. if(f->wasConstructedSuccessfully())
  990. return f;
  991. else
  992. {
  993. delete f;
  994. return NULL;
  995. }
  996. }
  997. bool pkgDepCache::MarkFollowsRecommends()
  998. {
  999. return _config->FindB("APT::AutoRemove::RecommendsImportant", true);
  1000. }
  1001. bool pkgDepCache::MarkFollowsSuggests()
  1002. {
  1003. return _config->FindB("APT::AutoRemove::SuggestsImportant", false);
  1004. }
  1005. // the main mark algorithm
  1006. bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
  1007. {
  1008. bool follow_recommends;
  1009. bool follow_suggests;
  1010. // init the states
  1011. for(PkgIterator p = PkgBegin(); !p.end(); ++p)
  1012. {
  1013. PkgState[p->ID].Marked = false;
  1014. PkgState[p->ID].Garbage = false;
  1015. // debug output
  1016. if(_config->FindB("Debug::pkgAutoRemove",false)
  1017. && PkgState[p->ID].Flags & Flag::Auto)
  1018. std::clog << "AutoDep: " << p.Name() << std::endl;
  1019. }
  1020. // init vars
  1021. follow_recommends = MarkFollowsRecommends();
  1022. follow_suggests = MarkFollowsSuggests();
  1023. // do the mark part, this is the core bit of the algorithm
  1024. for(PkgIterator p = PkgBegin(); !p.end(); ++p)
  1025. {
  1026. if(!(PkgState[p->ID].Flags & Flag::Auto) ||
  1027. (p->Flags & Flag::Essential) ||
  1028. userFunc.InRootSet(p))
  1029. {
  1030. // the package is installed (and set to keep)
  1031. if(PkgState[p->ID].Keep() && !p.CurrentVer().end())
  1032. MarkPackage(p, p.CurrentVer(),
  1033. follow_recommends, follow_suggests);
  1034. // the package is to be installed
  1035. else if(PkgState[p->ID].Install())
  1036. MarkPackage(p, PkgState[p->ID].InstVerIter(*this),
  1037. follow_recommends, follow_suggests);
  1038. }
  1039. }
  1040. return true;
  1041. }
  1042. // mark a single package in Mark-and-Sweep
  1043. void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
  1044. const pkgCache::VerIterator &ver,
  1045. bool follow_recommends,
  1046. bool follow_suggests)
  1047. {
  1048. pkgDepCache::StateCache &state = PkgState[pkg->ID];
  1049. VerIterator candver = state.CandidateVerIter(*this);
  1050. VerIterator instver = state.InstVerIter(*this);
  1051. #if 0
  1052. // If a package was garbage-collected but is now being marked, we
  1053. // should re-select it
  1054. // For cases when a pkg is set to upgrade and this trigger the
  1055. // removal of a no-longer used dependency. if the pkg is set to
  1056. // keep again later it will result in broken deps
  1057. if(state.Delete() && state.RemoveReason = Unused)
  1058. {
  1059. if(ver==candver)
  1060. mark_install(pkg, false, false, NULL);
  1061. else if(ver==pkg.CurrentVer())
  1062. MarkKeep(pkg, false, false);
  1063. instver=state.InstVerIter(*this);
  1064. }
  1065. #endif
  1066. // Ignore versions other than the InstVer, and ignore packages
  1067. // that are already going to be removed or just left uninstalled.
  1068. if(!(ver == instver && !instver.end()))
  1069. return;
  1070. // if we are marked already we are done
  1071. if(state.Marked)
  1072. return;
  1073. //std::cout << "Setting Marked for: " << pkg.Name() << std::endl;
  1074. state.Marked=true;
  1075. if(!ver.end())
  1076. {
  1077. for(DepIterator d = ver.DependsList(); !d.end(); ++d)
  1078. {
  1079. if(d->Type == Dep::Depends ||
  1080. d->Type == Dep::PreDepends ||
  1081. (follow_recommends &&
  1082. d->Type == Dep::Recommends) ||
  1083. (follow_suggests &&
  1084. d->Type == Dep::Suggests))
  1085. {
  1086. // Try all versions of this package.
  1087. for(VerIterator V = d.TargetPkg().VersionList();
  1088. !V.end(); ++V)
  1089. {
  1090. if(_system->VS->CheckDep(V.VerStr(), d->CompareOp, d.TargetVer()))
  1091. {
  1092. MarkPackage(V.ParentPkg(), V,
  1093. follow_recommends, follow_suggests);
  1094. }
  1095. }
  1096. // Now try virtual packages
  1097. for(PrvIterator prv=d.TargetPkg().ProvidesList();
  1098. !prv.end(); ++prv)
  1099. {
  1100. if(_system->VS->CheckDep(prv.ProvideVersion(), d->CompareOp,
  1101. d.TargetVer()))
  1102. {
  1103. MarkPackage(prv.OwnerPkg(), prv.OwnerVer(),
  1104. follow_recommends, follow_suggests);
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. bool pkgDepCache::Sweep()
  1112. {
  1113. // do the sweep
  1114. for(PkgIterator p=PkgBegin(); !p.end(); ++p)
  1115. {
  1116. StateCache &state=PkgState[p->ID];
  1117. // skip required packages
  1118. if (!p.CurrentVer().end() &&
  1119. (p.CurrentVer()->Priority == pkgCache::State::Required))
  1120. continue;
  1121. // if it is not marked and it is installed, it's garbage
  1122. if(!state.Marked && (!p.CurrentVer().end() || state.Install()))
  1123. {
  1124. state.Garbage=true;
  1125. if(_config->FindB("Debug::pkgAutoRemove",false))
  1126. std::cout << "Garbage: " << p.Name() << std::endl;
  1127. }
  1128. }
  1129. return true;
  1130. }