]>
Commit | Line | Data |
---|---|---|
b2e465d6 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7db98ffc | 3 | // $Id: debindexfile.cc,v 1.5.2.3 2004/01/04 19:11:00 mdz Exp $ |
b2e465d6 AL |
4 | /* ###################################################################### |
5 | ||
6 | Debian Specific sources.list types and the three sorts of Debian | |
7 | index files. | |
8 | ||
9 | ##################################################################### */ | |
10 | /*}}}*/ | |
11 | // Include Files /*{{{*/ | |
ea542140 DK |
12 | #include <config.h> |
13 | ||
b2e465d6 AL |
14 | #include <apt-pkg/debindexfile.h> |
15 | #include <apt-pkg/debsrcrecords.h> | |
16 | #include <apt-pkg/deblistparser.h> | |
17 | #include <apt-pkg/debrecords.h> | |
b2e465d6 AL |
18 | #include <apt-pkg/configuration.h> |
19 | #include <apt-pkg/progress.h> | |
20 | #include <apt-pkg/error.h> | |
21 | #include <apt-pkg/strutl.h> | |
22 | #include <apt-pkg/acquire-item.h> | |
7db98ffc | 23 | #include <apt-pkg/debmetaindex.h> |
233b7808 | 24 | #include <apt-pkg/gpgv.h> |
453b82a3 DK |
25 | #include <apt-pkg/fileutl.h> |
26 | #include <apt-pkg/indexfile.h> | |
27 | #include <apt-pkg/mmap.h> | |
28 | #include <apt-pkg/pkgcache.h> | |
29 | #include <apt-pkg/cacheiterators.h> | |
30 | #include <apt-pkg/pkgcachegen.h> | |
31 | #include <apt-pkg/pkgrecords.h> | |
32 | #include <apt-pkg/srcrecords.h> | |
0d29b9d4 | 33 | #include <apt-pkg/sptr.h> |
e011829d | 34 | |
453b82a3 DK |
35 | #include <stdio.h> |
36 | #include <iostream> | |
2f6a2fbb | 37 | #include <sstream> |
453b82a3 | 38 | #include <string> |
b2e465d6 AL |
39 | #include <sys/stat.h> |
40 | /*}}}*/ | |
41 | ||
73688d27 DK |
42 | using std::string; |
43 | ||
b2e465d6 AL |
44 | // SourcesIndex::debSourcesIndex - Constructor /*{{{*/ |
45 | // --------------------------------------------------------------------- | |
46 | /* */ | |
e3c1cfc7 | 47 | debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) : |
6c55f07a | 48 | pkgIndexTargetFile(Target, Trusted), d(NULL) |
b2e465d6 AL |
49 | { |
50 | } | |
51 | /*}}}*/ | |
52 | // SourcesIndex::SourceInfo - Short 1 liner describing a source /*{{{*/ | |
53 | // --------------------------------------------------------------------- | |
54 | /* The result looks like: | |
5e02df82 | 55 | http://foo/debian/ stable/main src 1.1.1 (dsc) */ |
b2e465d6 AL |
56 | string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, |
57 | pkgSrcRecords::File const &File) const | |
58 | { | |
e3c1cfc7 DK |
59 | string Res = Target.Description; |
60 | Res.erase(Target.Description.rfind(' ')); | |
61 | ||
b2e465d6 AL |
62 | Res += " "; |
63 | Res += Record.Package(); | |
64 | Res += " "; | |
65 | Res += Record.Version(); | |
66 | if (File.Type.empty() == false) | |
67 | Res += " (" + File.Type + ")"; | |
68 | return Res; | |
69 | } | |
70 | /*}}}*/ | |
71 | // SourcesIndex::CreateSrcParser - Get a parser for the source files /*{{{*/ | |
72 | // --------------------------------------------------------------------- | |
73 | /* */ | |
74 | pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const | |
75 | { | |
e3c1cfc7 | 76 | string const SourcesURI = IndexFileName(); |
b0f4b486 MV |
77 | if (FileExists(SourcesURI)) |
78 | return new debSrcRecordParser(SourcesURI, this); | |
79 | return NULL; | |
b2e465d6 AL |
80 | } |
81 | /*}}}*/ | |
b2e465d6 AL |
82 | |
83 | // PackagesIndex::debPackagesIndex - Contructor /*{{{*/ | |
84 | // --------------------------------------------------------------------- | |
85 | /* */ | |
e3c1cfc7 | 86 | debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) : |
6c55f07a | 87 | pkgIndexTargetFile(Target, Trusted), d(NULL) |
b2e465d6 AL |
88 | { |
89 | } | |
90 | /*}}}*/ | |
91 | // PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/ | |
92 | // --------------------------------------------------------------------- | |
93 | /* This is a shorter version that is designed to be < 60 chars or so */ | |
94 | string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const | |
95 | { | |
001c76fe DK |
96 | std::string const Dist = Target.Option(IndexTarget::RELEASE); |
97 | string Res = Target.Option(IndexTarget::SITE) + " " + Dist; | |
98 | std::string const Component = Target.Option(IndexTarget::COMPONENT); | |
e3c1cfc7 DK |
99 | if (Component.empty() == false) |
100 | Res += "/" + Component; | |
101 | ||
b2e465d6 AL |
102 | Res += " "; |
103 | Res += Ver.ParentPkg().Name(); | |
104 | Res += " "; | |
e3c1cfc7 | 105 | if (Dist.empty() == false && Dist[Dist.size() - 1] != '/') |
dd13742e | 106 | Res.append(Ver.Arch()).append(" "); |
b2e465d6 AL |
107 | Res += Ver.VerStr(); |
108 | return Res; | |
109 | } | |
110 | /*}}}*/ | |
b2e465d6 AL |
111 | // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ |
112 | // --------------------------------------------------------------------- | |
113 | /* */ | |
2e5f4e45 | 114 | bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
b2e465d6 | 115 | { |
e3c1cfc7 | 116 | string const PackageFile = IndexFileName(); |
468720c5 | 117 | FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); |
001c76fe | 118 | debListParser Parser(&Pkg, Target.Option(IndexTarget::ARCHITECTURE)); |
3184b4cf | 119 | |
b2e465d6 AL |
120 | if (_error->PendingError() == true) |
121 | return _error->Error("Problem opening %s",PackageFile.c_str()); | |
2e5f4e45 | 122 | if (Prog != NULL) |
e3c1cfc7 DK |
123 | Prog->SubProgress(0, Target.Description); |
124 | ||
125 | ||
001c76fe DK |
126 | std::string const URI = Target.Option(IndexTarget::REPO_URI); |
127 | std::string Dist = Target.Option(IndexTarget::RELEASE); | |
e3c1cfc7 DK |
128 | if (Dist.empty()) |
129 | Dist = "/"; | |
b2e465d6 | 130 | ::URI Tmp(URI); |
e185d8b3 | 131 | if (Gen.SelectFile(PackageFile, *this, Target.Option(IndexTarget::ARCHITECTURE), Target.Option(IndexTarget::COMPONENT)) == false) |
b2e465d6 AL |
132 | return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); |
133 | ||
134 | // Store the IMS information | |
135 | pkgCache::PkgFileIterator File = Gen.GetCurFile(); | |
a9fe5928 | 136 | pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File); |
76a763e1 DK |
137 | File->Size = Pkg.FileSize(); |
138 | File->mtime = Pkg.ModificationTime(); | |
b07aeb1a | 139 | |
b2e465d6 AL |
140 | if (Gen.MergeList(Parser) == false) |
141 | return _error->Error("Problem with MergeList %s",PackageFile.c_str()); | |
142 | ||
b2e465d6 AL |
143 | return true; |
144 | } | |
145 | /*}}}*/ | |
146 | // PackagesIndex::FindInCache - Find this index /*{{{*/ | |
147 | // --------------------------------------------------------------------- | |
148 | /* */ | |
149 | pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const | |
150 | { | |
e3c1cfc7 | 151 | string const FileName = IndexFileName(); |
b2e465d6 | 152 | pkgCache::PkgFileIterator File = Cache.FileBegin(); |
f7f0d6c7 | 153 | for (; File.end() == false; ++File) |
b2e465d6 | 154 | { |
f6442c77 | 155 | if (File.FileName() == NULL || FileName != File.FileName()) |
b2e465d6 AL |
156 | continue; |
157 | ||
158 | struct stat St; | |
159 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
160 | { |
161 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
162 | std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
b2e465d6 | 163 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 164 | } |
b2e465d6 | 165 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
166 | { |
167 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
168 | std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
169 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
170 | << ") doesn't match for " << File.FileName() << std::endl; | |
b2e465d6 | 171 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 172 | } |
b2e465d6 AL |
173 | return File; |
174 | } | |
175 | ||
176 | return File; | |
177 | } | |
178 | /*}}}*/ | |
179 | ||
a52f938b | 180 | // TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ |
e3c1cfc7 | 181 | debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) : |
6c55f07a | 182 | pkgIndexTargetFile(Target, true), d(NULL) |
45df0ad2 | 183 | {} |
a52f938b | 184 | /*}}}*/ |
45df0ad2 | 185 | bool debTranslationsIndex::HasPackages() const /*{{{*/ |
11680bfd | 186 | { |
e3c1cfc7 | 187 | return Exists(); |
a52f938b OS |
188 | } |
189 | /*}}}*/ | |
190 | // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ | |
191 | // --------------------------------------------------------------------- | |
192 | /* */ | |
2e5f4e45 | 193 | bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
a52f938b OS |
194 | { |
195 | // Check the translation file, if in use | |
e3c1cfc7 | 196 | string const TranslationFile = IndexFileName(); |
64c2bdc9 | 197 | if (FileExists(TranslationFile)) |
a52f938b | 198 | { |
468720c5 | 199 | FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension); |
bc1c9081 | 200 | debTranslationsParser TransParser(&Trans); |
a52f938b OS |
201 | if (_error->PendingError() == true) |
202 | return false; | |
b07aeb1a | 203 | |
2e5f4e45 | 204 | if (Prog != NULL) |
e3c1cfc7 | 205 | Prog->SubProgress(0, Target.Description); |
d2cb5b15 | 206 | if (Gen.SelectFile(TranslationFile, *this, "", Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource | pkgCache::Flag::NoPackages) == false) |
a52f938b OS |
207 | return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); |
208 | ||
209 | // Store the IMS information | |
210 | pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); | |
76a763e1 DK |
211 | TransFile->Size = Trans.FileSize(); |
212 | TransFile->mtime = Trans.ModificationTime(); | |
b07aeb1a | 213 | |
a52f938b OS |
214 | if (Gen.MergeList(TransParser) == false) |
215 | return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); | |
216 | } | |
217 | ||
218 | return true; | |
219 | } | |
220 | /*}}}*/ | |
c51c6f08 OS |
221 | // TranslationsIndex::FindInCache - Find this index /*{{{*/ |
222 | // --------------------------------------------------------------------- | |
223 | /* */ | |
224 | pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const | |
225 | { | |
e3c1cfc7 DK |
226 | string FileName = IndexFileName(); |
227 | ||
c51c6f08 | 228 | pkgCache::PkgFileIterator File = Cache.FileBegin(); |
f7f0d6c7 | 229 | for (; File.end() == false; ++File) |
f416d22e MV |
230 | { |
231 | if (FileName != File.FileName()) | |
232 | continue; | |
4d34acf1 | 233 | |
f416d22e MV |
234 | struct stat St; |
235 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
236 | { |
237 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
238 | std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
f416d22e | 239 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 240 | } |
f416d22e | 241 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
242 | { |
243 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
244 | std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
245 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
246 | << ") doesn't match for " << File.FileName() << std::endl; | |
f416d22e | 247 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 248 | } |
f416d22e | 249 | return File; |
e3c1cfc7 | 250 | } |
c51c6f08 OS |
251 | return File; |
252 | } | |
253 | /*}}}*/ | |
e3c1cfc7 | 254 | |
b2e465d6 AL |
255 | // StatusIndex::debStatusIndex - Constructor /*{{{*/ |
256 | // --------------------------------------------------------------------- | |
257 | /* */ | |
6c55f07a | 258 | debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), d(NULL), File(File) |
b2e465d6 AL |
259 | { |
260 | } | |
261 | /*}}}*/ | |
262 | // StatusIndex::Size - Return the size of the index /*{{{*/ | |
263 | // --------------------------------------------------------------------- | |
264 | /* */ | |
265 | unsigned long debStatusIndex::Size() const | |
266 | { | |
267 | struct stat S; | |
268 | if (stat(File.c_str(),&S) != 0) | |
269 | return 0; | |
270 | return S.st_size; | |
271 | } | |
272 | /*}}}*/ | |
273 | // StatusIndex::Merge - Load the index file into a cache /*{{{*/ | |
274 | // --------------------------------------------------------------------- | |
275 | /* */ | |
2e5f4e45 | 276 | bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
b2e465d6 | 277 | { |
468720c5 | 278 | FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension); |
b2e465d6 AL |
279 | if (_error->PendingError() == true) |
280 | return false; | |
281 | debListParser Parser(&Pkg); | |
282 | if (_error->PendingError() == true) | |
283 | return false; | |
2e5f4e45 DK |
284 | |
285 | if (Prog != NULL) | |
286 | Prog->SubProgress(0,File); | |
e185d8b3 | 287 | if (Gen.SelectFile(File, *this, "", "now", pkgCache::Flag::NotSource) == false) |
b2e465d6 AL |
288 | return _error->Error("Problem with SelectFile %s",File.c_str()); |
289 | ||
290 | // Store the IMS information | |
291 | pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); | |
b07aeb1a | 292 | pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(CFile); |
76a763e1 DK |
293 | CFile->Size = Pkg.FileSize(); |
294 | CFile->mtime = Pkg.ModificationTime(); | |
b07aeb1a | 295 | |
b2e465d6 | 296 | if (Gen.MergeList(Parser) == false) |
b07aeb1a | 297 | return _error->Error("Problem with MergeList %s",File.c_str()); |
b2e465d6 AL |
298 | return true; |
299 | } | |
300 | /*}}}*/ | |
301 | // StatusIndex::FindInCache - Find this index /*{{{*/ | |
302 | // --------------------------------------------------------------------- | |
303 | /* */ | |
304 | pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const | |
305 | { | |
306 | pkgCache::PkgFileIterator File = Cache.FileBegin(); | |
f7f0d6c7 | 307 | for (; File.end() == false; ++File) |
b2e465d6 AL |
308 | { |
309 | if (this->File != File.FileName()) | |
310 | continue; | |
311 | ||
312 | struct stat St; | |
313 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
314 | { |
315 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
316 | std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
b2e465d6 | 317 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 318 | } |
b2e465d6 | 319 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
320 | { |
321 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
322 | std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
323 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
324 | << ") doesn't match for " << File.FileName() << std::endl; | |
b2e465d6 | 325 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 326 | } |
b2e465d6 AL |
327 | return File; |
328 | } | |
329 | return File; | |
330 | } | |
331 | /*}}}*/ | |
332 | // StatusIndex::Exists - Check if the index is available /*{{{*/ | |
333 | // --------------------------------------------------------------------- | |
334 | /* */ | |
a02db58f | 335 | APT_CONST bool debStatusIndex::Exists() const |
b2e465d6 AL |
336 | { |
337 | // Abort if the file does not exist. | |
338 | return true; | |
339 | } | |
340 | /*}}}*/ | |
341 | ||
5465192b DK |
342 | // debDebPkgFileIndex - Single .deb file /*{{{*/ |
343 | debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile) | |
6c55f07a | 344 | : pkgIndexFile(true), d(NULL), DebFile(DebFile) |
0d29b9d4 | 345 | { |
fb11075f | 346 | DebFileFullPath = flAbsPath(DebFile); |
0d29b9d4 | 347 | } |
0d29b9d4 MV |
348 | std::string debDebPkgFileIndex::ArchiveURI(std::string /*File*/) const |
349 | { | |
350 | return "file:" + DebFileFullPath; | |
351 | } | |
0d29b9d4 MV |
352 | bool debDebPkgFileIndex::Exists() const |
353 | { | |
354 | return FileExists(DebFile); | |
355 | } | |
2f6a2fbb | 356 | bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &debfile) |
0d29b9d4 | 357 | { |
2f6a2fbb DK |
358 | // get the control data out of the deb file via dpkg-deb -I |
359 | std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg-deb"); | |
fdff5b03 MV |
360 | std::vector<const char *> Args; |
361 | Args.push_back(dpkg.c_str()); | |
fdff5b03 | 362 | Args.push_back("-I"); |
2f6a2fbb | 363 | Args.push_back(debfile.c_str()); |
fdff5b03 MV |
364 | Args.push_back("control"); |
365 | Args.push_back(NULL); | |
a9d990a2 MV |
366 | FileFd PipeFd; |
367 | pid_t Child; | |
fdff5b03 | 368 | if(Popen((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false) |
a9d990a2 | 369 | return _error->Error("Popen failed"); |
2f6a2fbb DK |
370 | |
371 | char buffer[1024]; | |
372 | do { | |
373 | unsigned long long actual = 0; | |
374 | if (PipeFd.Read(buffer, sizeof(buffer)-1, &actual) == false) | |
375 | return _error->Errno("read", "Failed to read dpkg pipe"); | |
376 | if (actual == 0) | |
377 | break; | |
378 | buffer[actual] = '\0'; | |
379 | content << buffer; | |
380 | } while(true); | |
a9d990a2 | 381 | ExecWait(Child, "Popen"); |
0d29b9d4 | 382 | |
2f6a2fbb DK |
383 | content << "Filename: " << debfile << "\n"; |
384 | struct stat Buf; | |
385 | if (stat(debfile.c_str(), &Buf) != 0) | |
386 | return false; | |
387 | content << "Size: " << Buf.st_size << "\n"; | |
388 | ||
389 | return true; | |
390 | } | |
391 | bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const | |
392 | { | |
393 | if(Prog) | |
394 | Prog->SubProgress(0, "Reading deb file"); | |
395 | ||
396 | // write the control data to a tempfile | |
fdff5b03 | 397 | SPtr<FileFd> DebControl = GetTempFile("deb-file-" + flNotDir(DebFile)); |
0d29b9d4 MV |
398 | if(DebControl == NULL) |
399 | return false; | |
2f6a2fbb DK |
400 | std::ostringstream content; |
401 | if (GetContent(content, DebFile) == false) | |
402 | return false; | |
403 | std::string const contentstr = content.str(); | |
5465192b DK |
404 | if (contentstr.empty()) |
405 | return true; | |
2f6a2fbb DK |
406 | DebControl->Write(contentstr.c_str(), contentstr.length()); |
407 | // rewind for the listparser | |
0d29b9d4 MV |
408 | DebControl->Seek(0); |
409 | ||
410 | // and give it to the list parser | |
411 | debDebFileParser Parser(DebControl, DebFile); | |
e185d8b3 | 412 | if(Gen.SelectFile(DebFile, *this, "", "now", pkgCache::Flag::LocalSource) == false) |
0d29b9d4 MV |
413 | return _error->Error("Problem with SelectFile %s", DebFile.c_str()); |
414 | ||
415 | pkgCache::PkgFileIterator File = Gen.GetCurFile(); | |
416 | File->Size = DebControl->Size(); | |
417 | File->mtime = DebControl->ModificationTime(); | |
448c38bd | 418 | |
0d29b9d4 MV |
419 | if (Gen.MergeList(Parser) == false) |
420 | return _error->Error("Problem with MergeLister for %s", DebFile.c_str()); | |
421 | ||
422 | return true; | |
423 | } | |
424 | pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const | |
425 | { | |
0d29b9d4 MV |
426 | pkgCache::PkgFileIterator File = Cache.FileBegin(); |
427 | for (; File.end() == false; ++File) | |
428 | { | |
429 | if (File.FileName() == NULL || DebFile != File.FileName()) | |
430 | continue; | |
431 | ||
432 | return File; | |
433 | } | |
5465192b | 434 | |
0d29b9d4 MV |
435 | return File; |
436 | } | |
437 | unsigned long debDebPkgFileIndex::Size() const | |
438 | { | |
439 | struct stat buf; | |
440 | if(stat(DebFile.c_str(), &buf) != 0) | |
441 | return 0; | |
442 | return buf.st_size; | |
443 | } | |
444 | /*}}}*/ | |
445 | ||
5465192b DK |
446 | // debDscFileIndex - a .dsc file /*{{{*/ |
447 | debDscFileIndex::debDscFileIndex(std::string const &DscFile) | |
6c55f07a | 448 | : pkgIndexFile(true), d(NULL), DscFile(DscFile) |
a49e7948 MV |
449 | { |
450 | } | |
a49e7948 MV |
451 | bool debDscFileIndex::Exists() const |
452 | { | |
453 | return FileExists(DscFile); | |
454 | } | |
455 | ||
456 | unsigned long debDscFileIndex::Size() const | |
457 | { | |
458 | struct stat buf; | |
459 | if(stat(DscFile.c_str(), &buf) == 0) | |
460 | return buf.st_size; | |
461 | return 0; | |
462 | } | |
a49e7948 MV |
463 | pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const |
464 | { | |
465 | if (!FileExists(DscFile)) | |
466 | return NULL; | |
467 | ||
468 | return new debDscRecordParser(DscFile,this); | |
469 | } | |
470 | /*}}}*/ | |
5465192b | 471 | |
b2e465d6 | 472 | // Index File types for Debian /*{{{*/ |
dce45dbe | 473 | class APT_HIDDEN debIFTypeSrc : public pkgIndexFile::Type |
b2e465d6 AL |
474 | { |
475 | public: | |
b2e465d6 AL |
476 | debIFTypeSrc() {Label = "Debian Source Index";}; |
477 | }; | |
dce45dbe | 478 | class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type |
b2e465d6 AL |
479 | { |
480 | public: | |
5465192b | 481 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE |
b2e465d6 AL |
482 | { |
483 | return new debRecordParser(File.FileName(),*File.Cache()); | |
484 | }; | |
485 | debIFTypePkg() {Label = "Debian Package Index";}; | |
486 | }; | |
dce45dbe | 487 | class APT_HIDDEN debIFTypeTrans : public debIFTypePkg |
97234432 MV |
488 | { |
489 | public: | |
490 | debIFTypeTrans() {Label = "Debian Translation Index";}; | |
491 | }; | |
dce45dbe | 492 | class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type |
b2e465d6 AL |
493 | { |
494 | public: | |
5465192b | 495 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE |
b2e465d6 AL |
496 | { |
497 | return new debRecordParser(File.FileName(),*File.Cache()); | |
498 | }; | |
499 | debIFTypeStatus() {Label = "Debian dpkg status file";}; | |
500 | }; | |
dce45dbe | 501 | class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type |
0d29b9d4 MV |
502 | { |
503 | public: | |
5465192b | 504 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE |
0d29b9d4 | 505 | { |
2f6a2fbb | 506 | return new debDebFileRecordParser(File.FileName()); |
0d29b9d4 | 507 | }; |
463c8d80 | 508 | debIFTypeDebPkgFile() {Label = "Debian deb file";}; |
0d29b9d4 | 509 | }; |
dce45dbe | 510 | class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type |
a49e7948 MV |
511 | { |
512 | public: | |
3b302846 | 513 | virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const APT_OVERRIDE |
a49e7948 MV |
514 | { |
515 | return new debDscRecordParser(DscFile, NULL); | |
516 | }; | |
463c8d80 | 517 | debIFTypeDscFile() {Label = "Debian dsc file";}; |
a49e7948 | 518 | }; |
dce45dbe | 519 | class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type |
77da39b9 MV |
520 | { |
521 | public: | |
3b302846 | 522 | virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const APT_OVERRIDE |
77da39b9 MV |
523 | { |
524 | return new debDscRecordParser(SourceDir + string("/debian/control"), NULL); | |
525 | }; | |
463c8d80 | 526 | debIFTypeDebianSourceDir() {Label = "Debian control file";}; |
77da39b9 | 527 | }; |
a49e7948 | 528 | |
dce45dbe DK |
529 | APT_HIDDEN debIFTypeSrc _apt_Src; |
530 | APT_HIDDEN debIFTypePkg _apt_Pkg; | |
531 | APT_HIDDEN debIFTypeTrans _apt_Trans; | |
532 | APT_HIDDEN debIFTypeStatus _apt_Status; | |
533 | APT_HIDDEN debIFTypeDebPkgFile _apt_DebPkgFile; | |
a49e7948 | 534 | // file based pseudo indexes |
dce45dbe DK |
535 | APT_HIDDEN debIFTypeDscFile _apt_DscFile; |
536 | APT_HIDDEN debIFTypeDebianSourceDir _apt_DebianSourceDir; | |
b2e465d6 AL |
537 | |
538 | const pkgIndexFile::Type *debSourcesIndex::GetType() const | |
539 | { | |
540 | return &_apt_Src; | |
541 | } | |
542 | const pkgIndexFile::Type *debPackagesIndex::GetType() const | |
543 | { | |
544 | return &_apt_Pkg; | |
545 | } | |
a52f938b OS |
546 | const pkgIndexFile::Type *debTranslationsIndex::GetType() const |
547 | { | |
97234432 | 548 | return &_apt_Trans; |
a52f938b | 549 | } |
b2e465d6 AL |
550 | const pkgIndexFile::Type *debStatusIndex::GetType() const |
551 | { | |
552 | return &_apt_Status; | |
553 | } | |
0d29b9d4 MV |
554 | const pkgIndexFile::Type *debDebPkgFileIndex::GetType() const |
555 | { | |
556 | return &_apt_DebPkgFile; | |
070536e6 | 557 | } |
a49e7948 MV |
558 | const pkgIndexFile::Type *debDscFileIndex::GetType() const |
559 | { | |
560 | return &_apt_DscFile; | |
561 | } | |
77da39b9 MV |
562 | const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const |
563 | { | |
564 | return &_apt_DebianSourceDir; | |
0d29b9d4 | 565 | } |
b2e465d6 | 566 | /*}}}*/ |
862bafea DK |
567 | |
568 | debStatusIndex::~debStatusIndex() {} | |
569 | debPackagesIndex::~debPackagesIndex() {} | |
570 | debTranslationsIndex::~debTranslationsIndex() {} | |
571 | debSourcesIndex::~debSourcesIndex() {} | |
572 | ||
573 | debDebPkgFileIndex::~debDebPkgFileIndex() {} | |
c8a4ce6c | 574 | debDscFileIndex::~debDscFileIndex() {} |