]>
Commit | Line | Data |
---|---|---|
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 | |
29 | using std::string; | |
30 | using std::cout; | |
31 | using std::endl; | |
98953965 | 32 | using std::vector; |
f7291f62 | 33 | using std::map; |
b2e465d6 AL |
34 | |
35 | class 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: | |
3c54407f DK |
63 | bool DoMD5; |
64 | bool DoSHA1; | |
65 | bool DoSHA256; | |
b2e465d6 AL |
66 | |
67 | unsigned long DeLinkLimit; | |
68 | string InternalPrefix; | |
69 | ||
70 | virtual bool DoPackage(string FileName) = 0; | |
9209ec47 DK |
71 | bool RecursiveScan(string const &Dir); |
72 | bool LoadFileList(string const &BaseDir,string const &File); | |
af6fa0b8 | 73 | void ClearPatterns() { Patterns.clear(); }; |
9209ec47 | 74 | void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); }; |
3cb3fe76 DK |
75 | void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); }; |
76 | void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); }; | |
9209ec47 | 77 | bool SetExts(string const &Vals); |
b2e465d6 | 78 | |
31981076 | 79 | FTWScanner(string const &Arch = string()); |
4c265635 | 80 | virtual ~FTWScanner() {}; |
b2e465d6 AL |
81 | }; |
82 | ||
66905344 DK |
83 | class TranslationWriter |
84 | { | |
34f1d96c | 85 | MultiCompress *Comp; |
66905344 DK |
86 | FILE *Output; |
87 | std::set<string> Included; | |
88 | unsigned short RefCounter; | |
89 | ||
90 | public: | |
91 | void IncreaseRefCounter() { ++RefCounter; }; | |
92 | unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; }; | |
93 | unsigned short GetRefCounter() const { return RefCounter; }; | |
94 | bool DoPackage(string const &Pkg, string const &Desc, string const &MD5); | |
95 | ||
34f1d96c DK |
96 | TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions); |
97 | TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {}; | |
66905344 DK |
98 | ~TranslationWriter(); |
99 | }; | |
100 | ||
b2e465d6 AL |
101 | class PackagesWriter : public FTWScanner |
102 | { | |
103 | Override Over; | |
104 | CacheDB Db; | |
105 | ||
106 | public: | |
107 | ||
108 | // Some flags | |
ff574e76 | 109 | bool DoAlwaysStat; |
b2e465d6 AL |
110 | bool NoOverride; |
111 | bool DoContents; | |
9c24493f | 112 | bool LongDescription; |
b2e465d6 AL |
113 | |
114 | // General options | |
115 | string PathPrefix; | |
116 | string DirStrip; | |
117 | FILE *Output; | |
118 | struct CacheDB::Stats &Stats; | |
66905344 | 119 | TranslationWriter *TransWriter; |
0b41e0e7 | 120 | |
9209ec47 DK |
121 | inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);}; |
122 | inline bool ReadExtraOverride(string const &File) | |
64177f17 | 123 | {return Over.ReadExtraOverride(File);}; |
b2e465d6 AL |
124 | virtual bool DoPackage(string FileName); |
125 | ||
9209ec47 DK |
126 | PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(), |
127 | string const &Arch=string()); | |
b2e465d6 AL |
128 | virtual ~PackagesWriter() {}; |
129 | }; | |
130 | ||
131 | class ContentsWriter : public FTWScanner | |
132 | { | |
133 | CacheDB Db; | |
134 | ||
135 | GenContents Gen; | |
136 | ||
137 | public: | |
138 | ||
139 | // General options | |
140 | FILE *Output; | |
141 | struct CacheDB::Stats &Stats; | |
142 | string Prefix; | |
143 | ||
144 | bool DoPackage(string FileName,string Package); | |
145 | virtual bool DoPackage(string FileName) | |
146 | {return DoPackage(FileName,string());}; | |
9209ec47 | 147 | bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress); |
b2e465d6 AL |
148 | |
149 | void Finish() {Gen.Print(Output);}; | |
9209ec47 | 150 | inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);}; |
b2e465d6 | 151 | |
31981076 | 152 | ContentsWriter(string const &DB, string const &Arch = string()); |
b2e465d6 AL |
153 | virtual ~ContentsWriter() {}; |
154 | }; | |
155 | ||
156 | class SourcesWriter : public FTWScanner | |
157 | { | |
158 | Override BOver; | |
159 | Override SOver; | |
160 | char *Buffer; | |
161 | unsigned long BufSize; | |
162 | ||
163 | public: | |
164 | ||
165 | bool NoOverride; | |
166 | ||
167 | // General options | |
168 | string PathPrefix; | |
169 | string DirStrip; | |
170 | FILE *Output; | |
171 | struct CacheDB::Stats Stats; | |
172 | ||
b2e465d6 AL |
173 | virtual bool DoPackage(string FileName); |
174 | ||
9209ec47 DK |
175 | SourcesWriter(string const &BOverrides,string const &SOverrides, |
176 | string const &ExtOverrides=string()); | |
b2e465d6 AL |
177 | virtual ~SourcesWriter() {free(Buffer);}; |
178 | }; | |
179 | ||
98953965 AL |
180 | class ReleaseWriter : public FTWScanner |
181 | { | |
182 | public: | |
9209ec47 | 183 | ReleaseWriter(string const &DB); |
98953965 | 184 | virtual bool DoPackage(string FileName); |
f7291f62 AL |
185 | void Finish(); |
186 | ||
187 | FILE *Output; | |
98953965 AL |
188 | // General options |
189 | string PathPrefix; | |
190 | string DirStrip; | |
f7291f62 AL |
191 | |
192 | protected: | |
193 | struct CheckSum | |
194 | { | |
195 | string MD5; | |
196 | string SHA1; | |
cde41ae8 | 197 | string SHA256; |
f7291f62 AL |
198 | // Limited by FileFd::Size() |
199 | unsigned long size; | |
0b41e0e7 | 200 | ~CheckSum() {}; |
f7291f62 AL |
201 | }; |
202 | map<string,struct CheckSum> CheckSums; | |
98953965 | 203 | }; |
b2e465d6 AL |
204 | |
205 | #endif |