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