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