cachefile.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: cachefile.cc,v 1.2 1999/04/19 02:35:38 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. /*}}}*/
  21. // CacheFile::CacheFile - Constructor /*{{{*/
  22. // ---------------------------------------------------------------------
  23. /* */
  24. pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), Lock()
  25. {
  26. }
  27. /*}}}*/
  28. // CacheFile::~CacheFile - Destructor /*{{{*/
  29. // ---------------------------------------------------------------------
  30. /* */
  31. pkgCacheFile::~pkgCacheFile()
  32. {
  33. delete Cache;
  34. delete Map;
  35. delete Lock;
  36. }
  37. /*}}}*/
  38. // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
  39. // ---------------------------------------------------------------------
  40. /* */
  41. bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
  42. {
  43. if (WithLock == true)
  44. Lock = new pkgDpkgLock;
  45. if (_error->PendingError() == true)
  46. return false;
  47. // Read the source list
  48. pkgSourceList List;
  49. if (List.ReadMainList() == false)
  50. return _error->Error("The list of sources could not be read.");
  51. /* Build all of the caches, using the cache files if we are locking
  52. (ie as root) */
  53. if (WithLock == true)
  54. {
  55. pkgMakeStatusCache(List,Progress);
  56. Progress.Done();
  57. if (_error->PendingError() == true)
  58. return _error->Error("The package lists or status file could not be parsed or opened.");
  59. if (_error->empty() == false)
  60. _error->Warning("You may want to run apt-get update to correct theses missing files");
  61. // Open the cache file
  62. FileFd File(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
  63. if (_error->PendingError() == true)
  64. return false;
  65. Map = new MMap(File,MMap::Public | MMap::ReadOnly);
  66. if (_error->PendingError() == true)
  67. return false;
  68. }
  69. else
  70. {
  71. Map = pkgMakeStatusCacheMem(List,Progress);
  72. Progress.Done();
  73. if (Map == 0)
  74. return false;
  75. }
  76. // Create the dependency cache
  77. Cache = new pkgDepCache(*Map,Progress);
  78. Progress.Done();
  79. if (_error->PendingError() == true)
  80. return false;
  81. return true;
  82. }
  83. /*}}}*/