edspindexfile.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. The scenario file is designed to work as an intermediate file between
  5. APT and the resolver. Its on propose very similar to a dpkg status file
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <config.h>
  10. #include <apt-pkg/edspindexfile.h>
  11. #include <apt-pkg/edsplistparser.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/fileutl.h>
  14. #include <apt-pkg/progress.h>
  15. #include <apt-pkg/debindexfile.h>
  16. #include <apt-pkg/indexfile.h>
  17. #include <apt-pkg/mmap.h>
  18. #include <apt-pkg/pkgcache.h>
  19. #include <apt-pkg/cacheiterators.h>
  20. #include <apt-pkg/pkgcachegen.h>
  21. #include <apt-pkg/pkgrecords.h>
  22. #include <stddef.h>
  23. #include <unistd.h>
  24. #include <string>
  25. /*}}}*/
  26. // edspIndex::edspIndex - Constructor /*{{{*/
  27. // ---------------------------------------------------------------------
  28. /* */
  29. edspIndex::edspIndex(std::string File) : debStatusIndex(File), d(NULL)
  30. {
  31. }
  32. /*}}}*/
  33. // StatusIndex::Merge - Load the index file into a cache /*{{{*/
  34. bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
  35. {
  36. FileFd Pkg;
  37. if (File != "stdin")
  38. Pkg.Open(File, FileFd::ReadOnly);
  39. else
  40. Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly);
  41. if (_error->PendingError() == true)
  42. return false;
  43. edspListParser Parser(&Pkg);
  44. if (_error->PendingError() == true)
  45. return false;
  46. if (Prog != NULL)
  47. Prog->SubProgress(0,File);
  48. if (Gen.SelectFile(File, *this, "", "edsp") == false)
  49. return _error->Error("Problem with SelectFile %s",File.c_str());
  50. // Store the IMS information
  51. pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
  52. pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(CFile);
  53. CFile->Size = Pkg.FileSize();
  54. CFile->mtime = Pkg.ModificationTime();
  55. if (Gen.MergeList(Parser) == false)
  56. return _error->Error("Problem with MergeList %s",File.c_str());
  57. return true;
  58. }
  59. /*}}}*/
  60. // Index File types for APT /*{{{*/
  61. class APT_HIDDEN edspIFType: public pkgIndexFile::Type
  62. {
  63. public:
  64. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator) const APT_OVERRIDE
  65. {
  66. // we don't have a record parser for this type as the file is not presistent
  67. return NULL;
  68. };
  69. edspIFType() {Label = "EDSP scenario file";};
  70. };
  71. APT_HIDDEN edspIFType _apt_Universe;
  72. const pkgIndexFile::Type *edspIndex::GetType() const
  73. {
  74. return &_apt_Universe;
  75. }
  76. /*}}}*/
  77. edspIndex::~edspIndex() {}