]> git.saurik.com Git - apt.git/blob - ftparchive/writer.h
* removed the pragma mess
[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 #ifdef __GNUG__
17 #endif
18
19 #include <string>
20 #include <stdio.h>
21 #include <iostream>
22 #include <vector>
23 #include <map>
24
25 #include "cachedb.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 const char *OriginalPath;
40 char *RealPath;
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 ReadLink);
49
50 bool Delink(string &FileName,const char *OriginalPath,
51 unsigned long &Bytes,off_t FileSize);
52
53 inline void NewLine(unsigned Priority)
54 {
55 if (ErrorPrinted == false && Quiet <= Priority)
56 {
57 cout << endl;
58 ErrorPrinted = true;
59 }
60 }
61
62 public:
63
64 unsigned long DeLinkLimit;
65 string InternalPrefix;
66
67 virtual bool DoPackage(string FileName) = 0;
68 bool RecursiveScan(string Dir);
69 bool LoadFileList(string BaseDir,string File);
70 void ClearPatterns() { Patterns.clear(); };
71 void AddPattern(string Pattern) { Patterns.push_back(Pattern); };
72 bool SetExts(string Vals);
73
74 FTWScanner();
75 virtual ~FTWScanner() {delete [] RealPath;};
76 };
77
78 class PackagesWriter : public FTWScanner
79 {
80 Override Over;
81 CacheDB Db;
82
83 public:
84
85 // Some flags
86 bool DoMD5;
87 bool DoSHA1;
88 bool DoSHA256;
89 bool NoOverride;
90 bool DoContents;
91
92 // General options
93 string PathPrefix;
94 string DirStrip;
95 FILE *Output;
96 struct CacheDB::Stats &Stats;
97 string Arch;
98
99 inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
100 inline bool ReadExtraOverride(string File)
101 {return Over.ReadExtraOverride(File);};
102 virtual bool DoPackage(string FileName);
103
104 PackagesWriter(string DB,string Overrides,string ExtOverrides=string(),
105 string Arch=string());
106 virtual ~PackagesWriter() {};
107 };
108
109 class ContentsWriter : public FTWScanner
110 {
111 CacheDB Db;
112
113 GenContents Gen;
114
115 public:
116
117 // General options
118 FILE *Output;
119 struct CacheDB::Stats &Stats;
120 string Prefix;
121
122 bool DoPackage(string FileName,string Package);
123 virtual bool DoPackage(string FileName)
124 {return DoPackage(FileName,string());};
125 bool ReadFromPkgs(string PkgFile,string PkgCompress);
126
127 void Finish() {Gen.Print(Output);};
128 inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
129
130 ContentsWriter(string DB);
131 virtual ~ContentsWriter() {};
132 };
133
134 class SourcesWriter : public FTWScanner
135 {
136 Override BOver;
137 Override SOver;
138 char *Buffer;
139 unsigned long BufSize;
140
141 public:
142
143 bool NoOverride;
144
145 // General options
146 string PathPrefix;
147 string DirStrip;
148 FILE *Output;
149 struct CacheDB::Stats Stats;
150
151 virtual bool DoPackage(string FileName);
152
153 SourcesWriter(string BOverrides,string SOverrides,
154 string ExtOverrides=string());
155 virtual ~SourcesWriter() {free(Buffer);};
156 };
157
158 class ReleaseWriter : public FTWScanner
159 {
160 public:
161 ReleaseWriter(string DB);
162 virtual bool DoPackage(string FileName);
163 void Finish();
164
165 FILE *Output;
166 // General options
167 string PathPrefix;
168 string DirStrip;
169
170 protected:
171 struct CheckSum
172 {
173 string MD5;
174 string SHA1;
175 string SHA256;
176 // Limited by FileFd::Size()
177 unsigned long size;
178 ~CheckSum() {};
179 };
180 map<string,struct CheckSum> CheckSums;
181 };
182
183 #endif