pkgrecords.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgrecords.cc,v 1.3 1998/10/20 02:39:23 jgg Exp $
  4. /* ######################################################################
  5. Package Records - Allows access to complete package description records
  6. directly from the file.
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #ifdef __GNUG__
  11. #pragma implementation "apt-pkg/pkgrecords.h"
  12. #endif
  13. #include <apt-pkg/pkgrecords.h>
  14. #include <apt-pkg/debrecords.h>
  15. #include <apt-pkg/error.h>
  16. #include <apt-pkg/configuration.h>
  17. /*}}}*/
  18. // Records::pkgRecords - Constructor /*{{{*/
  19. // ---------------------------------------------------------------------
  20. /* This will create the necessary structures to access the status files */
  21. pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
  22. {
  23. string ListDir = _config->FindFile("Dir::State::lists");
  24. Files = new PkgFile[Cache.HeaderP->PackageFileCount];
  25. for (pkgCache::PkgFileIterator I = Cache.FileBegin();
  26. I.end() == false; I++)
  27. {
  28. // We can not initialize if the cache is out of sync.
  29. if (I.IsOk() == false)
  30. {
  31. _error->Error("Package file %s is out of sync.",I.FileName());
  32. return;
  33. }
  34. // Create the file
  35. Files[I->ID].File = new FileFd(ListDir + I.FileName(),FileFd::ReadOnly);
  36. if (_error->PendingError() == true)
  37. return;
  38. // Create the parser
  39. Files[I->ID].Parse = new debRecordParser(*Files[I->ID].File);
  40. if (_error->PendingError() == true)
  41. return;
  42. }
  43. }
  44. /*}}}*/
  45. // Records::~pkgRecords - Destructor /*{{{*/
  46. // ---------------------------------------------------------------------
  47. /* */
  48. pkgRecords::~pkgRecords()
  49. {
  50. delete [] Files;
  51. }
  52. /*}}}*/
  53. // Records::Lookup - Get a parser for the package version file /*{{{*/
  54. // ---------------------------------------------------------------------
  55. /* */
  56. pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator &Ver)
  57. {
  58. PkgFile &File = Files[Ver.File()->ID];
  59. File.Parse->Jump(Ver);
  60. return *File.Parse;
  61. }
  62. /*}}}*/
  63. // Records::Pkgfile::~PkgFile - Destructor /*{{{*/
  64. // ---------------------------------------------------------------------
  65. /* */
  66. pkgRecords::PkgFile::~PkgFile()
  67. {
  68. delete Parse;
  69. delete File;
  70. }
  71. /*}}}*/