]> git.saurik.com Git - apt.git/blob - ftparchive/writer.h
enable APT in unpack/configure ordering to handle loops as well
[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 long &Bytes,unsigned long long 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 bool DoSHA512;
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 TranslationWriter
85 {
86 MultiCompress *Comp;
87 FILE *Output;
88 std::set<string> Included;
89 unsigned short RefCounter;
90
91 public:
92 void IncreaseRefCounter() { ++RefCounter; };
93 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
94 unsigned short GetRefCounter() const { return RefCounter; };
95 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
96
97 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
98 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
99 ~TranslationWriter();
100 };
101
102 class PackagesWriter : public FTWScanner
103 {
104 Override Over;
105 CacheDB Db;
106
107 public:
108
109 // Some flags
110 bool DoAlwaysStat;
111 bool NoOverride;
112 bool DoContents;
113 bool LongDescription;
114
115 // General options
116 string PathPrefix;
117 string DirStrip;
118 FILE *Output;
119 struct CacheDB::Stats &Stats;
120 TranslationWriter *TransWriter;
121
122 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
123 inline bool ReadExtraOverride(string const &File)
124 {return Over.ReadExtraOverride(File);};
125 virtual bool DoPackage(string FileName);
126
127 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
128 string const &Arch=string());
129 virtual ~PackagesWriter() {};
130 };
131
132 class ContentsWriter : public FTWScanner
133 {
134 CacheDB Db;
135
136 GenContents Gen;
137
138 public:
139
140 // General options
141 FILE *Output;
142 struct CacheDB::Stats &Stats;
143 string Prefix;
144
145 bool DoPackage(string FileName,string Package);
146 virtual bool DoPackage(string FileName)
147 {return DoPackage(FileName,string());};
148 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
149
150 void Finish() {Gen.Print(Output);};
151 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
152
153 ContentsWriter(string const &DB, string const &Arch = string());
154 virtual ~ContentsWriter() {};
155 };
156
157 class SourcesWriter : public FTWScanner
158 {
159 Override BOver;
160 Override SOver;
161 char *Buffer;
162 unsigned long long BufSize;
163
164 public:
165
166 bool NoOverride;
167
168 // General options
169 string PathPrefix;
170 string DirStrip;
171 FILE *Output;
172 struct CacheDB::Stats Stats;
173
174 virtual bool DoPackage(string FileName);
175
176 SourcesWriter(string const &BOverrides,string const &SOverrides,
177 string const &ExtOverrides=string());
178 virtual ~SourcesWriter() {free(Buffer);};
179 };
180
181 class ReleaseWriter : public FTWScanner
182 {
183 public:
184 ReleaseWriter(string const &DB);
185 virtual bool DoPackage(string FileName);
186 void Finish();
187
188 FILE *Output;
189 // General options
190 string PathPrefix;
191 string DirStrip;
192
193 protected:
194 struct CheckSum
195 {
196 string MD5;
197 string SHA1;
198 string SHA256;
199 string SHA512;
200 // Limited by FileFd::Size()
201 unsigned long long size;
202 ~CheckSum() {};
203 };
204 map<string,struct CheckSum> CheckSums;
205 };
206
207 #endif