* [ABI-Break] Implement EDSP in libapt-pkg so that all front-ends which
[ntk/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 bool DoMD5;
64 bool DoSHA1;
65 bool DoSHA256;
66
67 unsigned long DeLinkLimit;
68 string InternalPrefix;
69
70 virtual bool DoPackage(string FileName) = 0;
71 bool RecursiveScan(string const &Dir);
72 bool LoadFileList(string const &BaseDir,string const &File);
73 void ClearPatterns() { Patterns.clear(); };
74 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
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()); };
77 bool SetExts(string const &Vals);
78
79 FTWScanner(string const &Arch = string());
80 virtual ~FTWScanner() {};
81 };
82
83 class TranslationWriter
84 {
85 MultiCompress *Comp;
86 FILE *Output;
87 std::set<string> Included;
88 unsigned short RefCounter;
89
90 public:
91 void IncreaseRefCounter() { ++RefCounter; };
92 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
93 unsigned short GetRefCounter() const { return RefCounter; };
94 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
95
96 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
97 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
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 FILE *Output;
118 struct CacheDB::Stats &Stats;
119 TranslationWriter *TransWriter;
120
121 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
122 inline bool ReadExtraOverride(string const &File)
123 {return Over.ReadExtraOverride(File);};
124 virtual bool DoPackage(string FileName);
125
126 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
127 string const &Arch=string());
128 virtual ~PackagesWriter() {};
129 };
130
131 class ContentsWriter : public FTWScanner
132 {
133 CacheDB Db;
134
135 GenContents Gen;
136
137 public:
138
139 // General options
140 FILE *Output;
141 struct CacheDB::Stats &Stats;
142 string Prefix;
143
144 bool DoPackage(string FileName,string Package);
145 virtual bool DoPackage(string FileName)
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(string const &DB, string const &Arch = string());
153 virtual ~ContentsWriter() {};
154 };
155
156 class SourcesWriter : public FTWScanner
157 {
158 Override BOver;
159 Override SOver;
160 char *Buffer;
161 unsigned long BufSize;
162
163 public:
164
165 bool NoOverride;
166
167 // General options
168 string PathPrefix;
169 string DirStrip;
170 FILE *Output;
171 struct CacheDB::Stats Stats;
172
173 virtual bool DoPackage(string FileName);
174
175 SourcesWriter(string const &BOverrides,string const &SOverrides,
176 string const &ExtOverrides=string());
177 virtual ~SourcesWriter() {free(Buffer);};
178 };
179
180 class ReleaseWriter : public FTWScanner
181 {
182 public:
183 ReleaseWriter(string const &DB);
184 virtual bool DoPackage(string FileName);
185 void Finish();
186
187 FILE *Output;
188 // General options
189 string PathPrefix;
190 string DirStrip;
191
192 protected:
193 struct CheckSum
194 {
195 string MD5;
196 string SHA1;
197 string SHA256;
198 string SHA512;
199 // Limited by FileFd::Size()
200 unsigned long size;
201 ~CheckSum() {};
202 };
203 map<string,struct CheckSum> CheckSums;
204 };
205
206 #endif