testextract.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <stdio.h>
  10. #include <stdlib.h>
  11. using namespace std;
  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. pkgInitConfig(*_config);
  73. pkgInitSystem(*_config,_system);
  74. _config->Set("Dir::State::status","/tmp/testing/status");
  75. Go(argc,argv);
  76. if (_error->PendingError() == true)
  77. {
  78. _error->DumpErrors();
  79. return 0;
  80. }
  81. }