writer.h 3.9 KB

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