testextract.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. fgets(Line,sizeof(Line),F);
  57. Itm.Name = _strstrip(Line);
  58. Itm.Type = pkgDirStream::Item::File;
  59. if (Line[strlen(Line)-1] == '/')
  60. Itm.Type = pkgDirStream::Item::Directory;
  61. int Fd;
  62. if (Extract.DoItem(Itm,Fd) == false) {
  63. fclose(F);
  64. return false;
  65. }
  66. }
  67. fclose(F);
  68. }
  69. else
  70. if (Deb.ExtractArchive(Extract) == false)
  71. return false;
  72. }
  73. return true;
  74. }
  75. int main(int argc,char *argv[])
  76. {
  77. pkgInitConfig(*_config);
  78. pkgInitSystem(*_config,_system);
  79. _config->Set("Dir::State::status","/tmp/testing/status");
  80. Go(argc,argv);
  81. if (_error->PendingError() == true)
  82. {
  83. _error->DumpErrors();
  84. return 0;
  85. }
  86. }