writer.h 5.0 KB

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