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