]> git.saurik.com Git - apt.git/blob - ftparchive/writer.h
Release 1.4~beta1
[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 bool IncludeArchAll;
44 const char *OriginalPath;
45 bool ErrorPrinted;
46
47 // Stuff for the delinker
48 bool NoLinkAct;
49
50 static FTWScanner *Owner;
51 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
52 static int ScannerFile(const char *File, bool const &ReadLink);
53
54 bool Delink(string &FileName,const char *OriginalPath,
55 unsigned long long &Bytes,unsigned long long const &FileSize);
56
57 inline void NewLine(unsigned const &Priority)
58 {
59 if (ErrorPrinted == false && Quiet <= Priority)
60 {
61 c1out << endl;
62 ErrorPrinted = true;
63 }
64 }
65
66 public:
67 FileFd *Output;
68 bool OwnsOutput;
69 unsigned int DoHashes;
70
71 unsigned long DeLinkLimit;
72 string InternalPrefix;
73
74 virtual bool DoPackage(string FileName) = 0;
75 bool RecursiveScan(string const &Dir);
76 bool LoadFileList(string const &BaseDir,string const &File);
77 void ClearPatterns() { Patterns.clear(); };
78 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
79 void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
80 void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
81 bool SetExts(string const &Vals);
82
83 FTWScanner(FileFd * const Output, string const &Arch = string(), bool const IncludeArchAll = true);
84 virtual ~FTWScanner();
85 };
86
87 class MultiCompress;
88
89 class TranslationWriter
90 {
91 MultiCompress *Comp;
92 std::set<string> Included;
93 FileFd *Output;
94
95 public:
96 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
97
98 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
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 struct CacheDB::Stats &Stats;
119 TranslationWriter * const 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) APT_OVERRIDE;
125
126 PackagesWriter(FileFd * const Output, TranslationWriter * const TransWriter, string const &DB,
127 string const &Overrides,
128 string const &ExtOverrides = "",
129 string const &Arch = "",
130 bool const IncludeArchAll = true);
131 virtual ~PackagesWriter();
132 };
133
134 class ContentsWriter : public FTWScanner
135 {
136 CacheDB Db;
137
138 GenContents Gen;
139
140 public:
141
142 // General options
143 struct CacheDB::Stats &Stats;
144 string Prefix;
145
146 bool DoPackage(string FileName,string Package);
147 virtual bool DoPackage(string FileName) APT_OVERRIDE
148 {return DoPackage(FileName,string());};
149 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
150
151 void Finish() {Gen.Print(*Output);};
152 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
153
154 ContentsWriter(FileFd * const Output, string const &DB, string const &Arch = string(),
155 bool const IncludeArchAll = true);
156 virtual ~ContentsWriter() {};
157 };
158
159 class SourcesWriter : public FTWScanner
160 {
161 CacheDB Db;
162 Override BOver;
163 Override SOver;
164 char *Buffer;
165 unsigned long long BufSize;
166
167 public:
168
169 bool NoOverride;
170 bool DoAlwaysStat;
171
172 // General options
173 string PathPrefix;
174 string DirStrip;
175 struct CacheDB::Stats &Stats;
176
177 virtual bool DoPackage(string FileName) APT_OVERRIDE;
178
179 SourcesWriter(FileFd * const Output, string const &DB,string const &BOverrides,string const &SOverrides,
180 string const &ExtOverrides=string());
181 virtual ~SourcesWriter() {free(Buffer);};
182 };
183
184 class ReleaseWriter : public FTWScanner
185 {
186 public:
187 ReleaseWriter(FileFd * const Output, string const &DB);
188 virtual bool DoPackage(string FileName) APT_OVERRIDE;
189 void Finish();
190
191 // General options
192 string PathPrefix;
193 string DirStrip;
194
195 struct CheckSum
196 {
197 HashStringList Hashes;
198 // Limited by FileFd::Size()
199 unsigned long long size;
200 ~CheckSum() {};
201 };
202 protected:
203 map<string,struct CheckSum> CheckSums;
204 };
205
206 #endif