pkgrecords.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgrecords.cc,v 1.5 1999/02/22 03:30:06 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. Files = new PkgFile[Cache.HeaderP->PackageFileCount];
  24. for (pkgCache::PkgFileIterator I = Cache.FileBegin();
  25. I.end() == false; I++)
  26. {
  27. // We can not initialize if the cache is out of sync.
  28. if (I.IsOk() == false)
  29. {
  30. _error->Error("Package file %s is out of sync.",I.FileName());
  31. return;
  32. }
  33. // Create the file
  34. Files[I->ID].File = new FileFd(I.FileName(),FileFd::ReadOnly);
  35. if (_error->PendingError() == true)
  36. return;
  37. // Create the parser
  38. Files[I->ID].Parse = new debRecordParser(*Files[I->ID].File,Cache);
  39. if (_error->PendingError() == true)
  40. return;
  41. }
  42. }
  43. /*}}}*/
  44. // Records::~pkgRecords - Destructor /*{{{*/
  45. // ---------------------------------------------------------------------
  46. /* */
  47. pkgRecords::~pkgRecords()
  48. {
  49. delete [] Files;
  50. }
  51. /*}}}*/
  52. // Records::Lookup - Get a parser for the package version file /*{{{*/
  53. // ---------------------------------------------------------------------
  54. /* */
  55. pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
  56. {
  57. PkgFile &File = Files[Ver.File()->ID];
  58. File.Parse->Jump(Ver);
  59. return *File.Parse;
  60. }
  61. /*}}}*/
  62. // Records::Pkgfile::~PkgFile - Destructor /*{{{*/
  63. // ---------------------------------------------------------------------
  64. /* */
  65. pkgRecords::PkgFile::~PkgFile()
  66. {
  67. delete Parse;
  68. delete File;
  69. }
  70. /*}}}*/