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