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