writer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. // General options
  71. string PathPrefix;
  72. string DirStrip;
  73. FILE *Output;
  74. struct CacheDB::Stats &Stats;
  75. string Arch;
  76. inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
  77. inline bool ReadExtraOverride(string File)
  78. {return Over.ReadExtraOverride(File);};
  79. virtual bool DoPackage(string FileName);
  80. PackagesWriter(string DB,string Overrides,string ExtOverrides=string(),
  81. string Arch=string());
  82. virtual ~PackagesWriter() {};
  83. };
  84. class ContentsWriter : public FTWScanner
  85. {
  86. CacheDB Db;
  87. GenContents Gen;
  88. public:
  89. // General options
  90. FILE *Output;
  91. struct CacheDB::Stats &Stats;
  92. string Prefix;
  93. bool DoPackage(string FileName,string Package);
  94. virtual bool DoPackage(string FileName)
  95. {return DoPackage(FileName,string());};
  96. bool ReadFromPkgs(string PkgFile,string PkgCompress);
  97. void Finish() {Gen.Print(Output);};
  98. inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
  99. ContentsWriter(string DB);
  100. virtual ~ContentsWriter() {};
  101. };
  102. class SourcesWriter : public FTWScanner
  103. {
  104. Override BOver;
  105. Override SOver;
  106. char *Buffer;
  107. unsigned long BufSize;
  108. public:
  109. bool NoOverride;
  110. // General options
  111. string PathPrefix;
  112. string DirStrip;
  113. FILE *Output;
  114. struct CacheDB::Stats Stats;
  115. virtual bool DoPackage(string FileName);
  116. SourcesWriter(string BOverrides,string SOverrides,
  117. string ExtOverrides=string());
  118. virtual ~SourcesWriter() {free(Buffer);};
  119. };
  120. class ReleaseWriter : public FTWScanner
  121. {
  122. public:
  123. ReleaseWriter(string DB);
  124. virtual bool DoPackage(string FileName);
  125. void Finish();
  126. FILE *Output;
  127. // General options
  128. string PathPrefix;
  129. string DirStrip;
  130. protected:
  131. struct CheckSum
  132. {
  133. string MD5;
  134. string SHA1;
  135. string SHA256;
  136. // Limited by FileFd::Size()
  137. unsigned long size;
  138. ~CheckSum() {};
  139. };
  140. map<string,struct CheckSum> CheckSums;
  141. };
  142. #endif