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