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