]> git.saurik.com Git - apt.git/blame - ftparchive/writer.h
merge debian/sid into debian/experimental
[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
AL
44 bool ErrorPrinted;
45
46 // Stuff for the delinker
47 bool NoLinkAct;
48
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
AL
61 ErrorPrinted = true;
62 }
63 }
64
65 public:
a311fb96 66 unsigned int DoHashes;
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
472ff00e
DK
84class MultiCompress;
85
66905344
DK
86class TranslationWriter
87{
34f1d96c 88 MultiCompress *Comp;
66905344
DK
89 FILE *Output;
90 std::set<string> Included;
91 unsigned short RefCounter;
92
93 public:
94 void IncreaseRefCounter() { ++RefCounter; };
95 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
96 unsigned short GetRefCounter() const { return RefCounter; };
97 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
98
34f1d96c
DK
99 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
100 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
66905344
DK
101 ~TranslationWriter();
102};
103
b2e465d6
AL
104class PackagesWriter : public FTWScanner
105{
106 Override Over;
107 CacheDB Db;
108
109 public:
110
111 // Some flags
ff574e76 112 bool DoAlwaysStat;
b2e465d6
AL
113 bool NoOverride;
114 bool DoContents;
9c24493f 115 bool LongDescription;
b2e465d6
AL
116
117 // General options
118 string PathPrefix;
119 string DirStrip;
120 FILE *Output;
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
21ea1dbb
MV
129 PackagesWriter(string const &DB,
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;
139
140 GenContents Gen;
141
142 public:
143
144 // General options
145 FILE *Output;
146 struct CacheDB::Stats &Stats;
147 string Prefix;
148
149 bool DoPackage(string FileName,string Package);
150 virtual bool DoPackage(string FileName)
151 {return DoPackage(FileName,string());};
9209ec47 152 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
b2e465d6
AL
153
154 void Finish() {Gen.Print(Output);};
9209ec47 155 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
b2e465d6 156
31981076 157 ContentsWriter(string const &DB, string const &Arch = string());
b2e465d6
AL
158 virtual ~ContentsWriter() {};
159};
160
161class SourcesWriter : public FTWScanner
162{
f6f06a8f 163 CacheDB Db;
b2e465d6
AL
164 Override BOver;
165 Override SOver;
166 char *Buffer;
650faab0 167 unsigned long long BufSize;
b2e465d6
AL
168
169 public:
170
171 bool NoOverride;
f6f06a8f 172 bool DoAlwaysStat;
b2e465d6
AL
173
174 // General options
175 string PathPrefix;
176 string DirStrip;
177 FILE *Output;
ce928105 178 struct CacheDB::Stats &Stats;
b2e465d6 179
b2e465d6
AL
180 virtual bool DoPackage(string FileName);
181
f6f06a8f 182 SourcesWriter(string const &DB,string const &BOverrides,string const &SOverrides,
9209ec47 183 string const &ExtOverrides=string());
b2e465d6
AL
184 virtual ~SourcesWriter() {free(Buffer);};
185};
186
98953965
AL
187class ReleaseWriter : public FTWScanner
188{
189public:
9209ec47 190 ReleaseWriter(string const &DB);
98953965 191 virtual bool DoPackage(string FileName);
f7291f62
AL
192 void Finish();
193
194 FILE *Output;
98953965
AL
195 // General options
196 string PathPrefix;
197 string DirStrip;
f7291f62 198
f7291f62
AL
199 struct CheckSum
200 {
a311fb96 201 HashStringList Hashes;
f7291f62 202 // Limited by FileFd::Size()
650faab0 203 unsigned long long size;
0b41e0e7 204 ~CheckSum() {};
f7291f62 205 };
a311fb96 206protected:
f7291f62 207 map<string,struct CheckSum> CheckSums;
98953965 208};
b2e465d6
AL
209
210#endif