multicompress.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <string>
  16. #include <apt-pkg/fileutl.h>
  17. #include <apt-pkg/aptconfiguration.h>
  18. #include <stdio.h>
  19. #include <sys/types.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. int Fd;
  32. };
  33. Files *Outputs;
  34. pid_t Outputter;
  35. mode_t Permissions;
  36. bool OpenCompress(APT::Configuration::Compressor const &Prog,
  37. pid_t &Pid,int const &FileFd, int &OutFd,bool const &Comp);
  38. bool Child(int const &Fd);
  39. bool Start();
  40. bool Die();
  41. public:
  42. // The FD to write to for compression.
  43. FILE *Input;
  44. unsigned long UpdateMTime;
  45. bool Finalize(unsigned long long &OutSize);
  46. bool OpenOld(int &Fd,pid_t &Proc);
  47. bool CloseOld(int Fd,pid_t Proc);
  48. static bool GetStat(std::string const &Output,std::string const &Compress,struct stat &St);
  49. MultiCompress(std::string const &Output,std::string const &Compress,
  50. mode_t const &Permissions, bool const &Write = true);
  51. ~MultiCompress();
  52. };
  53. #endif