]> git.saurik.com Git - apt.git/blame - ftparchive/writer.h
Merge branch 'debian/experimental' into feature/srv-records
[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
a311fb96
DK
16#include <apt-pkg/hashes.h>
17
b2e465d6
AL
18#include <string>
19#include <stdio.h>
8c58f506 20#include <iostream>
64177f17 21#include <vector>
f7291f62 22#include <map>
66905344 23#include <set>
453b82a3
DK
24#include <stdlib.h>
25#include <sys/types.h>
b2e465d6 26
453b82a3 27#include "contents.h"
b2e465d6
AL
28#include "cachedb.h"
29#include "override.h"
30#include "apt-ftparchive.h"
8c58f506
AL
31
32using std::string;
33using std::cout;
34using std::endl;
98953965 35using std::vector;
f7291f62 36using std::map;
472ff00e 37
b2e465d6
AL
38class FTWScanner
39{
40 protected:
98953965 41 vector<string> Patterns;
31981076 42 string Arch;
b2e465d6 43 const char *OriginalPath;
b2e465d6 44 bool ErrorPrinted;
88593886 45
b2e465d6
AL
46 // Stuff for the delinker
47 bool NoLinkAct;
88593886 48
b2e465d6 49 static FTWScanner *Owner;
cde41ae8 50 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
9209ec47 51 static int ScannerFile(const char *File, bool const &ReadLink);
b2e465d6
AL
52
53 bool Delink(string &FileName,const char *OriginalPath,
650faab0 54 unsigned long long &Bytes,unsigned long long const &FileSize);
b2e465d6 55
9209ec47 56 inline void NewLine(unsigned const &Priority)
b2e465d6
AL
57 {
58 if (ErrorPrinted == false && Quiet <= Priority)
59 {
db40f8e0 60 c1out << endl;
b2e465d6 61 ErrorPrinted = true;
88593886 62 }
b2e465d6 63 }
88593886 64
b2e465d6 65 public:
88593886 66 FileFd *Output;
a311fb96 67 unsigned int DoHashes;
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);
88593886
DK
80
81 FTWScanner(FileFd * const Output, 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 std::set<string> Included;
91 unsigned short RefCounter;
88593886 92 FileFd *Output;
66905344
DK
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 100 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
88593886 101 TranslationWriter() : Comp(NULL), RefCounter(0) {};
66905344
DK
102 ~TranslationWriter();
103};
104
b2e465d6
AL
105class PackagesWriter : public FTWScanner
106{
107 Override Over;
108 CacheDB Db;
88593886 109
b2e465d6
AL
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;
b2e465d6 121 struct CacheDB::Stats &Stats;
66905344 122 TranslationWriter *TransWriter;
0b41e0e7 123
9209ec47
DK
124 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
125 inline bool ReadExtraOverride(string const &File)
64177f17 126 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
127 virtual bool DoPackage(string FileName);
128
88593886 129 PackagesWriter(FileFd * const Output, string const &DB,
21ea1dbb
MV
130 string const &Overrides,
131 string const &ExtOverrides = "",
132 string const &Arch = "");
b2e465d6
AL
133 virtual ~PackagesWriter() {};
134};
135
136class ContentsWriter : public FTWScanner
137{
138 CacheDB Db;
88593886 139
b2e465d6 140 GenContents Gen;
88593886 141
b2e465d6
AL
142 public:
143
144 // General options
b2e465d6
AL
145 struct CacheDB::Stats &Stats;
146 string Prefix;
88593886 147
b2e465d6
AL
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 152
88593886 153 void Finish() {Gen.Print(*Output);};
9209ec47 154 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
88593886
DK
155
156 ContentsWriter(FileFd * const Output, 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;
88593886 167
b2e465d6
AL
168 public:
169
170 bool NoOverride;
f6f06a8f 171 bool DoAlwaysStat;
88593886 172
b2e465d6
AL
173 // General options
174 string PathPrefix;
175 string DirStrip;
ce928105 176 struct CacheDB::Stats &Stats;
b2e465d6 177
b2e465d6
AL
178 virtual bool DoPackage(string FileName);
179
88593886 180 SourcesWriter(FileFd * const Output, string const &DB,string const &BOverrides,string const &SOverrides,
9209ec47 181 string const &ExtOverrides=string());
b2e465d6
AL
182 virtual ~SourcesWriter() {free(Buffer);};
183};
184
98953965
AL
185class ReleaseWriter : public FTWScanner
186{
187public:
88593886 188 ReleaseWriter(FileFd * const Output, string const &DB);
98953965 189 virtual bool DoPackage(string FileName);
f7291f62
AL
190 void Finish();
191
98953965
AL
192 // General options
193 string PathPrefix;
194 string DirStrip;
f7291f62 195
f7291f62
AL
196 struct CheckSum
197 {
a311fb96 198 HashStringList Hashes;
f7291f62 199 // Limited by FileFd::Size()
650faab0 200 unsigned long long size;
0b41e0e7 201 ~CheckSum() {};
f7291f62 202 };
a311fb96 203protected:
f7291f62 204 map<string,struct CheckSum> CheckSums;
98953965 205};
b2e465d6
AL
206
207#endif