writer.h 3.7 KB

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