]> git.saurik.com Git - apt.git/blame_incremental - ftparchive/writer.h
add apt-vendor information for tanglu
[apt.git] / ftparchive / writer.h
... / ...
CommitLineData
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 "override.h"
26#include "apt-ftparchive.h"
27
28using std::string;
29using std::cout;
30using std::endl;
31using std::vector;
32using std::map;
33
34class FTWScanner
35{
36 protected:
37 vector<string> Patterns;
38 string Arch;
39 const char *OriginalPath;
40 bool ErrorPrinted;
41
42 // Stuff for the delinker
43 bool NoLinkAct;
44
45 static FTWScanner *Owner;
46 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
47 static int ScannerFile(const char *File, bool const &ReadLink);
48
49 bool Delink(string &FileName,const char *OriginalPath,
50 unsigned long long &Bytes,unsigned long long const &FileSize);
51
52 inline void NewLine(unsigned const &Priority)
53 {
54 if (ErrorPrinted == false && Quiet <= Priority)
55 {
56 c1out << endl;
57 ErrorPrinted = true;
58 }
59 }
60
61 public:
62 bool DoMD5;
63 bool DoSHA1;
64 bool DoSHA256;
65 bool DoSHA512;
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
83class MultiCompress;
84
85class TranslationWriter
86{
87 MultiCompress *Comp;
88 FILE *Output;
89 std::set<string> Included;
90 unsigned short RefCounter;
91
92 public:
93 void IncreaseRefCounter() { ++RefCounter; };
94 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
95 unsigned short GetRefCounter() const { return RefCounter; };
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() : Comp(NULL), Output(NULL), RefCounter(0) {};
100 ~TranslationWriter();
101};
102
103class PackagesWriter : public FTWScanner
104{
105 Override Over;
106 CacheDB Db;
107
108 public:
109
110 // Some flags
111 bool DoAlwaysStat;
112 bool NoOverride;
113 bool DoContents;
114 bool LongDescription;
115
116 // General options
117 string PathPrefix;
118 string DirStrip;
119 FILE *Output;
120 struct CacheDB::Stats &Stats;
121 TranslationWriter *TransWriter;
122
123 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
124 inline bool ReadExtraOverride(string const &File)
125 {return Over.ReadExtraOverride(File);};
126 virtual bool DoPackage(string FileName);
127
128 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
129 string const &Arch=string());
130 virtual ~PackagesWriter() {};
131};
132
133class ContentsWriter : public FTWScanner
134{
135 CacheDB Db;
136
137 GenContents Gen;
138
139 public:
140
141 // General options
142 FILE *Output;
143 struct CacheDB::Stats &Stats;
144 string Prefix;
145
146 bool DoPackage(string FileName,string Package);
147 virtual bool DoPackage(string FileName)
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(string const &DB, string const &Arch = string());
155 virtual ~ContentsWriter() {};
156};
157
158class SourcesWriter : public FTWScanner
159{
160 CacheDB Db;
161 Override BOver;
162 Override SOver;
163 char *Buffer;
164 unsigned long long BufSize;
165
166 public:
167
168 bool NoOverride;
169 bool DoAlwaysStat;
170
171 // General options
172 string PathPrefix;
173 string DirStrip;
174 FILE *Output;
175 struct CacheDB::Stats Stats;
176
177 virtual bool DoPackage(string FileName);
178
179 SourcesWriter(string const &DB,string const &BOverrides,string const &SOverrides,
180 string const &ExtOverrides=string());
181 virtual ~SourcesWriter() {free(Buffer);};
182};
183
184class ReleaseWriter : public FTWScanner
185{
186public:
187 ReleaseWriter(string const &DB);
188 virtual bool DoPackage(string FileName);
189 void Finish();
190
191 FILE *Output;
192 // General options
193 string PathPrefix;
194 string DirStrip;
195
196protected:
197 struct CheckSum
198 {
199 string MD5;
200 string SHA1;
201 string SHA256;
202 string SHA512;
203 // Limited by FileFd::Size()
204 unsigned long long size;
205 ~CheckSum() {};
206 };
207 map<string,struct CheckSum> CheckSums;
208};
209
210#endif