Switch the TranslationWriter to use MultiCompress to be able to generate
[ntk/apt.git] / ftparchive / writer.h
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b3d44315 3// $Id: writer.h,v 1.4.2.2 2003/12/26 22:55:43 mdz Exp $
b2e465d6
AL
4/* ######################################################################
5
6 Writer
7
8 The file writer classes. These write various types of output, sources,
9 packages and contents.
10
11 ##################################################################### */
12 /*}}}*/
13#ifndef WRITER_H
14#define WRITER_H
15
b2e465d6
AL
16
17#include <string>
18#include <stdio.h>
8c58f506 19#include <iostream>
64177f17 20#include <vector>
f7291f62 21#include <map>
66905344 22#include <set>
b2e465d6
AL
23
24#include "cachedb.h"
34f1d96c 25#include "multicompress.h"
b2e465d6
AL
26#include "override.h"
27#include "apt-ftparchive.h"
8c58f506
AL
28
29using std::string;
30using std::cout;
31using std::endl;
98953965 32using std::vector;
f7291f62 33using std::map;
b2e465d6
AL
34
35class FTWScanner
36{
37 protected:
98953965 38 vector<string> Patterns;
31981076 39 string Arch;
b2e465d6 40 const char *OriginalPath;
b2e465d6
AL
41 bool ErrorPrinted;
42
43 // Stuff for the delinker
44 bool NoLinkAct;
45
46 static FTWScanner *Owner;
cde41ae8 47 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
9209ec47 48 static int ScannerFile(const char *File, bool const &ReadLink);
b2e465d6
AL
49
50 bool Delink(string &FileName,const char *OriginalPath,
9209ec47 51 unsigned long &Bytes,off_t const &FileSize);
b2e465d6 52
9209ec47 53 inline void NewLine(unsigned const &Priority)
b2e465d6
AL
54 {
55 if (ErrorPrinted == false && Quiet <= Priority)
56 {
db40f8e0 57 c1out << endl;
b2e465d6
AL
58 ErrorPrinted = true;
59 }
60 }
61
62 public:
63
64 unsigned long DeLinkLimit;
65 string InternalPrefix;
66
67 virtual bool DoPackage(string FileName) = 0;
9209ec47
DK
68 bool RecursiveScan(string const &Dir);
69 bool LoadFileList(string const &BaseDir,string const &File);
af6fa0b8 70 void ClearPatterns() { Patterns.clear(); };
9209ec47
DK
71 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
72 bool SetExts(string const &Vals);
b2e465d6 73
31981076 74 FTWScanner(string const &Arch = string());
b2e465d6
AL
75};
76
66905344
DK
77class TranslationWriter
78{
34f1d96c 79 MultiCompress *Comp;
66905344
DK
80 FILE *Output;
81 std::set<string> Included;
82 unsigned short RefCounter;
83
84 public:
85 void IncreaseRefCounter() { ++RefCounter; };
86 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
87 unsigned short GetRefCounter() const { return RefCounter; };
88 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
89
34f1d96c
DK
90 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
91 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
66905344
DK
92 ~TranslationWriter();
93};
94
b2e465d6
AL
95class PackagesWriter : public FTWScanner
96{
97 Override Over;
98 CacheDB Db;
99
100 public:
101
102 // Some flags
103 bool DoMD5;
cde41ae8
MV
104 bool DoSHA1;
105 bool DoSHA256;
ff574e76 106 bool DoAlwaysStat;
b2e465d6
AL
107 bool NoOverride;
108 bool DoContents;
9c24493f 109 bool LongDescription;
b2e465d6
AL
110
111 // General options
112 string PathPrefix;
113 string DirStrip;
114 FILE *Output;
115 struct CacheDB::Stats &Stats;
66905344 116 TranslationWriter *TransWriter;
0b41e0e7 117
9209ec47
DK
118 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
119 inline bool ReadExtraOverride(string const &File)
64177f17 120 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
121 virtual bool DoPackage(string FileName);
122
9209ec47
DK
123 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
124 string const &Arch=string());
b2e465d6
AL
125 virtual ~PackagesWriter() {};
126};
127
128class ContentsWriter : public FTWScanner
129{
130 CacheDB Db;
131
132 GenContents Gen;
133
134 public:
135
136 // General options
137 FILE *Output;
138 struct CacheDB::Stats &Stats;
139 string Prefix;
140
141 bool DoPackage(string FileName,string Package);
142 virtual bool DoPackage(string FileName)
143 {return DoPackage(FileName,string());};
9209ec47 144 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
b2e465d6
AL
145
146 void Finish() {Gen.Print(Output);};
9209ec47 147 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
b2e465d6 148
31981076 149 ContentsWriter(string const &DB, string const &Arch = string());
b2e465d6
AL
150 virtual ~ContentsWriter() {};
151};
152
153class SourcesWriter : public FTWScanner
154{
155 Override BOver;
156 Override SOver;
157 char *Buffer;
158 unsigned long BufSize;
159
160 public:
161
162 bool NoOverride;
163
164 // General options
165 string PathPrefix;
166 string DirStrip;
167 FILE *Output;
168 struct CacheDB::Stats Stats;
169
b2e465d6
AL
170 virtual bool DoPackage(string FileName);
171
9209ec47
DK
172 SourcesWriter(string const &BOverrides,string const &SOverrides,
173 string const &ExtOverrides=string());
b2e465d6
AL
174 virtual ~SourcesWriter() {free(Buffer);};
175};
176
98953965
AL
177class ReleaseWriter : public FTWScanner
178{
179public:
9209ec47 180 ReleaseWriter(string const &DB);
98953965 181 virtual bool DoPackage(string FileName);
f7291f62
AL
182 void Finish();
183
184 FILE *Output;
98953965
AL
185 // General options
186 string PathPrefix;
187 string DirStrip;
f7291f62
AL
188
189protected:
190 struct CheckSum
191 {
192 string MD5;
193 string SHA1;
cde41ae8 194 string SHA256;
f7291f62
AL
195 // Limited by FileFd::Size()
196 unsigned long size;
0b41e0e7 197 ~CheckSum() {};
f7291f62
AL
198 };
199 map<string,struct CheckSum> CheckSums;
98953965 200};
b2e465d6
AL
201
202#endif