writer.h 3.8 KB

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