You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

215 lines
5.1 KiB

  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. Writer
  6. The file writer classes. These write various types of output, sources,
  7. packages and contents.
  8. ##################################################################### */
  9. /*}}}*/
  10. #ifndef WRITER_H
  11. #define WRITER_H
  12. #include <string>
  13. #include <stdio.h>
  14. #include <iostream>
  15. #include <vector>
  16. #include <map>
  17. #include <set>
  18. #include <stdlib.h>
  19. #include <sys/types.h>
  20. #include "contents.h"
  21. #include "cachedb.h"
  22. #include "override.h"
  23. #include "apt-ftparchive.h"
  24. using std::string;
  25. using std::cout;
  26. using std::endl;
  27. using std::vector;
  28. using std::map;
  29. class FTWScanner
  30. {
  31. protected:
  32. vector<string> Patterns;
  33. string Arch;
  34. const char *OriginalPath;
  35. bool ErrorPrinted;
  36. // Stuff for the delinker
  37. bool NoLinkAct;
  38. static FTWScanner *Owner;
  39. static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
  40. static int ScannerFile(const char *File, bool const &ReadLink);
  41. bool Delink(string &FileName,const char *OriginalPath,
  42. unsigned long long &Bytes,unsigned long long const &FileSize);
  43. inline void NewLine(unsigned const &Priority)
  44. {
  45. if (ErrorPrinted == false && Quiet <= Priority)
  46. {
  47. c1out << endl;
  48. ErrorPrinted = true;
  49. }
  50. }
  51. public:
  52. bool DoMD5;
  53. bool DoSHA1;
  54. bool DoSHA256;
  55. bool DoSHA512;
  56. unsigned long DeLinkLimit;
  57. string InternalPrefix;
  58. virtual bool DoPackage(string FileName) = 0;
  59. bool RecursiveScan(string const &Dir);
  60. bool LoadFileList(string const &BaseDir,string const &File);
  61. void ClearPatterns() { Patterns.clear(); };
  62. void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
  63. void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
  64. void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
  65. bool SetExts(string const &Vals);
  66. FTWScanner(string const &Arch = string());
  67. virtual ~FTWScanner() {};
  68. };
  69. class MultiCompress;
  70. class TranslationWriter
  71. {
  72. MultiCompress *Comp;
  73. FILE *Output;
  74. std::set<string> Included;
  75. unsigned short RefCounter;
  76. public:
  77. void IncreaseRefCounter() { ++RefCounter; };
  78. unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
  79. unsigned short GetRefCounter() const { return RefCounter; };
  80. bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
  81. TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
  82. TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
  83. ~TranslationWriter();
  84. };
  85. class PackagesWriter : public FTWScanner
  86. {
  87. Override Over;
  88. CacheDB Db;
  89. public:
  90. // Some flags
  91. bool DoAlwaysStat;
  92. bool NoOverride;
  93. bool DoContents;
  94. bool LongDescription;
  95. // General options
  96. string PathPrefix;
  97. string DirStrip;
  98. FILE *Output;
  99. struct CacheDB::Stats &Stats;
  100. TranslationWriter *TransWriter;
  101. inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
  102. inline bool ReadExtraOverride(string const &File)
  103. {return Over.ReadExtraOverride(File);};
  104. virtual bool DoPackage(string FileName);
  105. PackagesWriter(string const &DB,
  106. string const &Overrides,
  107. string const &ExtOverrides = "",
  108. string const &Arch = "");
  109. virtual ~PackagesWriter() {};
  110. };
  111. class ContentsWriter : public FTWScanner
  112. {
  113. CacheDB Db;
  114. GenContents Gen;
  115. public:
  116. // General options
  117. FILE *Output;
  118. struct CacheDB::Stats &Stats;
  119. string Prefix;
  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. void Finish() {Gen.Print(Output);};
  125. inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
  126. ContentsWriter(string const &DB, string const &Arch = string());
  127. virtual ~ContentsWriter() {};
  128. };
  129. class SourcesWriter : public FTWScanner
  130. {
  131. CacheDB Db;
  132. Override BOver;
  133. Override SOver;
  134. char *Buffer;
  135. unsigned long long BufSize;
  136. public:
  137. bool NoOverride;
  138. bool DoAlwaysStat;
  139. // General options
  140. string PathPrefix;
  141. string DirStrip;
  142. FILE *Output;
  143. struct CacheDB::Stats &Stats;
  144. virtual bool DoPackage(string FileName);
  145. SourcesWriter(string const &DB,string const &BOverrides,string const &SOverrides,
  146. string const &ExtOverrides=string());
  147. virtual ~SourcesWriter() {free(Buffer);};
  148. };
  149. class ReleaseWriter : public FTWScanner
  150. {
  151. public:
  152. ReleaseWriter(string const &DB);
  153. virtual bool DoPackage(string FileName);
  154. void Finish();
  155. FILE *Output;
  156. // General options
  157. string PathPrefix;
  158. string DirStrip;
  159. protected:
  160. struct CheckSum
  161. {
  162. string MD5;
  163. string SHA1;
  164. string SHA256;
  165. string SHA512;
  166. // Limited by FileFd::Size()
  167. unsigned long long size;
  168. ~CheckSum() {};
  169. };
  170. map<string,struct CheckSum> CheckSums;
  171. };
  172. #endif