depcache.cc 37 KB

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