You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

130 lines
3.5 KiB

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