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