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