]> git.saurik.com Git - apt.git/blame - ftparchive/writer.h
apt-pkg/cdrom.h: move new member to the end to minimize ABI risk
[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
b2e465d6
AL
16
17#include <string>
18#include <stdio.h>
8c58f506 19#include <iostream>
64177f17 20#include <vector>
f7291f62 21#include <map>
66905344 22#include <set>
b2e465d6
AL
23
24#include "cachedb.h"
34f1d96c 25#include "multicompress.h"
b2e465d6
AL
26#include "override.h"
27#include "apt-ftparchive.h"
8c58f506
AL
28
29using std::string;
30using std::cout;
31using std::endl;
98953965 32using std::vector;
f7291f62 33using std::map;
b2e465d6
AL
34
35class FTWScanner
36{
37 protected:
98953965 38 vector<string> Patterns;
31981076 39 string Arch;
b2e465d6 40 const char *OriginalPath;
b2e465d6
AL
41 bool ErrorPrinted;
42
43 // Stuff for the delinker
44 bool NoLinkAct;
45
46 static FTWScanner *Owner;
cde41ae8 47 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
9209ec47 48 static int ScannerFile(const char *File, bool const &ReadLink);
b2e465d6
AL
49
50 bool Delink(string &FileName,const char *OriginalPath,
9209ec47 51 unsigned long &Bytes,off_t const &FileSize);
b2e465d6 52
9209ec47 53 inline void NewLine(unsigned const &Priority)
b2e465d6
AL
54 {
55 if (ErrorPrinted == false && Quiet <= Priority)
56 {
db40f8e0 57 c1out << endl;
b2e465d6
AL
58 ErrorPrinted = true;
59 }
60 }
61
62 public:
63
64 unsigned long DeLinkLimit;
65 string InternalPrefix;
66
67 virtual bool DoPackage(string FileName) = 0;
9209ec47
DK
68 bool RecursiveScan(string const &Dir);
69 bool LoadFileList(string const &BaseDir,string const &File);
af6fa0b8 70 void ClearPatterns() { Patterns.clear(); };
9209ec47 71 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
3cb3fe76
DK
72 void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
73 void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
9209ec47 74 bool SetExts(string const &Vals);
b2e465d6 75
31981076 76 FTWScanner(string const &Arch = string());
4c265635 77 virtual ~FTWScanner() {};
b2e465d6
AL
78};
79
66905344
DK
80class TranslationWriter
81{
34f1d96c 82 MultiCompress *Comp;
66905344
DK
83 FILE *Output;
84 std::set<string> Included;
85 unsigned short RefCounter;
86
87 public:
88 void IncreaseRefCounter() { ++RefCounter; };
89 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
90 unsigned short GetRefCounter() const { return RefCounter; };
91 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
92
34f1d96c
DK
93 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
94 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
66905344
DK
95 ~TranslationWriter();
96};
97
b2e465d6
AL
98class PackagesWriter : public FTWScanner
99{
100 Override Over;
101 CacheDB Db;
102
103 public:
104
105 // Some flags
106 bool DoMD5;
cde41ae8
MV
107 bool DoSHA1;
108 bool DoSHA256;
ff574e76 109 bool DoAlwaysStat;
b2e465d6
AL
110 bool NoOverride;
111 bool DoContents;
9c24493f 112 bool LongDescription;
b2e465d6
AL
113
114 // General options
115 string PathPrefix;
116 string DirStrip;
117 FILE *Output;
118 struct CacheDB::Stats &Stats;
66905344 119 TranslationWriter *TransWriter;
0b41e0e7 120
9209ec47
DK
121 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
122 inline bool ReadExtraOverride(string const &File)
64177f17 123 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
124 virtual bool DoPackage(string FileName);
125
9209ec47
DK
126 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
127 string const &Arch=string());
b2e465d6
AL
128 virtual ~PackagesWriter() {};
129};
130
131class ContentsWriter : public FTWScanner
132{
133 CacheDB Db;
134
135 GenContents Gen;
136
137 public:
138
139 // General options
140 FILE *Output;
141 struct CacheDB::Stats &Stats;
142 string Prefix;
143
144 bool DoPackage(string FileName,string Package);
145 virtual bool DoPackage(string FileName)
146 {return DoPackage(FileName,string());};
9209ec47 147 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
b2e465d6
AL
148
149 void Finish() {Gen.Print(Output);};
9209ec47 150 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
b2e465d6 151
31981076 152 ContentsWriter(string const &DB, string const &Arch = string());
b2e465d6
AL
153 virtual ~ContentsWriter() {};
154};
155
156class SourcesWriter : public FTWScanner
157{
158 Override BOver;
159 Override SOver;
160 char *Buffer;
161 unsigned long BufSize;
162
163 public:
164
165 bool NoOverride;
166
167 // General options
168 string PathPrefix;
169 string DirStrip;
170 FILE *Output;
171 struct CacheDB::Stats Stats;
172
b2e465d6
AL
173 virtual bool DoPackage(string FileName);
174
9209ec47
DK
175 SourcesWriter(string const &BOverrides,string const &SOverrides,
176 string const &ExtOverrides=string());
b2e465d6
AL
177 virtual ~SourcesWriter() {free(Buffer);};
178};
179
98953965
AL
180class ReleaseWriter : public FTWScanner
181{
182public:
9209ec47 183 ReleaseWriter(string const &DB);
98953965 184 virtual bool DoPackage(string FileName);
f7291f62
AL
185 void Finish();
186
187 FILE *Output;
98953965
AL
188 // General options
189 string PathPrefix;
190 string DirStrip;
f7291f62
AL
191
192protected:
193 struct CheckSum
194 {
195 string MD5;
196 string SHA1;
cde41ae8 197 string SHA256;
f7291f62
AL
198 // Limited by FileFd::Size()
199 unsigned long size;
0b41e0e7 200 ~CheckSum() {};
f7291f62
AL
201 };
202 map<string,struct CheckSum> CheckSums;
98953965 203};
b2e465d6
AL
204
205#endif