testextract.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <apt-pkg/dpkgdb.h>
  2. #include <apt-pkg/debfile.h>
  3. #include <apt-pkg/error.h>
  4. #include <apt-pkg/configuration.h>
  5. #include <apt-pkg/progress.h>
  6. #include <apt-pkg/extract.h>
  7. #include <apt-pkg/init.h>
  8. #include <apt-pkg/strutl.h>
  9. #include <apt-pkg/fileutl.h>
  10. #include <apt-pkg/pkgsystem.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. using namespace std;
  14. bool Go(int argc,char *argv[])
  15. {
  16. // Init the database
  17. debDpkgDB Db;
  18. {
  19. OpTextProgress Prog;
  20. if (Db.ReadyPkgCache(Prog) == false)
  21. return false;
  22. Prog.Done();
  23. if (Db.ReadyFileList(Prog) == false)
  24. return false;
  25. }
  26. for (int I = 1; I < argc; I++)
  27. {
  28. const char *Fake = 0;
  29. for (unsigned J = 0; argv[I][J] != 0; J++)
  30. {
  31. if (argv[I][J] != ',')
  32. continue;
  33. Fake = argv[I] + J + 1;
  34. argv[I][J] = 0;
  35. }
  36. FileFd F(argv[I],FileFd::ReadOnly);
  37. debDebFile Deb(F);
  38. if (_error->PendingError() == true)
  39. return false;
  40. if (Deb.ExtractControl(Db) == false)
  41. return false;
  42. cout << argv[I] << endl;
  43. pkgCache::VerIterator Ver = Deb.MergeControl(Db);
  44. if (Ver.end() == true)
  45. return false;
  46. cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
  47. pkgExtract Extract(Db.GetFLCache(),Ver);
  48. if (Fake != 0)
  49. {
  50. pkgExtract::Item Itm;
  51. memset(&Itm,0,sizeof(Itm));
  52. FILE *F = fopen(Fake,"r");
  53. while (feof(F) == 0)
  54. {
  55. char Line[300];
  56. if (fgets(Line,sizeof(Line),F) == NULL)
  57. return false;
  58. Itm.Name = _strstrip(Line);
  59. Itm.Type = pkgDirStream::Item::File;
  60. if (Line[strlen(Line)-1] == '/')
  61. Itm.Type = pkgDirStream::Item::Directory;
  62. int Fd;
  63. if (Extract.DoItem(Itm,Fd) == false) {
  64. fclose(F);
  65. return false;
  66. }
  67. }
  68. fclose(F);
  69. }
  70. else
  71. if (Deb.ExtractArchive(Extract) == false)
  72. return false;
  73. }
  74. return true;
  75. }
  76. int main(int argc,char *argv[])
  77. {
  78. pkgInitConfig(*_config);
  79. pkgInitSystem(*_config,_system);
  80. _config->Set("Dir::State::status","/tmp/testing/status");
  81. Go(argc,argv);
  82. if (_error->PendingError() == true)
  83. {
  84. _error->DumpErrors();
  85. return 0;
  86. }
  87. }