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