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. #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 Scanner(const char *File,const struct stat *sb,int Flag);
  39. bool Delink(string &FileName,const char *OriginalPath,
  40. unsigned long &Bytes,struct stat &St);
  41. inline void NewLine(unsigned Priority)
  42. {
  43. if (ErrorPrinted == false && Quiet <= Priority)
  44. {
  45. cout << endl;
  46. ErrorPrinted = true;
  47. }
  48. }
  49. public:
  50. unsigned long DeLinkLimit;
  51. string InternalPrefix;
  52. virtual bool DoPackage(string FileName) = 0;
  53. bool RecursiveScan(string Dir);
  54. bool LoadFileList(string BaseDir,string File);
  55. void ClearPatterns() { Patterns.clear(); };
  56. void AddPattern(string Pattern) { Patterns.push_back(Pattern); };
  57. bool SetExts(string Vals);
  58. FTWScanner();
  59. virtual ~FTWScanner() {delete [] RealPath;};
  60. };
  61. class PackagesWriter : public FTWScanner
  62. {
  63. Override Over;
  64. CacheDB Db;
  65. public:
  66. // Some flags
  67. bool DoMD5;
  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. // Limited by FileFd::Size()
  136. unsigned long size;
  137. ~CheckSum() {};
  138. };
  139. map<string,struct CheckSum> CheckSums;
  140. };
  141. #endif