reorder includes: add <config.h> if needed and include it at first
[ntk/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:
3c54407f
DK
63 bool DoMD5;
64 bool DoSHA1;
65 bool DoSHA256;
9abccf4a 66 bool DoSHA512;
b2e465d6
AL
67
68 unsigned long DeLinkLimit;
69 string InternalPrefix;
70
71 virtual bool DoPackage(string FileName) = 0;
9209ec47
DK
72 bool RecursiveScan(string const &Dir);
73 bool LoadFileList(string const &BaseDir,string const &File);
af6fa0b8 74 void ClearPatterns() { Patterns.clear(); };
9209ec47 75 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
3cb3fe76
DK
76 void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
77 void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
9209ec47 78 bool SetExts(string const &Vals);
b2e465d6 79
31981076 80 FTWScanner(string const &Arch = string());
4c265635 81 virtual ~FTWScanner() {};
b2e465d6
AL
82};
83
66905344
DK
84class TranslationWriter
85{
34f1d96c 86 MultiCompress *Comp;
66905344
DK
87 FILE *Output;
88 std::set<string> Included;
89 unsigned short RefCounter;
90
91 public:
92 void IncreaseRefCounter() { ++RefCounter; };
93 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
94 unsigned short GetRefCounter() const { return RefCounter; };
95 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
96
34f1d96c
DK
97 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
98 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
66905344
DK
99 ~TranslationWriter();
100};
101
b2e465d6
AL
102class PackagesWriter : public FTWScanner
103{
104 Override Over;
105 CacheDB Db;
106
107 public:
108
109 // Some flags
ff574e76 110 bool DoAlwaysStat;
b2e465d6
AL
111 bool NoOverride;
112 bool DoContents;
9c24493f 113 bool LongDescription;
b2e465d6
AL
114
115 // General options
116 string PathPrefix;
117 string DirStrip;
118 FILE *Output;
119 struct CacheDB::Stats &Stats;
66905344 120 TranslationWriter *TransWriter;
0b41e0e7 121
9209ec47
DK
122 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
123 inline bool ReadExtraOverride(string const &File)
64177f17 124 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
125 virtual bool DoPackage(string FileName);
126
9209ec47
DK
127 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
128 string const &Arch=string());
b2e465d6
AL
129 virtual ~PackagesWriter() {};
130};
131
132class ContentsWriter : public FTWScanner
133{
134 CacheDB Db;
135
136 GenContents Gen;
137
138 public:
139
140 // General options
141 FILE *Output;
142 struct CacheDB::Stats &Stats;
143 string Prefix;
144
145 bool DoPackage(string FileName,string Package);
146 virtual bool DoPackage(string FileName)
147 {return DoPackage(FileName,string());};
9209ec47 148 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
b2e465d6
AL
149
150 void Finish() {Gen.Print(Output);};
9209ec47 151 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
b2e465d6 152
31981076 153 ContentsWriter(string const &DB, string const &Arch = string());
b2e465d6
AL
154 virtual ~ContentsWriter() {};
155};
156
157class SourcesWriter : public FTWScanner
158{
159 Override BOver;
160 Override SOver;
161 char *Buffer;
162 unsigned long BufSize;
163
164 public:
165
166 bool NoOverride;
167
168 // General options
169 string PathPrefix;
170 string DirStrip;
171 FILE *Output;
172 struct CacheDB::Stats Stats;
173
b2e465d6
AL
174 virtual bool DoPackage(string FileName);
175
9209ec47
DK
176 SourcesWriter(string const &BOverrides,string const &SOverrides,
177 string const &ExtOverrides=string());
b2e465d6
AL
178 virtual ~SourcesWriter() {free(Buffer);};
179};
180
98953965
AL
181class ReleaseWriter : public FTWScanner
182{
183public:
9209ec47 184 ReleaseWriter(string const &DB);
98953965 185 virtual bool DoPackage(string FileName);
f7291f62
AL
186 void Finish();
187
188 FILE *Output;
98953965
AL
189 // General options
190 string PathPrefix;
191 string DirStrip;
f7291f62
AL
192
193protected:
194 struct CheckSum
195 {
196 string MD5;
197 string SHA1;
cde41ae8 198 string SHA256;
9a961efc 199 string SHA512;
f7291f62
AL
200 // Limited by FileFd::Size()
201 unsigned long size;
0b41e0e7 202 ~CheckSum() {};
f7291f62
AL
203 };
204 map<string,struct CheckSum> CheckSums;
98953965 205};
b2e465d6
AL
206
207#endif