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.
 
 
 
 
 
 

204 lines
4.7 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. bool SetExts(string const &Vals);
  58. FTWScanner(string const &Arch = string());
  59. virtual ~FTWScanner() {};
  60. };
  61. class TranslationWriter
  62. {
  63. MultiCompress *Comp;
  64. FILE *Output;
  65. std::set<string> Included;
  66. unsigned short RefCounter;
  67. public:
  68. void IncreaseRefCounter() { ++RefCounter; };
  69. unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
  70. unsigned short GetRefCounter() const { return RefCounter; };
  71. bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
  72. TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
  73. TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
  74. ~TranslationWriter();
  75. };
  76. class PackagesWriter : public FTWScanner
  77. {
  78. Override Over;
  79. CacheDB Db;
  80. public:
  81. // Some flags
  82. bool DoMD5;
  83. bool DoSHA1;
  84. bool DoSHA256;
  85. bool DoAlwaysStat;
  86. bool NoOverride;
  87. bool DoContents;
  88. bool LongDescription;
  89. // General options
  90. string PathPrefix;
  91. string DirStrip;
  92. FILE *Output;
  93. struct CacheDB::Stats &Stats;
  94. TranslationWriter *TransWriter;
  95. inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
  96. inline bool ReadExtraOverride(string const &File)
  97. {return Over.ReadExtraOverride(File);};
  98. virtual bool DoPackage(string FileName);
  99. PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
  100. string const &Arch=string());
  101. virtual ~PackagesWriter() {};
  102. };
  103. class ContentsWriter : public FTWScanner
  104. {
  105. CacheDB Db;
  106. GenContents Gen;
  107. public:
  108. // General options
  109. FILE *Output;
  110. struct CacheDB::Stats &Stats;
  111. string Prefix;
  112. bool DoPackage(string FileName,string Package);
  113. virtual bool DoPackage(string FileName)
  114. {return DoPackage(FileName,string());};
  115. bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
  116. void Finish() {Gen.Print(Output);};
  117. inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
  118. ContentsWriter(string const &DB, string const &Arch = string());
  119. virtual ~ContentsWriter() {};
  120. };
  121. class SourcesWriter : public FTWScanner
  122. {
  123. Override BOver;
  124. Override SOver;
  125. char *Buffer;
  126. unsigned long BufSize;
  127. public:
  128. bool NoOverride;
  129. // General options
  130. string PathPrefix;
  131. string DirStrip;
  132. FILE *Output;
  133. struct CacheDB::Stats Stats;
  134. virtual bool DoPackage(string FileName);
  135. SourcesWriter(string const &BOverrides,string const &SOverrides,
  136. string const &ExtOverrides=string());
  137. virtual ~SourcesWriter() {free(Buffer);};
  138. };
  139. class ReleaseWriter : public FTWScanner
  140. {
  141. public:
  142. ReleaseWriter(string const &DB);
  143. virtual bool DoPackage(string FileName);
  144. void Finish();
  145. FILE *Output;
  146. // General options
  147. string PathPrefix;
  148. string DirStrip;
  149. protected:
  150. struct CheckSum
  151. {
  152. string MD5;
  153. string SHA1;
  154. string SHA256;
  155. // Limited by FileFd::Size()
  156. unsigned long size;
  157. ~CheckSum() {};
  158. };
  159. map<string,struct CheckSum> CheckSums;
  160. };
  161. #endif