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