multicompress.h 1.6 KB

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