writer.h 3.9 KB

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