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