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.
 
 
 
 
 
 

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