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.
 
 
 
 
 
 

79 lines
2.0 KiB

  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 <stdio.h>
  18. #include <sys/types.h>
  19. class MultiCompress
  20. {
  21. // Enumeration of all supported compressors
  22. struct CompType
  23. {
  24. const char *Name;
  25. const char *Extension;
  26. const char *Binary;
  27. const char *CompArgs;
  28. const char *UnCompArgs;
  29. unsigned char Cost;
  30. };
  31. // An output file
  32. struct Files
  33. {
  34. string Output;
  35. const CompType *CompressProg;
  36. Files *Next;
  37. FileFd TmpFile;
  38. pid_t CompressProc;
  39. time_t OldMTime;
  40. int Fd;
  41. };
  42. Files *Outputs;
  43. pid_t Outputter;
  44. mode_t Permissions;
  45. static const CompType Compressors[];
  46. bool OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd,
  47. int &OutFd,bool const &Comp);
  48. bool Child(int const &Fd);
  49. bool Start();
  50. bool Die();
  51. public:
  52. // The FD to write to for compression.
  53. FILE *Input;
  54. unsigned long UpdateMTime;
  55. bool Finalize(unsigned long &OutSize);
  56. bool OpenOld(int &Fd,pid_t &Proc);
  57. bool CloseOld(int Fd,pid_t Proc);
  58. static bool GetStat(string const &Output,string const &Compress,struct stat &St);
  59. MultiCompress(string const &Output,string const &Compress,
  60. mode_t const &Permissions, bool const &Write = true);
  61. ~MultiCompress();
  62. };
  63. #endif