aptmethod.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef APT_APTMETHOD_H
  2. #define APT_APTMETHOD_H
  3. #include <apt-pkg/acquire-method.h>
  4. #include <apt-pkg/configuration.h>
  5. #include <locale>
  6. #include <string>
  7. class aptMethod : public pkgAcqMethod
  8. {
  9. char const * const Binary;
  10. public:
  11. virtual bool Configuration(std::string Message) APT_OVERRIDE
  12. {
  13. if (pkgAcqMethod::Configuration(Message) == false)
  14. return false;
  15. std::string const conf = std::string("Binary::") + Binary;
  16. _config->MoveSubTree(conf.c_str(), NULL);
  17. DropPrivsOrDie();
  18. return true;
  19. }
  20. bool CalculateHashes(FetchItem const * const Itm, FetchResult &Res) const
  21. {
  22. Hashes Hash(Itm->ExpectedHashes);
  23. FileFd Fd;
  24. if (Fd.Open(Res.Filename, FileFd::ReadOnly) == false || Hash.AddFD(Fd) == false)
  25. return false;
  26. Res.TakeHashes(Hash);
  27. return true;
  28. }
  29. void Warning(const char *Format,...)
  30. {
  31. va_list args;
  32. va_start(args,Format);
  33. PrintStatus("104 Warning", Format, args);
  34. va_end(args);
  35. }
  36. aptMethod(char const * const Binary, char const * const Ver, unsigned long const Flags) :
  37. pkgAcqMethod(Ver, Flags), Binary(Binary)
  38. {
  39. try {
  40. std::locale::global(std::locale(""));
  41. } catch (...) {
  42. setlocale(LC_ALL, "");
  43. }
  44. }
  45. };
  46. #endif