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