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
|
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: writer.h,v 1.6 2003/12/26 20:50:01 mdz Exp $
/* ######################################################################
Writer
The file writer classes. These write various types of output, sources,
packages and contents.
##################################################################### */
/*}}}*/
#ifndef WRITER_H
#define WRITER_H
#ifdef __GNUG__
#pragma interface "writer.h"
#endif
#include <string>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include "cachedb.h"
#include "override.h"
#include "apt-ftparchive.h"
using std::string;
using std::cout;
using std::endl;
using std::vector;
using std::map;
class FTWScanner
{
protected:
vector<string> Patterns;
const char *OriginalPath;
char *RealPath;
bool ErrorPrinted;
// Stuff for the delinker
bool NoLinkAct;
static FTWScanner *Owner;
static int Scanner(const char *File,const struct stat *sb,int Flag);
bool Delink(string &FileName,const char *OriginalPath,
unsigned long &Bytes,struct stat &St);
inline void NewLine(unsigned Priority)
{
if (ErrorPrinted == false && Quiet <= Priority)
{
cout << endl;
ErrorPrinted = true;
}
}
public:
unsigned long DeLinkLimit;
string InternalPrefix;
virtual bool DoPackage(string FileName) = 0;
bool RecursiveScan(string Dir);
bool LoadFileList(string BaseDir,string File);
bool ClearPatterns() { Patterns.clear(); };
bool AddPattern(string Pattern) { Patterns.push_back(Pattern); };
bool SetExts(string Vals);
FTWScanner();
virtual ~FTWScanner() {delete [] RealPath;};
};
class PackagesWriter : public FTWScanner
{
Override Over;
CacheDB Db;
public:
// Some flags
bool DoMD5;
bool NoOverride;
bool DoContents;
// General options
string PathPrefix;
string DirStrip;
FILE *Output;
struct CacheDB::Stats &Stats;
inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
inline bool ReadExtraOverride(string File)
{return Over.ReadExtraOverride(File);};
virtual bool DoPackage(string FileName);
PackagesWriter(string DB,string Overrides,string ExtOverrides=string());
virtual ~PackagesWriter() {};
};
class ContentsWriter : public FTWScanner
{
CacheDB Db;
GenContents Gen;
public:
// General options
FILE *Output;
struct CacheDB::Stats &Stats;
string Prefix;
bool DoPackage(string FileName,string Package);
virtual bool DoPackage(string FileName)
{return DoPackage(FileName,string());};
bool ReadFromPkgs(string PkgFile,string PkgCompress);
void Finish() {Gen.Print(Output);};
inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
ContentsWriter(string DB);
virtual ~ContentsWriter() {};
};
class SourcesWriter : public FTWScanner
{
Override BOver;
Override SOver;
char *Buffer;
unsigned long BufSize;
public:
bool NoOverride;
// General options
string PathPrefix;
string DirStrip;
FILE *Output;
struct CacheDB::Stats Stats;
virtual bool DoPackage(string FileName);
SourcesWriter(string BOverrides,string SOverrides,
string ExtOverrides=string());
virtual ~SourcesWriter() {free(Buffer);};
};
class ReleaseWriter : public FTWScanner
{
public:
ReleaseWriter(string DB);
virtual bool DoPackage(string FileName);
void Finish();
FILE *Output;
// General options
string PathPrefix;
string DirStrip;
protected:
struct CheckSum
{
string MD5;
string SHA1;
// Limited by FileFd::Size()
unsigned long size;
};
map<string,struct CheckSum> CheckSums;
};
#endif
|