edspindexfile.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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)
  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,std::string(),*this) == false)
  49. return _error->Error("Problem with SelectFile %s",File.c_str());
  50. // Store the IMS information
  51. pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
  52. CFile->Size = Pkg.FileSize();
  53. CFile->mtime = Pkg.ModificationTime();
  54. map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "edsp::scenario");
  55. CFile->Archive = storage;
  56. if (Gen.MergeList(Parser) == false)
  57. return _error->Error("Problem with MergeList %s",File.c_str());
  58. return true;
  59. }
  60. /*}}}*/
  61. // Index File types for APT /*{{{*/
  62. class edspIFType: public pkgIndexFile::Type
  63. {
  64. public:
  65. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator) const
  66. {
  67. // we don't have a record parser for this type as the file is not presistent
  68. return NULL;
  69. };
  70. edspIFType() {Label = "EDSP scenario file";};
  71. };
  72. static edspIFType _apt_Universe;
  73. const pkgIndexFile::Type *edspIndex::GetType() const
  74. {
  75. return &_apt_Universe;
  76. }
  77. /*}}}*/