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