]>
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" | |
25 | #include "override.h" | |
26 | #include "apt-ftparchive.h" | |
8c58f506 AL |
27 | |
28 | using std::string; | |
29 | using std::cout; | |
30 | using std::endl; | |
98953965 | 31 | using std::vector; |
f7291f62 | 32 | using std::map; |
472ff00e | 33 | |
b2e465d6 AL |
34 | class FTWScanner |
35 | { | |
36 | protected: | |
98953965 | 37 | vector<string> Patterns; |
31981076 | 38 | string Arch; |
b2e465d6 | 39 | const char *OriginalPath; |
b2e465d6 AL |
40 | bool ErrorPrinted; |
41 | ||
42 | // Stuff for the delinker | |
43 | bool NoLinkAct; | |
44 | ||
45 | static FTWScanner *Owner; | |
cde41ae8 | 46 | static int ScannerFTW(const char *File,const struct stat *sb,int Flag); |
9209ec47 | 47 | static int ScannerFile(const char *File, bool const &ReadLink); |
b2e465d6 AL |
48 | |
49 | bool Delink(string &FileName,const char *OriginalPath, | |
650faab0 | 50 | unsigned long long &Bytes,unsigned long long const &FileSize); |
b2e465d6 | 51 | |
9209ec47 | 52 | inline void NewLine(unsigned const &Priority) |
b2e465d6 AL |
53 | { |
54 | if (ErrorPrinted == false && Quiet <= Priority) | |
55 | { | |
db40f8e0 | 56 | c1out << endl; |
b2e465d6 AL |
57 | ErrorPrinted = true; |
58 | } | |
59 | } | |
60 | ||
61 | public: | |
3c54407f DK |
62 | bool DoMD5; |
63 | bool DoSHA1; | |
64 | bool DoSHA256; | |
9abccf4a | 65 | bool DoSHA512; |
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 | ||
472ff00e DK |
83 | class MultiCompress; |
84 | ||
66905344 DK |
85 | class TranslationWriter |
86 | { | |
34f1d96c | 87 | MultiCompress *Comp; |
66905344 DK |
88 | FILE *Output; |
89 | std::set<string> Included; | |
90 | unsigned short RefCounter; | |
91 | ||
92 | public: | |
93 | void IncreaseRefCounter() { ++RefCounter; }; | |
94 | unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; }; | |
95 | unsigned short GetRefCounter() const { return RefCounter; }; | |
96 | bool DoPackage(string const &Pkg, string const &Desc, string const &MD5); | |
97 | ||
34f1d96c DK |
98 | TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions); |
99 | TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {}; | |
66905344 DK |
100 | ~TranslationWriter(); |
101 | }; | |
102 | ||
b2e465d6 AL |
103 | class PackagesWriter : public FTWScanner |
104 | { | |
105 | Override Over; | |
106 | CacheDB Db; | |
107 | ||
108 | public: | |
109 | ||
110 | // Some flags | |
ff574e76 | 111 | bool DoAlwaysStat; |
b2e465d6 AL |
112 | bool NoOverride; |
113 | bool DoContents; | |
9c24493f | 114 | bool LongDescription; |
b2e465d6 AL |
115 | |
116 | // General options | |
117 | string PathPrefix; | |
118 | string DirStrip; | |
119 | FILE *Output; | |
120 | struct CacheDB::Stats &Stats; | |
66905344 | 121 | TranslationWriter *TransWriter; |
0b41e0e7 | 122 | |
9209ec47 DK |
123 | inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);}; |
124 | inline bool ReadExtraOverride(string const &File) | |
64177f17 | 125 | {return Over.ReadExtraOverride(File);}; |
b2e465d6 AL |
126 | virtual bool DoPackage(string FileName); |
127 | ||
9209ec47 DK |
128 | PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(), |
129 | string const &Arch=string()); | |
b2e465d6 AL |
130 | virtual ~PackagesWriter() {}; |
131 | }; | |
132 | ||
133 | class ContentsWriter : public FTWScanner | |
134 | { | |
135 | CacheDB Db; | |
136 | ||
137 | GenContents Gen; | |
138 | ||
139 | public: | |
140 | ||
141 | // General options | |
142 | FILE *Output; | |
143 | struct CacheDB::Stats &Stats; | |
144 | string Prefix; | |
145 | ||
146 | bool DoPackage(string FileName,string Package); | |
147 | virtual bool DoPackage(string FileName) | |
148 | {return DoPackage(FileName,string());}; | |
9209ec47 | 149 | bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress); |
b2e465d6 AL |
150 | |
151 | void Finish() {Gen.Print(Output);}; | |
9209ec47 | 152 | inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);}; |
b2e465d6 | 153 | |
31981076 | 154 | ContentsWriter(string const &DB, string const &Arch = string()); |
b2e465d6 AL |
155 | virtual ~ContentsWriter() {}; |
156 | }; | |
157 | ||
158 | class SourcesWriter : public FTWScanner | |
159 | { | |
f6f06a8f | 160 | CacheDB Db; |
b2e465d6 AL |
161 | Override BOver; |
162 | Override SOver; | |
163 | char *Buffer; | |
650faab0 | 164 | unsigned long long BufSize; |
b2e465d6 AL |
165 | |
166 | public: | |
167 | ||
168 | bool NoOverride; | |
f6f06a8f | 169 | bool DoAlwaysStat; |
b2e465d6 AL |
170 | |
171 | // General options | |
172 | string PathPrefix; | |
173 | string DirStrip; | |
174 | FILE *Output; | |
175 | struct CacheDB::Stats Stats; | |
176 | ||
b2e465d6 AL |
177 | virtual bool DoPackage(string FileName); |
178 | ||
f6f06a8f | 179 | SourcesWriter(string const &DB,string const &BOverrides,string const &SOverrides, |
9209ec47 | 180 | string const &ExtOverrides=string()); |
b2e465d6 AL |
181 | virtual ~SourcesWriter() {free(Buffer);}; |
182 | }; | |
183 | ||
98953965 AL |
184 | class ReleaseWriter : public FTWScanner |
185 | { | |
186 | public: | |
9209ec47 | 187 | ReleaseWriter(string const &DB); |
98953965 | 188 | virtual bool DoPackage(string FileName); |
f7291f62 AL |
189 | void Finish(); |
190 | ||
191 | FILE *Output; | |
98953965 AL |
192 | // General options |
193 | string PathPrefix; | |
194 | string DirStrip; | |
f7291f62 AL |
195 | |
196 | protected: | |
197 | struct CheckSum | |
198 | { | |
199 | string MD5; | |
200 | string SHA1; | |
cde41ae8 | 201 | string SHA256; |
9a961efc | 202 | string SHA512; |
f7291f62 | 203 | // Limited by FileFd::Size() |
650faab0 | 204 | unsigned long long size; |
0b41e0e7 | 205 | ~CheckSum() {}; |
f7291f62 AL |
206 | }; |
207 | map<string,struct CheckSum> CheckSums; | |
98953965 | 208 | }; |
b2e465d6 AL |
209 | |
210 | #endif |