]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: writer.h,v 1.4.2.2 2003/12/26 22:55:43 mdz Exp $ | |
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 | ||
16 | #include <apt-pkg/hashes.h> | |
17 | ||
18 | #include <string> | |
19 | #include <stdio.h> | |
20 | #include <iostream> | |
21 | #include <vector> | |
22 | #include <map> | |
23 | #include <set> | |
24 | #include <stdlib.h> | |
25 | #include <sys/types.h> | |
26 | ||
27 | #include "contents.h" | |
28 | #include "cachedb.h" | |
29 | #include "override.h" | |
30 | #include "apt-ftparchive.h" | |
31 | ||
32 | using std::string; | |
33 | using std::cout; | |
34 | using std::endl; | |
35 | using std::vector; | |
36 | using std::map; | |
37 | ||
38 | class FTWScanner | |
39 | { | |
40 | protected: | |
41 | vector<string> Patterns; | |
42 | string Arch; | |
43 | const char *OriginalPath; | |
44 | bool ErrorPrinted; | |
45 | ||
46 | // Stuff for the delinker | |
47 | bool NoLinkAct; | |
48 | ||
49 | static FTWScanner *Owner; | |
50 | static int ScannerFTW(const char *File,const struct stat *sb,int Flag); | |
51 | static int ScannerFile(const char *File, bool const &ReadLink); | |
52 | ||
53 | bool Delink(string &FileName,const char *OriginalPath, | |
54 | unsigned long long &Bytes,unsigned long long const &FileSize); | |
55 | ||
56 | inline void NewLine(unsigned const &Priority) | |
57 | { | |
58 | if (ErrorPrinted == false && Quiet <= Priority) | |
59 | { | |
60 | c1out << endl; | |
61 | ErrorPrinted = true; | |
62 | } | |
63 | } | |
64 | ||
65 | public: | |
66 | FileFd *Output; | |
67 | bool OwnsOutput; | |
68 | unsigned int DoHashes; | |
69 | ||
70 | unsigned long DeLinkLimit; | |
71 | string InternalPrefix; | |
72 | ||
73 | virtual bool DoPackage(string FileName) = 0; | |
74 | bool RecursiveScan(string const &Dir); | |
75 | bool LoadFileList(string const &BaseDir,string const &File); | |
76 | void ClearPatterns() { Patterns.clear(); }; | |
77 | void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); }; | |
78 | void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); }; | |
79 | void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); }; | |
80 | bool SetExts(string const &Vals); | |
81 | ||
82 | FTWScanner(FileFd * const Output, string const &Arch = string()); | |
83 | virtual ~FTWScanner(); | |
84 | }; | |
85 | ||
86 | class MultiCompress; | |
87 | ||
88 | class TranslationWriter | |
89 | { | |
90 | MultiCompress *Comp; | |
91 | std::set<string> Included; | |
92 | FileFd *Output; | |
93 | ||
94 | public: | |
95 | bool DoPackage(string const &Pkg, string const &Desc, string const &MD5); | |
96 | ||
97 | TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions); | |
98 | ~TranslationWriter(); | |
99 | }; | |
100 | ||
101 | class PackagesWriter : public FTWScanner | |
102 | { | |
103 | Override Over; | |
104 | CacheDB Db; | |
105 | ||
106 | public: | |
107 | ||
108 | // Some flags | |
109 | bool DoAlwaysStat; | |
110 | bool NoOverride; | |
111 | bool DoContents; | |
112 | bool LongDescription; | |
113 | ||
114 | // General options | |
115 | string PathPrefix; | |
116 | string DirStrip; | |
117 | struct CacheDB::Stats &Stats; | |
118 | TranslationWriter * const TransWriter; | |
119 | ||
120 | inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);}; | |
121 | inline bool ReadExtraOverride(string const &File) | |
122 | {return Over.ReadExtraOverride(File);}; | |
123 | virtual bool DoPackage(string FileName) APT_OVERRIDE; | |
124 | ||
125 | PackagesWriter(FileFd * const Output, TranslationWriter * const TransWriter, string const &DB, | |
126 | string const &Overrides, | |
127 | string const &ExtOverrides = "", | |
128 | string const &Arch = ""); | |
129 | virtual ~PackagesWriter(); | |
130 | }; | |
131 | ||
132 | class ContentsWriter : public FTWScanner | |
133 | { | |
134 | CacheDB Db; | |
135 | ||
136 | GenContents Gen; | |
137 | ||
138 | public: | |
139 | ||
140 | // General options | |
141 | struct CacheDB::Stats &Stats; | |
142 | string Prefix; | |
143 | ||
144 | bool DoPackage(string FileName,string Package); | |
145 | virtual bool DoPackage(string FileName) APT_OVERRIDE | |
146 | {return DoPackage(FileName,string());}; | |
147 | bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress); | |
148 | ||
149 | void Finish() {Gen.Print(*Output);}; | |
150 | inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);}; | |
151 | ||
152 | ContentsWriter(FileFd * const Output, string const &DB, string const &Arch = string()); | |
153 | virtual ~ContentsWriter() {}; | |
154 | }; | |
155 | ||
156 | class SourcesWriter : public FTWScanner | |
157 | { | |
158 | CacheDB Db; | |
159 | Override BOver; | |
160 | Override SOver; | |
161 | char *Buffer; | |
162 | unsigned long long BufSize; | |
163 | ||
164 | public: | |
165 | ||
166 | bool NoOverride; | |
167 | bool DoAlwaysStat; | |
168 | ||
169 | // General options | |
170 | string PathPrefix; | |
171 | string DirStrip; | |
172 | struct CacheDB::Stats &Stats; | |
173 | ||
174 | virtual bool DoPackage(string FileName) APT_OVERRIDE; | |
175 | ||
176 | SourcesWriter(FileFd * const Output, string const &DB,string const &BOverrides,string const &SOverrides, | |
177 | string const &ExtOverrides=string()); | |
178 | virtual ~SourcesWriter() {free(Buffer);}; | |
179 | }; | |
180 | ||
181 | class ReleaseWriter : public FTWScanner | |
182 | { | |
183 | public: | |
184 | ReleaseWriter(FileFd * const Output, string const &DB); | |
185 | virtual bool DoPackage(string FileName) APT_OVERRIDE; | |
186 | void Finish(); | |
187 | ||
188 | // General options | |
189 | string PathPrefix; | |
190 | string DirStrip; | |
191 | ||
192 | struct CheckSum | |
193 | { | |
194 | HashStringList Hashes; | |
195 | // Limited by FileFd::Size() | |
196 | unsigned long long size; | |
197 | ~CheckSum() {}; | |
198 | }; | |
199 | protected: | |
200 | map<string,struct CheckSum> CheckSums; | |
201 | }; | |
202 | ||
203 | #endif |