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