testdeb.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <config.h>
  2. #include <apt-pkg/dirstream.h>
  3. #include <apt-pkg/debfile.h>
  4. #include <apt-pkg/error.h>
  5. #include <apt-pkg/extracttar.h>
  6. #include <apt-pkg/arfile.h>
  7. #include <apt-pkg/fileutl.h>
  8. #include <iostream>
  9. #include <string>
  10. class NullStream : public pkgDirStream
  11. {
  12. public:
  13. virtual bool DoItem(Item &/*Itm*/, int &/*Fd*/) APT_OVERRIDE {return true;};
  14. };
  15. static bool Test(const char *File)
  16. {
  17. FileFd Fd(File,FileFd::ReadOnly);
  18. debDebFile Deb(Fd);
  19. if (_error->PendingError() == true)
  20. return false;
  21. // Get the archive member and positition the file
  22. const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz");
  23. if (Member == 0)
  24. return false;
  25. // Extract it.
  26. ExtractTar Tar(Deb.GetFile(),Member->Size, "gzip");
  27. NullStream Dir;
  28. if (Tar.Go(Dir) == false)
  29. return false;
  30. return true;
  31. }
  32. int main(int argc, const char *argv[])
  33. {
  34. if (argc != 2) {
  35. std::cout << "One parameter expected - given " << argc << std::endl;
  36. return 100;
  37. }
  38. Test(argv[1]);
  39. _error->DumpErrors();
  40. return 0;
  41. }