]>
Commit | Line | Data |
---|---|---|
b2e465d6 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7db98ffc | 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 | ||
16 | #ifdef __GNUG__ | |
17 | #pragma interface "writer.h" | |
18 | #endif | |
19 | ||
20 | #include <string> | |
21 | #include <stdio.h> | |
8c58f506 | 22 | #include <iostream> |
64177f17 | 23 | #include <vector> |
f7291f62 | 24 | #include <map> |
b2e465d6 AL |
25 | |
26 | #include "cachedb.h" | |
27 | #include "override.h" | |
28 | #include "apt-ftparchive.h" | |
8c58f506 AL |
29 | |
30 | using std::string; | |
31 | using std::cout; | |
32 | using std::endl; | |
98953965 | 33 | using std::vector; |
f7291f62 | 34 | using std::map; |
b2e465d6 AL |
35 | |
36 | class FTWScanner | |
37 | { | |
38 | protected: | |
98953965 | 39 | vector<string> Patterns; |
b2e465d6 AL |
40 | const char *OriginalPath; |
41 | char *RealPath; | |
42 | bool ErrorPrinted; | |
43 | ||
44 | // Stuff for the delinker | |
45 | bool NoLinkAct; | |
46 | ||
47 | static FTWScanner *Owner; | |
48 | static int Scanner(const char *File,const struct stat *sb,int Flag); | |
49 | ||
50 | bool Delink(string &FileName,const char *OriginalPath, | |
51 | unsigned long &Bytes,struct stat &St); | |
52 | ||
53 | inline void NewLine(unsigned Priority) | |
54 | { | |
55 | if (ErrorPrinted == false && Quiet <= Priority) | |
56 | { | |
57 | cout << endl; | |
58 | ErrorPrinted = true; | |
59 | } | |
60 | } | |
61 | ||
62 | public: | |
63 | ||
64 | unsigned long DeLinkLimit; | |
65 | string InternalPrefix; | |
66 | ||
67 | virtual bool DoPackage(string FileName) = 0; | |
68 | bool RecursiveScan(string Dir); | |
69 | bool LoadFileList(string BaseDir,string File); | |
af6fa0b8 AL |
70 | void ClearPatterns() { Patterns.clear(); }; |
71 | void AddPattern(string Pattern) { Patterns.push_back(Pattern); }; | |
b2e465d6 AL |
72 | bool SetExts(string Vals); |
73 | ||
74 | FTWScanner(); | |
98953965 | 75 | virtual ~FTWScanner() {delete [] RealPath;}; |
b2e465d6 AL |
76 | }; |
77 | ||
78 | class PackagesWriter : public FTWScanner | |
79 | { | |
80 | Override Over; | |
81 | CacheDB Db; | |
82 | ||
83 | public: | |
84 | ||
85 | // Some flags | |
86 | bool DoMD5; | |
87 | bool NoOverride; | |
88 | bool DoContents; | |
89 | ||
90 | // General options | |
91 | string PathPrefix; | |
92 | string DirStrip; | |
93 | FILE *Output; | |
94 | struct CacheDB::Stats &Stats; | |
29ba053e MZ |
95 | string Arch; |
96 | ||
b2e465d6 | 97 | inline bool ReadOverride(string File) {return Over.ReadOverride(File);}; |
64177f17 AL |
98 | inline bool ReadExtraOverride(string File) |
99 | {return Over.ReadExtraOverride(File);}; | |
b2e465d6 AL |
100 | virtual bool DoPackage(string FileName); |
101 | ||
29ba053e MZ |
102 | PackagesWriter(string DB,string Overrides,string ExtOverrides=string(), |
103 | string Arch=string()); | |
b2e465d6 AL |
104 | virtual ~PackagesWriter() {}; |
105 | }; | |
106 | ||
107 | class ContentsWriter : public FTWScanner | |
108 | { | |
109 | CacheDB Db; | |
110 | ||
111 | GenContents Gen; | |
112 | ||
113 | public: | |
114 | ||
115 | // General options | |
116 | FILE *Output; | |
117 | struct CacheDB::Stats &Stats; | |
118 | string Prefix; | |
119 | ||
120 | bool DoPackage(string FileName,string Package); | |
121 | virtual bool DoPackage(string FileName) | |
122 | {return DoPackage(FileName,string());}; | |
123 | bool ReadFromPkgs(string PkgFile,string PkgCompress); | |
124 | ||
125 | void Finish() {Gen.Print(Output);}; | |
126 | inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);}; | |
127 | ||
128 | ContentsWriter(string DB); | |
129 | virtual ~ContentsWriter() {}; | |
130 | }; | |
131 | ||
132 | class SourcesWriter : public FTWScanner | |
133 | { | |
134 | Override BOver; | |
135 | Override SOver; | |
136 | char *Buffer; | |
137 | unsigned long BufSize; | |
138 | ||
139 | public: | |
140 | ||
141 | bool NoOverride; | |
142 | ||
143 | // General options | |
144 | string PathPrefix; | |
145 | string DirStrip; | |
146 | FILE *Output; | |
147 | struct CacheDB::Stats Stats; | |
148 | ||
b2e465d6 AL |
149 | virtual bool DoPackage(string FileName); |
150 | ||
64177f17 AL |
151 | SourcesWriter(string BOverrides,string SOverrides, |
152 | string ExtOverrides=string()); | |
b2e465d6 AL |
153 | virtual ~SourcesWriter() {free(Buffer);}; |
154 | }; | |
155 | ||
98953965 AL |
156 | class ReleaseWriter : public FTWScanner |
157 | { | |
158 | public: | |
159 | ReleaseWriter(string DB); | |
160 | virtual bool DoPackage(string FileName); | |
f7291f62 AL |
161 | void Finish(); |
162 | ||
163 | FILE *Output; | |
98953965 AL |
164 | // General options |
165 | string PathPrefix; | |
166 | string DirStrip; | |
f7291f62 AL |
167 | |
168 | protected: | |
169 | struct CheckSum | |
170 | { | |
171 | string MD5; | |
172 | string SHA1; | |
173 | // Limited by FileFd::Size() | |
174 | unsigned long size; | |
29ba053e | 175 | ~CheckSum() {}; |
f7291f62 AL |
176 | }; |
177 | map<string,struct CheckSum> CheckSums; | |
98953965 | 178 | }; |
b2e465d6 AL |
179 | |
180 | #endif |