]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: multicompress.h,v 1.2 2001/02/20 07:03:18 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | MultiCompressor | |
7 | ||
8 | Multiple output class. Takes a single FILE* and writes it simultaneously | |
9 | to many compressed files. Then checks if the resulting output is | |
10 | different from any previous output and overwrites the old files. Care is | |
11 | taken to ensure that the new files are not generally readable while they | |
12 | are being written. | |
13 | ||
14 | ##################################################################### */ | |
15 | /*}}}*/ | |
16 | #ifndef MULTICOMPRESS_H | |
17 | #define MULTICOMPRESS_H | |
18 | ||
19 | #ifdef __GNUG__ | |
20 | #pragma interface "multicompress.h" | |
21 | #endif | |
22 | ||
23 | #include <string> | |
24 | #include <apt-pkg/fileutl.h> | |
25 | #include <stdio.h> | |
26 | #include <sys/types.h> | |
27 | ||
28 | class MultiCompress | |
29 | { | |
30 | // Enumeration of all supported compressors | |
31 | struct CompType | |
32 | { | |
33 | const char *Name; | |
34 | const char *Extension; | |
35 | const char *Binary; | |
36 | const char *CompArgs; | |
37 | const char *UnCompArgs; | |
38 | unsigned char Cost; | |
39 | }; | |
40 | ||
41 | // An output file | |
42 | struct Files | |
43 | { | |
44 | string Output; | |
45 | const CompType *CompressProg; | |
46 | Files *Next; | |
47 | FileFd TmpFile; | |
48 | pid_t CompressProc; | |
49 | time_t OldMTime; | |
50 | int Fd; | |
51 | }; | |
52 | ||
53 | Files *Outputs; | |
54 | pid_t Outputter; | |
55 | mode_t Permissions; | |
56 | static const CompType Compressors[]; | |
57 | ||
58 | bool OpenCompress(const CompType *Prog,pid_t &Pid,int FileFd, | |
59 | int &OutFd,bool Comp); | |
60 | bool Child(int Fd); | |
61 | bool Start(); | |
62 | bool Die(); | |
63 | ||
64 | public: | |
65 | ||
66 | // The FD to write to for compression. | |
67 | FILE *Input; | |
68 | unsigned long UpdateMTime; | |
69 | ||
70 | bool Finalize(unsigned long &OutSize); | |
71 | bool OpenOld(int &Fd,pid_t &Proc); | |
72 | bool CloseOld(int Fd,pid_t Proc); | |
73 | static bool GetStat(string Output,string Compress,struct stat &St); | |
74 | ||
75 | MultiCompress(string Output,string Compress,mode_t Permissions, | |
76 | bool Write = true); | |
77 | ~MultiCompress(); | |
78 | }; | |
79 | ||
80 | #endif |