cachefile.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
  4. /* ######################################################################
  5. CacheFile - Simple wrapper class for opening, generating and whatnot
  6. This class implements a simple 2 line mechanism to open various sorts
  7. of caches. It can operate as root, as not root, show progress and so on,
  8. it transparently handles everything necessary.
  9. ##################################################################### */
  10. /*}}}*/
  11. // Include Files /*{{{*/
  12. #include <apt-pkg/cachefile.h>
  13. #include <apt-pkg/error.h>
  14. #include <apt-pkg/sourcelist.h>
  15. #include <apt-pkg/pkgcachegen.h>
  16. #include <apt-pkg/configuration.h>
  17. #include <apt-pkg/policy.h>
  18. #include <apt-pkg/pkgsystem.h>
  19. #include <apti18n.h>
  20. /*}}}*/
  21. // CacheFile::CacheFile - Constructor /*{{{*/
  22. // ---------------------------------------------------------------------
  23. /* */
  24. pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
  25. {
  26. }
  27. /*}}}*/
  28. // CacheFile::~CacheFile - Destructor /*{{{*/
  29. // ---------------------------------------------------------------------
  30. /* */
  31. pkgCacheFile::~pkgCacheFile()
  32. {
  33. delete DCache;
  34. delete Policy;
  35. delete Cache;
  36. delete Map;
  37. _system->UnLock(true);
  38. }
  39. /*}}}*/
  40. // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
  41. // ---------------------------------------------------------------------
  42. /* */
  43. bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
  44. {
  45. if (WithLock == true)
  46. if (_system->Lock() == false)
  47. return false;
  48. if (_config->FindB("Debug::NoLocking",false) == true)
  49. WithLock = false;
  50. if (_error->PendingError() == true)
  51. return false;
  52. // Read the source list
  53. pkgSourceList List;
  54. if (List.ReadMainList() == false)
  55. return _error->Error(_("The list of sources could not be read."));
  56. // Read the caches
  57. bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
  58. Progress.Done();
  59. if (Res == false)
  60. return _error->Error(_("The package lists or status file could not be parsed or opened."));
  61. /* This sux, remove it someday */
  62. if (_error->empty() == false)
  63. _error->Warning(_("You may want to run apt-get update to correct these problems"));
  64. Cache = new pkgCache(Map);
  65. if (_error->PendingError() == true)
  66. return false;
  67. return true;
  68. }
  69. /*}}}*/
  70. // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
  71. // ---------------------------------------------------------------------
  72. /* */
  73. bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
  74. {
  75. if (BuildCaches(Progress,WithLock) == false)
  76. return false;
  77. // The policy engine
  78. Policy = new pkgPolicy(Cache);
  79. if (_error->PendingError() == true)
  80. return false;
  81. if (ReadPinFile(*Policy) == false)
  82. return false;
  83. // Create the dependency cache
  84. DCache = new pkgDepCache(Cache,Policy);
  85. if (_error->PendingError() == true)
  86. return false;
  87. DCache->Init(&Progress);
  88. Progress.Done();
  89. if (_error->PendingError() == true)
  90. return false;
  91. return true;
  92. }
  93. /*}}}*/
  94. // CacheFile::Close - close the cache files /*{{{*/
  95. // ---------------------------------------------------------------------
  96. /* */
  97. void pkgCacheFile::Close()
  98. {
  99. delete DCache;
  100. delete Policy;
  101. delete Cache;
  102. delete Map;
  103. _system->UnLock(true);
  104. Map = 0;
  105. DCache = 0;
  106. Policy = 0;
  107. Cache = 0;
  108. }
  109. /*}}}*/