sources.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <string>
  2. #include <sstream>
  3. // for memcpy
  4. #include <cstring>
  5. #include <apt-pkg/error.h>
  6. #include <apt-pkg/gpgv.h>
  7. #include "sources.h"
  8. bool DscExtract::TakeDsc(const void *newData, unsigned long long newSize)
  9. {
  10. if (newSize == 0)
  11. {
  12. // adding two newlines 'off record' for pkgTagSection.Scan() calls
  13. Data = "\n\n";
  14. Length = 0;
  15. return true;
  16. }
  17. Data = std::string((const char*)newData, newSize);
  18. // adding two newlines 'off record' for pkgTagSection.Scan() calls
  19. Data.append("\n\n");
  20. Length = newSize;
  21. return true;
  22. }
  23. bool DscExtract::Read(std::string FileName)
  24. {
  25. Data.clear();
  26. Length = 0;
  27. FileFd F;
  28. if (OpenMaybeClearSignedFile(FileName, F) == false)
  29. return false;
  30. IsClearSigned = (FileName != F.Name());
  31. std::ostringstream data;
  32. char buffer[1024];
  33. do {
  34. unsigned long long actual = 0;
  35. if (F.Read(buffer, sizeof(buffer)-1, &actual) == false)
  36. return _error->Errno("read", "Failed to read dsc file %s", FileName.c_str());
  37. if (actual == 0)
  38. break;
  39. Length += actual;
  40. buffer[actual] = '\0';
  41. data << buffer;
  42. } while(true);
  43. // adding two newlines 'off record' for pkgTagSection.Scan() calls
  44. data << "\n\n";
  45. Data = data.str();
  46. return true;
  47. }