testextract.cc 2.0 KB

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