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