]> git.saurik.com Git - apt.git/blame - ftparchive/writer.h
* methods/gzip.cc:
[apt.git] / ftparchive / writer.h
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b3d44315 3// $Id: writer.h,v 1.4.2.2 2003/12/26 22:55:43 mdz Exp $
b2e465d6
AL
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>
8c58f506 22#include <iostream>
64177f17 23#include <vector>
f7291f62 24#include <map>
b2e465d6
AL
25
26#include "cachedb.h"
27#include "override.h"
28#include "apt-ftparchive.h"
8c58f506
AL
29
30using std::string;
31using std::cout;
32using std::endl;
98953965 33using std::vector;
f7291f62 34using std::map;
b2e465d6
AL
35
36class FTWScanner
37{
38 protected:
98953965 39 vector<string> Patterns;
b2e465d6
AL
40 const char *OriginalPath;
41 char *RealPath;
42 bool ErrorPrinted;
43
44 // Stuff for the delinker
45 bool NoLinkAct;
46
47 static FTWScanner *Owner;
cde41ae8
MV
48 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
49 static int ScannerFile(const char *File, bool ReadLink);
b2e465d6
AL
50
51 bool Delink(string &FileName,const char *OriginalPath,
cde41ae8 52 unsigned long &Bytes,off_t FileSize);
b2e465d6
AL
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);
af6fa0b8
AL
71 void ClearPatterns() { Patterns.clear(); };
72 void AddPattern(string Pattern) { Patterns.push_back(Pattern); };
b2e465d6
AL
73 bool SetExts(string Vals);
74
75 FTWScanner();
98953965 76 virtual ~FTWScanner() {delete [] RealPath;};
b2e465d6
AL
77};
78
79class PackagesWriter : public FTWScanner
80{
81 Override Over;
82 CacheDB Db;
83
84 public:
85
86 // Some flags
87 bool DoMD5;
cde41ae8
MV
88 bool DoSHA1;
89 bool DoSHA256;
b2e465d6
AL
90 bool NoOverride;
91 bool DoContents;
92
93 // General options
94 string PathPrefix;
95 string DirStrip;
96 FILE *Output;
97 struct CacheDB::Stats &Stats;
0b41e0e7
MV
98 string Arch;
99
b2e465d6 100 inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
64177f17
AL
101 inline bool ReadExtraOverride(string File)
102 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
103 virtual bool DoPackage(string FileName);
104
0b41e0e7
MV
105 PackagesWriter(string DB,string Overrides,string ExtOverrides=string(),
106 string Arch=string());
b2e465d6
AL
107 virtual ~PackagesWriter() {};
108};
109
110class 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
135class 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
b2e465d6
AL
152 virtual bool DoPackage(string FileName);
153
64177f17
AL
154 SourcesWriter(string BOverrides,string SOverrides,
155 string ExtOverrides=string());
b2e465d6
AL
156 virtual ~SourcesWriter() {free(Buffer);};
157};
158
98953965
AL
159class ReleaseWriter : public FTWScanner
160{
161public:
162 ReleaseWriter(string DB);
163 virtual bool DoPackage(string FileName);
f7291f62
AL
164 void Finish();
165
166 FILE *Output;
98953965
AL
167 // General options
168 string PathPrefix;
169 string DirStrip;
f7291f62
AL
170
171protected:
172 struct CheckSum
173 {
174 string MD5;
175 string SHA1;
cde41ae8 176 string SHA256;
f7291f62
AL
177 // Limited by FileFd::Size()
178 unsigned long size;
0b41e0e7 179 ~CheckSum() {};
f7291f62
AL
180 };
181 map<string,struct CheckSum> CheckSums;
98953965 182};
b2e465d6
AL
183
184#endif