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