summaryrefslogtreecommitdiff
path: root/ftparchive/writer.h
blob: 86884dcfc40768cd71a218a55bf2c1e2a3a6945e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: writer.h,v 1.4.2.2 2003/12/26 22:55:43 mdz Exp $
/* ######################################################################

   Writer 
   
   The file writer classes. These write various types of output, sources,
   packages and contents.
   
   ##################################################################### */
									/*}}}*/
#ifndef WRITER_H
#define WRITER_H

#include <string>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <sys/types.h>

#include "contents.h"
#include "cachedb.h"
#include "override.h"
#include "apt-ftparchive.h"

using std::string;
using std::cout;
using std::endl;
using std::vector;
using std::map;

class FTWScanner
{
   protected:
   vector<string> Patterns;
   string Arch;
   const char *OriginalPath;
   bool ErrorPrinted;
   
   // Stuff for the delinker
   bool NoLinkAct;
   
   static FTWScanner *Owner;
   static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
   static int ScannerFile(const char *File, bool const &ReadLink);

   bool Delink(string &FileName,const char *OriginalPath,
	       unsigned long long &Bytes,unsigned long long const &FileSize);

   inline void NewLine(unsigned const &Priority)
   {
      if (ErrorPrinted == false && Quiet <= Priority)
      {
	 c1out << endl;
	 ErrorPrinted = true;
      }	 
   }
   
   public:
   bool DoMD5;
   bool DoSHA1;
   bool DoSHA256;
   bool DoSHA512;

   unsigned long DeLinkLimit;
   string InternalPrefix;

   virtual bool DoPackage(string FileName) = 0;
   bool RecursiveScan(string const &Dir);
   bool LoadFileList(string const &BaseDir,string const &File);
   void ClearPatterns() { Patterns.clear(); };
   void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
   void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
   void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
   bool SetExts(string const &Vals);
      
   FTWScanner(string const &Arch = string());
   virtual ~FTWScanner() {};
};

class MultiCompress;

class TranslationWriter
{
   MultiCompress *Comp;
   FILE *Output;
   std::set<string> Included;
   unsigned short RefCounter;

   public:
   void IncreaseRefCounter() { ++RefCounter; };
   unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
   unsigned short GetRefCounter() const { return RefCounter; };
   bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);

   TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
   TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
   ~TranslationWriter();
};

class PackagesWriter : public FTWScanner
{
   Override Over;
   CacheDB Db;
      
   public:

   // Some flags
   bool DoAlwaysStat;
   bool NoOverride;
   bool DoContents;
   bool LongDescription;

   // General options
   string PathPrefix;
   string DirStrip;
   FILE *Output;
   struct CacheDB::Stats &Stats;
   TranslationWriter *TransWriter;

   inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
   inline bool ReadExtraOverride(string const &File) 
      {return Over.ReadExtraOverride(File);};
   virtual bool DoPackage(string FileName);

   PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
		  string const &Arch=string());
   virtual ~PackagesWriter() {};
};

class ContentsWriter : public FTWScanner
{
   CacheDB Db;
   
   GenContents Gen;
   
   public:

   // General options
   FILE *Output;
   struct CacheDB::Stats &Stats;
   string Prefix;
   
   bool DoPackage(string FileName,string Package);
   virtual bool DoPackage(string FileName) 
             {return DoPackage(FileName,string());};
   bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);

   void Finish() {Gen.Print(Output);};
   inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
   
   ContentsWriter(string const &DB, string const &Arch = string());
   virtual ~ContentsWriter() {};
};

class SourcesWriter : public FTWScanner
{
   CacheDB Db;
   Override BOver;
   Override SOver;
   char *Buffer;
   unsigned long long BufSize;
   
   public:

   bool NoOverride;
   bool DoAlwaysStat;
   
   // General options
   string PathPrefix;
   string DirStrip;
   FILE *Output;
   struct CacheDB::Stats Stats;

   virtual bool DoPackage(string FileName);

   SourcesWriter(string const &DB,string const &BOverrides,string const &SOverrides,
		 string const &ExtOverrides=string());
   virtual ~SourcesWriter() {free(Buffer);};
};

class ReleaseWriter : public FTWScanner
{
public:
   ReleaseWriter(string const &DB);
   virtual bool DoPackage(string FileName);
   void Finish();

   FILE *Output;
   // General options
   string PathPrefix;
   string DirStrip;

protected:
   struct CheckSum
   {
      string MD5;
      string SHA1;
      string SHA256;
      string SHA512;
      // Limited by FileFd::Size()
      unsigned long long size;
      ~CheckSum() {};
   };
   map<string,struct CheckSum> CheckSums;
};

#endif