]> git.saurik.com Git - apt.git/blob - ftparchive/multicompress.h
5496b06d02e18f09171aa4caa4949d65a46b1275
[apt.git] / ftparchive / multicompress.h
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 #include <apt-pkg/fileutl.h>
20 #include <apt-pkg/aptconfiguration.h>
21
22 #include <string>
23 #include <stdio.h>
24 #include <sys/types.h>
25
26 class MultiCompress
27 {
28 // An output file
29 struct Files
30 {
31 std::string Output;
32 APT::Configuration::Compressor CompressProg;
33 Files *Next;
34 FileFd TmpFile;
35 pid_t CompressProc;
36 time_t OldMTime;
37 int Fd;
38 };
39
40 Files *Outputs;
41 pid_t Outputter;
42 mode_t Permissions;
43
44 bool OpenCompress(APT::Configuration::Compressor const &Prog,
45 pid_t &Pid,int const &FileFd, int &OutFd,bool const &Comp);
46 bool Child(int const &Fd);
47 bool Start();
48 bool Die();
49
50 public:
51
52 // The FD to write to for compression.
53 FILE *Input;
54 unsigned long UpdateMTime;
55
56 bool Finalize(unsigned long long &OutSize);
57 bool OpenOld(int &Fd,pid_t &Proc);
58 bool CloseOld(int Fd,pid_t Proc);
59 static bool GetStat(std::string const &Output,std::string const &Compress,struct stat &St);
60
61 MultiCompress(std::string const &Output,std::string const &Compress,
62 mode_t const &Permissions, bool const &Write = true);
63 ~MultiCompress();
64 };
65
66 #endif