cachefile.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: cachefile.cc,v 1.7 2001/07/01 20:49:08 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. #ifdef __GNUG__
  13. #pragma implementation "apt-pkg/cachefile.h"
  14. #endif
  15. #include <apt-pkg/cachefile.h>
  16. #include <apt-pkg/error.h>
  17. #include <apt-pkg/sourcelist.h>
  18. #include <apt-pkg/pkgcachegen.h>
  19. #include <apt-pkg/configuration.h>
  20. #include <apt-pkg/policy.h>
  21. #include <apt-pkg/pkgsystem.h>
  22. #include <apti18n.h>
  23. /*}}}*/
  24. // CacheFile::CacheFile - Constructor /*{{{*/
  25. // ---------------------------------------------------------------------
  26. /* */
  27. pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
  28. {
  29. }
  30. /*}}}*/
  31. // CacheFile::~CacheFile - Destructor /*{{{*/
  32. // ---------------------------------------------------------------------
  33. /* */
  34. pkgCacheFile::~pkgCacheFile()
  35. {
  36. delete DCache;
  37. delete Policy;
  38. delete Cache;
  39. delete Map;
  40. _system->UnLock(true);
  41. }
  42. /*}}}*/
  43. // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
  44. // ---------------------------------------------------------------------
  45. /* */
  46. bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
  47. {
  48. if (WithLock == true)
  49. if (_system->Lock() == false)
  50. return false;
  51. if (_config->FindB("Debug::NoLocking",false) == true)
  52. WithLock = false;
  53. if (_error->PendingError() == true)
  54. return false;
  55. // Read the source list
  56. pkgSourceList List;
  57. if (List.ReadMainList() == false)
  58. return _error->Error(_("The list of sources could not be read."));
  59. // Read the caches
  60. bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
  61. Progress.Done();
  62. if (Res == false)
  63. return _error->Error(_("The package lists or status file could not be parsed or opened."));
  64. /* This sux, remove it someday */
  65. if (_error->empty() == false)
  66. _error->Warning(_("You may want to run apt-get update to correct these problems"));
  67. Cache = new pkgCache(Map);
  68. if (_error->PendingError() == true)
  69. return false;
  70. // The policy engine
  71. Policy = new pkgPolicy(Cache);
  72. if (_error->PendingError() == true)
  73. return false;
  74. if (ReadPinFile(*Policy) == false)
  75. return false;
  76. // Create the dependency cache
  77. DCache = new pkgDepCache(Cache,Policy);
  78. if (_error->PendingError() == true)
  79. return false;
  80. DCache->Init(&Progress);
  81. Progress.Done();
  82. if (_error->PendingError() == true)
  83. return false;
  84. return true;
  85. }
  86. /*}}}*/
  87. // CacheFile::Close - close the cache files /*{{{*/
  88. // ---------------------------------------------------------------------
  89. /* */
  90. void pkgCacheFile::Close()
  91. {
  92. delete DCache;
  93. delete Policy;
  94. delete Cache;
  95. delete Map;
  96. _system->UnLock(true);
  97. Map = 0;
  98. DCache = 0;
  99. Policy = 0;
  100. Cache = 0;
  101. }
  102. /*}}}*/