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