You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.5 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. MultiCompressor
  5. Multiple output class. Takes a single FILE* and writes it simultaneously
  6. to many compressed files. Then checks if the resulting output is
  7. different from any previous output and overwrites the old files. Care is
  8. taken to ensure that the new files are not generally readable while they
  9. are being written.
  10. ##################################################################### */
  11. /*}}}*/
  12. #ifndef MULTICOMPRESS_H
  13. #define MULTICOMPRESS_H
  14. #include <apt-pkg/aptconfiguration.h>
  15. #include <apt-pkg/fileutl.h>
  16. #include <string>
  17. #include <stdio.h>
  18. #include <sys/types.h>
  19. #include <time.h>
  20. class MultiCompress
  21. {
  22. // An output file
  23. struct Files
  24. {
  25. std::string Output;
  26. APT::Configuration::Compressor CompressProg;
  27. Files *Next;
  28. FileFd TmpFile;
  29. pid_t CompressProc;
  30. time_t OldMTime;
  31. };
  32. Files *Outputs;
  33. pid_t Outputter;
  34. mode_t Permissions;
  35. bool Child(int const &Fd);
  36. bool Start();
  37. bool Die();
  38. public:
  39. // The FD to write to for compression.
  40. FileFd Input;
  41. unsigned long UpdateMTime;
  42. bool Finalize(unsigned long long &OutSize);
  43. bool OpenOld(FileFd &Fd);
  44. static bool GetStat(std::string const &Output,std::string const &Compress,struct stat &St);
  45. MultiCompress(std::string const &Output,std::string const &Compress,
  46. mode_t const &Permissions, bool const &Write = true);
  47. ~MultiCompress();
  48. };
  49. #endif