cachefile.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: cachefile.cc,v 1.6 2001/03/13 06:51:46 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 (_error->PendingError() == true)
  52. return false;
  53. // Read the source list
  54. pkgSourceList List;
  55. if (List.ReadMainList() == false)
  56. return _error->Error(_("The list of sources could not be read."));
  57. // Read the caches
  58. bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
  59. Progress.Done();
  60. if (Res == false)
  61. return _error->Error(_("The package lists or status file could not be parsed or opened."));
  62. /* This sux, remove it someday */
  63. if (_error->empty() == false)
  64. _error->Warning(_("You may want to run apt-get update to correct these problems"));
  65. Cache = new pkgCache(Map);
  66. if (_error->PendingError() == true)
  67. return false;
  68. // The policy engine
  69. Policy = new pkgPolicy(Cache);
  70. if (_error->PendingError() == true)
  71. return false;
  72. if (ReadPinFile(*Policy) == false)
  73. return false;
  74. // Create the dependency cache
  75. DCache = new pkgDepCache(Cache,Policy);
  76. if (_error->PendingError() == true)
  77. return false;
  78. DCache->Init(&Progress);
  79. Progress.Done();
  80. if (_error->PendingError() == true)
  81. return false;
  82. return true;
  83. }
  84. /*}}}*/
  85. // CacheFile::Close - close the cache files /*{{{*/
  86. // ---------------------------------------------------------------------
  87. /* */
  88. void pkgCacheFile::Close()
  89. {
  90. delete DCache;
  91. delete Policy;
  92. delete Cache;
  93. delete Map;
  94. _system->UnLock(true);
  95. Map = 0;
  96. DCache = 0;
  97. Policy = 0;
  98. Cache = 0;
  99. }
  100. /*}}}*/