debindexfile.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: debindexfile.cc,v 1.5.2.3 2004/01/04 19:11:00 mdz Exp $
  4. /* ######################################################################
  5. Debian Specific sources.list types and the three sorts of Debian
  6. index files.
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include <config.h>
  11. #include <apt-pkg/debindexfile.h>
  12. #include <apt-pkg/debsrcrecords.h>
  13. #include <apt-pkg/deblistparser.h>
  14. #include <apt-pkg/debrecords.h>
  15. #include <apt-pkg/sourcelist.h>
  16. #include <apt-pkg/configuration.h>
  17. #include <apt-pkg/progress.h>
  18. #include <apt-pkg/error.h>
  19. #include <apt-pkg/strutl.h>
  20. #include <apt-pkg/acquire-item.h>
  21. #include <apt-pkg/debmetaindex.h>
  22. #include <apt-pkg/gpgv.h>
  23. #include <sys/stat.h>
  24. /*}}}*/
  25. using std::string;
  26. // SourcesIndex::debSourcesIndex - Constructor /*{{{*/
  27. // ---------------------------------------------------------------------
  28. /* */
  29. debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) :
  30. pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section)
  31. {
  32. }
  33. /*}}}*/
  34. // SourcesIndex::SourceInfo - Short 1 liner describing a source /*{{{*/
  35. // ---------------------------------------------------------------------
  36. /* The result looks like:
  37. http://foo/debian/ stable/main src 1.1.1 (dsc) */
  38. string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
  39. pkgSrcRecords::File const &File) const
  40. {
  41. string Res;
  42. Res = ::URI::NoUserPassword(URI) + ' ';
  43. if (Dist[Dist.size() - 1] == '/')
  44. {
  45. if (Dist != "/")
  46. Res += Dist;
  47. }
  48. else
  49. Res += Dist + '/' + Section;
  50. Res += " ";
  51. Res += Record.Package();
  52. Res += " ";
  53. Res += Record.Version();
  54. if (File.Type.empty() == false)
  55. Res += " (" + File.Type + ")";
  56. return Res;
  57. }
  58. /*}}}*/
  59. // SourcesIndex::CreateSrcParser - Get a parser for the source files /*{{{*/
  60. // ---------------------------------------------------------------------
  61. /* */
  62. pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
  63. {
  64. string SourcesURI = _config->FindDir("Dir::State::lists") +
  65. URItoFileName(IndexURI("Sources"));
  66. string SourcesURIgzip = SourcesURI + ".gz";
  67. if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip))
  68. return NULL;
  69. else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip))
  70. SourcesURI = SourcesURIgzip;
  71. return new debSrcRecordParser(SourcesURI,this);
  72. }
  73. /*}}}*/
  74. // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/
  75. // ---------------------------------------------------------------------
  76. /* */
  77. string debSourcesIndex::Describe(bool Short) const
  78. {
  79. char S[300];
  80. if (Short == true)
  81. snprintf(S,sizeof(S),"%s",Info("Sources").c_str());
  82. else
  83. snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(),
  84. IndexFile("Sources").c_str());
  85. return S;
  86. }
  87. /*}}}*/
  88. // SourcesIndex::Info - One liner describing the index URI /*{{{*/
  89. // ---------------------------------------------------------------------
  90. /* */
  91. string debSourcesIndex::Info(const char *Type) const
  92. {
  93. string Info = ::URI::NoUserPassword(URI) + ' ';
  94. if (Dist[Dist.size() - 1] == '/')
  95. {
  96. if (Dist != "/")
  97. Info += Dist;
  98. }
  99. else
  100. Info += Dist + '/' + Section;
  101. Info += " ";
  102. Info += Type;
  103. return Info;
  104. }
  105. /*}}}*/
  106. // SourcesIndex::Index* - Return the URI to the index files /*{{{*/
  107. // ---------------------------------------------------------------------
  108. /* */
  109. inline string debSourcesIndex::IndexFile(const char *Type) const
  110. {
  111. string s = URItoFileName(IndexURI(Type));
  112. string sgzip = s + ".gz";
  113. if (!FileExists(s) && FileExists(sgzip))
  114. return sgzip;
  115. else
  116. return s;
  117. }
  118. string debSourcesIndex::IndexURI(const char *Type) const
  119. {
  120. string Res;
  121. if (Dist[Dist.size() - 1] == '/')
  122. {
  123. if (Dist != "/")
  124. Res = URI + Dist;
  125. else
  126. Res = URI;
  127. }
  128. else
  129. Res = URI + "dists/" + Dist + '/' + Section +
  130. "/source/";
  131. Res += Type;
  132. return Res;
  133. }
  134. /*}}}*/
  135. // SourcesIndex::Exists - Check if the index is available /*{{{*/
  136. // ---------------------------------------------------------------------
  137. /* */
  138. bool debSourcesIndex::Exists() const
  139. {
  140. return FileExists(IndexFile("Sources"));
  141. }
  142. /*}}}*/
  143. // SourcesIndex::Size - Return the size of the index /*{{{*/
  144. // ---------------------------------------------------------------------
  145. /* */
  146. unsigned long debSourcesIndex::Size() const
  147. {
  148. unsigned long size = 0;
  149. /* we need to ignore errors here; if the lists are absent, just return 0 */
  150. _error->PushToStack();
  151. FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension);
  152. if (!f.Failed())
  153. size = f.Size();
  154. if (_error->PendingError() == true)
  155. size = 0;
  156. _error->RevertToStack();
  157. return size;
  158. }
  159. /*}}}*/
  160. // PackagesIndex::debPackagesIndex - Contructor /*{{{*/
  161. // ---------------------------------------------------------------------
  162. /* */
  163. debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section,
  164. bool const &Trusted, string const &Arch) :
  165. pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch)
  166. {
  167. if (Architecture == "native")
  168. Architecture = _config->Find("APT::Architecture");
  169. }
  170. /*}}}*/
  171. // PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/
  172. // ---------------------------------------------------------------------
  173. /* This is a shorter version that is designed to be < 60 chars or so */
  174. string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const
  175. {
  176. string Res = ::URI::NoUserPassword(URI) + ' ';
  177. if (Dist[Dist.size() - 1] == '/')
  178. {
  179. if (Dist != "/")
  180. Res += Dist;
  181. }
  182. else
  183. Res += Dist + '/' + Section;
  184. Res += " ";
  185. Res += Ver.ParentPkg().Name();
  186. Res += " ";
  187. if (Dist[Dist.size() - 1] != '/')
  188. Res.append(Ver.Arch()).append(" ");
  189. Res += Ver.VerStr();
  190. return Res;
  191. }
  192. /*}}}*/
  193. // PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/
  194. // ---------------------------------------------------------------------
  195. /* This should help the user find the index in the sources.list and
  196. in the filesystem for problem solving */
  197. string debPackagesIndex::Describe(bool Short) const
  198. {
  199. char S[300];
  200. if (Short == true)
  201. snprintf(S,sizeof(S),"%s",Info("Packages").c_str());
  202. else
  203. snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(),
  204. IndexFile("Packages").c_str());
  205. return S;
  206. }
  207. /*}}}*/
  208. // PackagesIndex::Info - One liner describing the index URI /*{{{*/
  209. // ---------------------------------------------------------------------
  210. /* */
  211. string debPackagesIndex::Info(const char *Type) const
  212. {
  213. string Info = ::URI::NoUserPassword(URI) + ' ';
  214. if (Dist[Dist.size() - 1] == '/')
  215. {
  216. if (Dist != "/")
  217. Info += Dist;
  218. }
  219. else
  220. Info += Dist + '/' + Section;
  221. Info += " ";
  222. if (Dist[Dist.size() - 1] != '/')
  223. Info += Architecture + " ";
  224. Info += Type;
  225. return Info;
  226. }
  227. /*}}}*/
  228. // PackagesIndex::Index* - Return the URI to the index files /*{{{*/
  229. // ---------------------------------------------------------------------
  230. /* */
  231. inline string debPackagesIndex::IndexFile(const char *Type) const
  232. {
  233. string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
  234. string sgzip = s + ".gz";
  235. if (!FileExists(s) && FileExists(sgzip))
  236. return sgzip;
  237. else
  238. return s;
  239. }
  240. string debPackagesIndex::IndexURI(const char *Type) const
  241. {
  242. string Res;
  243. if (Dist[Dist.size() - 1] == '/')
  244. {
  245. if (Dist != "/")
  246. Res = URI + Dist;
  247. else
  248. Res = URI;
  249. }
  250. else
  251. Res = URI + "dists/" + Dist + '/' + Section +
  252. "/binary-" + Architecture + '/';
  253. Res += Type;
  254. return Res;
  255. }
  256. /*}}}*/
  257. // PackagesIndex::Exists - Check if the index is available /*{{{*/
  258. // ---------------------------------------------------------------------
  259. /* */
  260. bool debPackagesIndex::Exists() const
  261. {
  262. return FileExists(IndexFile("Packages"));
  263. }
  264. /*}}}*/
  265. // PackagesIndex::Size - Return the size of the index /*{{{*/
  266. // ---------------------------------------------------------------------
  267. /* This is really only used for progress reporting. */
  268. unsigned long debPackagesIndex::Size() const
  269. {
  270. unsigned long size = 0;
  271. /* we need to ignore errors here; if the lists are absent, just return 0 */
  272. _error->PushToStack();
  273. FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension);
  274. if (!f.Failed())
  275. size = f.Size();
  276. if (_error->PendingError() == true)
  277. size = 0;
  278. _error->RevertToStack();
  279. return size;
  280. }
  281. /*}}}*/
  282. // PackagesIndex::Merge - Load the index file into a cache /*{{{*/
  283. // ---------------------------------------------------------------------
  284. /* */
  285. bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
  286. {
  287. string PackageFile = IndexFile("Packages");
  288. FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension);
  289. debListParser Parser(&Pkg, Architecture);
  290. if (_error->PendingError() == true)
  291. return _error->Error("Problem opening %s",PackageFile.c_str());
  292. if (Prog != NULL)
  293. Prog->SubProgress(0,Info("Packages"));
  294. ::URI Tmp(URI);
  295. if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
  296. return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
  297. // Store the IMS information
  298. pkgCache::PkgFileIterator File = Gen.GetCurFile();
  299. pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File);
  300. File->Size = Pkg.FileSize();
  301. File->mtime = Pkg.ModificationTime();
  302. if (Gen.MergeList(Parser) == false)
  303. return _error->Error("Problem with MergeList %s",PackageFile.c_str());
  304. // Check the release file
  305. string ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("InRelease");
  306. bool releaseExists = false;
  307. if (FileExists(ReleaseFile) == true)
  308. releaseExists = true;
  309. else
  310. ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("Release");
  311. if (releaseExists == true || FileExists(ReleaseFile) == true)
  312. {
  313. FileFd Rel;
  314. // Beware: The 'Release' file might be clearsigned in case the
  315. // signature for an 'InRelease' file couldn't be checked
  316. if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
  317. return false;
  318. if (_error->PendingError() == true)
  319. return false;
  320. Parser.LoadReleaseInfo(File,Rel,Section);
  321. }
  322. return true;
  323. }
  324. /*}}}*/
  325. // PackagesIndex::FindInCache - Find this index /*{{{*/
  326. // ---------------------------------------------------------------------
  327. /* */
  328. pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
  329. {
  330. string FileName = IndexFile("Packages");
  331. pkgCache::PkgFileIterator File = Cache.FileBegin();
  332. for (; File.end() == false; ++File)
  333. {
  334. if (File.FileName() == NULL || FileName != File.FileName())
  335. continue;
  336. struct stat St;
  337. if (stat(File.FileName(),&St) != 0)
  338. {
  339. if (_config->FindB("Debug::pkgCacheGen", false))
  340. std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  341. return pkgCache::PkgFileIterator(Cache);
  342. }
  343. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  344. {
  345. if (_config->FindB("Debug::pkgCacheGen", false))
  346. std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  347. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  348. << ") doesn't match for " << File.FileName() << std::endl;
  349. return pkgCache::PkgFileIterator(Cache);
  350. }
  351. return File;
  352. }
  353. return File;
  354. }
  355. /*}}}*/
  356. // TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/
  357. // ---------------------------------------------------------------------
  358. /* */
  359. debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section,
  360. char const * const Translation) :
  361. pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section),
  362. Language(Translation)
  363. {}
  364. /*}}}*/
  365. // TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/
  366. // ---------------------------------------------------------------------
  367. /* */
  368. inline string debTranslationsIndex::IndexFile(const char *Type) const
  369. {
  370. string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
  371. string sgzip = s + ".gz";
  372. if (!FileExists(s) && FileExists(sgzip))
  373. return sgzip;
  374. else
  375. return s;
  376. }
  377. string debTranslationsIndex::IndexURI(const char *Type) const
  378. {
  379. string Res;
  380. if (Dist[Dist.size() - 1] == '/')
  381. {
  382. if (Dist != "/")
  383. Res = URI + Dist;
  384. else
  385. Res = URI;
  386. }
  387. else
  388. Res = URI + "dists/" + Dist + '/' + Section +
  389. "/i18n/Translation-";
  390. Res += Type;
  391. return Res;
  392. }
  393. /*}}}*/
  394. // TranslationsIndex::GetIndexes - Fetch the index files /*{{{*/
  395. // ---------------------------------------------------------------------
  396. /* */
  397. bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const
  398. {
  399. string const TranslationFile = string("Translation-").append(Language);
  400. new pkgAcqIndexTrans(Owner, IndexURI(Language),
  401. Info(TranslationFile.c_str()),
  402. TranslationFile);
  403. return true;
  404. }
  405. /*}}}*/
  406. // TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/
  407. // ---------------------------------------------------------------------
  408. /* This should help the user find the index in the sources.list and
  409. in the filesystem for problem solving */
  410. string debTranslationsIndex::Describe(bool Short) const
  411. {
  412. char S[300];
  413. if (Short == true)
  414. snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str());
  415. else
  416. snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(),
  417. IndexFile(Language).c_str());
  418. return S;
  419. }
  420. /*}}}*/
  421. // TranslationsIndex::Info - One liner describing the index URI /*{{{*/
  422. // ---------------------------------------------------------------------
  423. /* */
  424. string debTranslationsIndex::Info(const char *Type) const
  425. {
  426. string Info = ::URI::NoUserPassword(URI) + ' ';
  427. if (Dist[Dist.size() - 1] == '/')
  428. {
  429. if (Dist != "/")
  430. Info += Dist;
  431. }
  432. else
  433. Info += Dist + '/' + Section;
  434. Info += " ";
  435. Info += Type;
  436. return Info;
  437. }
  438. /*}}}*/
  439. bool debTranslationsIndex::HasPackages() const /*{{{*/
  440. {
  441. return FileExists(IndexFile(Language));
  442. }
  443. /*}}}*/
  444. // TranslationsIndex::Exists - Check if the index is available /*{{{*/
  445. // ---------------------------------------------------------------------
  446. /* */
  447. bool debTranslationsIndex::Exists() const
  448. {
  449. return FileExists(IndexFile(Language));
  450. }
  451. /*}}}*/
  452. // TranslationsIndex::Size - Return the size of the index /*{{{*/
  453. // ---------------------------------------------------------------------
  454. /* This is really only used for progress reporting. */
  455. unsigned long debTranslationsIndex::Size() const
  456. {
  457. unsigned long size = 0;
  458. /* we need to ignore errors here; if the lists are absent, just return 0 */
  459. _error->PushToStack();
  460. FileFd f(IndexFile(Language), FileFd::ReadOnly, FileFd::Extension);
  461. if (!f.Failed())
  462. size = f.Size();
  463. if (_error->PendingError() == true)
  464. size = 0;
  465. _error->RevertToStack();
  466. return size;
  467. }
  468. /*}}}*/
  469. // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/
  470. // ---------------------------------------------------------------------
  471. /* */
  472. bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
  473. {
  474. // Check the translation file, if in use
  475. string TranslationFile = IndexFile(Language);
  476. if (FileExists(TranslationFile))
  477. {
  478. FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension);
  479. debListParser TransParser(&Trans);
  480. if (_error->PendingError() == true)
  481. return false;
  482. if (Prog != NULL)
  483. Prog->SubProgress(0, Info(TranslationFile.c_str()));
  484. if (Gen.SelectFile(TranslationFile,string(),*this) == false)
  485. return _error->Error("Problem with SelectFile %s",TranslationFile.c_str());
  486. // Store the IMS information
  487. pkgCache::PkgFileIterator TransFile = Gen.GetCurFile();
  488. TransFile->Size = Trans.FileSize();
  489. TransFile->mtime = Trans.ModificationTime();
  490. if (Gen.MergeList(TransParser) == false)
  491. return _error->Error("Problem with MergeList %s",TranslationFile.c_str());
  492. }
  493. return true;
  494. }
  495. /*}}}*/
  496. // TranslationsIndex::FindInCache - Find this index /*{{{*/
  497. // ---------------------------------------------------------------------
  498. /* */
  499. pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const
  500. {
  501. string FileName = IndexFile(Language);
  502. pkgCache::PkgFileIterator File = Cache.FileBegin();
  503. for (; File.end() == false; ++File)
  504. {
  505. if (FileName != File.FileName())
  506. continue;
  507. struct stat St;
  508. if (stat(File.FileName(),&St) != 0)
  509. {
  510. if (_config->FindB("Debug::pkgCacheGen", false))
  511. std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  512. return pkgCache::PkgFileIterator(Cache);
  513. }
  514. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  515. {
  516. if (_config->FindB("Debug::pkgCacheGen", false))
  517. std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  518. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  519. << ") doesn't match for " << File.FileName() << std::endl;
  520. return pkgCache::PkgFileIterator(Cache);
  521. }
  522. return File;
  523. }
  524. return File;
  525. }
  526. /*}}}*/
  527. // StatusIndex::debStatusIndex - Constructor /*{{{*/
  528. // ---------------------------------------------------------------------
  529. /* */
  530. debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), File(File)
  531. {
  532. }
  533. /*}}}*/
  534. // StatusIndex::Size - Return the size of the index /*{{{*/
  535. // ---------------------------------------------------------------------
  536. /* */
  537. unsigned long debStatusIndex::Size() const
  538. {
  539. struct stat S;
  540. if (stat(File.c_str(),&S) != 0)
  541. return 0;
  542. return S.st_size;
  543. }
  544. /*}}}*/
  545. // StatusIndex::Merge - Load the index file into a cache /*{{{*/
  546. // ---------------------------------------------------------------------
  547. /* */
  548. bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
  549. {
  550. FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension);
  551. if (_error->PendingError() == true)
  552. return false;
  553. debListParser Parser(&Pkg);
  554. if (_error->PendingError() == true)
  555. return false;
  556. if (Prog != NULL)
  557. Prog->SubProgress(0,File);
  558. if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false)
  559. return _error->Error("Problem with SelectFile %s",File.c_str());
  560. // Store the IMS information
  561. pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
  562. CFile->Size = Pkg.FileSize();
  563. CFile->mtime = Pkg.ModificationTime();
  564. map_ptrloc const storage = Gen.WriteUniqString("now");
  565. CFile->Archive = storage;
  566. if (Gen.MergeList(Parser) == false)
  567. return _error->Error("Problem with MergeList %s",File.c_str());
  568. return true;
  569. }
  570. /*}}}*/
  571. // StatusIndex::FindInCache - Find this index /*{{{*/
  572. // ---------------------------------------------------------------------
  573. /* */
  574. pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const
  575. {
  576. pkgCache::PkgFileIterator File = Cache.FileBegin();
  577. for (; File.end() == false; ++File)
  578. {
  579. if (this->File != File.FileName())
  580. continue;
  581. struct stat St;
  582. if (stat(File.FileName(),&St) != 0)
  583. {
  584. if (_config->FindB("Debug::pkgCacheGen", false))
  585. std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  586. return pkgCache::PkgFileIterator(Cache);
  587. }
  588. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  589. {
  590. if (_config->FindB("Debug::pkgCacheGen", false))
  591. std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  592. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  593. << ") doesn't match for " << File.FileName() << std::endl;
  594. return pkgCache::PkgFileIterator(Cache);
  595. }
  596. return File;
  597. }
  598. return File;
  599. }
  600. /*}}}*/
  601. // StatusIndex::Exists - Check if the index is available /*{{{*/
  602. // ---------------------------------------------------------------------
  603. /* */
  604. bool debStatusIndex::Exists() const
  605. {
  606. // Abort if the file does not exist.
  607. return true;
  608. }
  609. /*}}}*/
  610. // Index File types for Debian /*{{{*/
  611. class debIFTypeSrc : public pkgIndexFile::Type
  612. {
  613. public:
  614. debIFTypeSrc() {Label = "Debian Source Index";};
  615. };
  616. class debIFTypePkg : public pkgIndexFile::Type
  617. {
  618. public:
  619. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
  620. {
  621. return new debRecordParser(File.FileName(),*File.Cache());
  622. };
  623. debIFTypePkg() {Label = "Debian Package Index";};
  624. };
  625. class debIFTypeTrans : public debIFTypePkg
  626. {
  627. public:
  628. debIFTypeTrans() {Label = "Debian Translation Index";};
  629. };
  630. class debIFTypeStatus : public pkgIndexFile::Type
  631. {
  632. public:
  633. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
  634. {
  635. return new debRecordParser(File.FileName(),*File.Cache());
  636. };
  637. debIFTypeStatus() {Label = "Debian dpkg status file";};
  638. };
  639. static debIFTypeSrc _apt_Src;
  640. static debIFTypePkg _apt_Pkg;
  641. static debIFTypeTrans _apt_Trans;
  642. static debIFTypeStatus _apt_Status;
  643. const pkgIndexFile::Type *debSourcesIndex::GetType() const
  644. {
  645. return &_apt_Src;
  646. }
  647. const pkgIndexFile::Type *debPackagesIndex::GetType() const
  648. {
  649. return &_apt_Pkg;
  650. }
  651. const pkgIndexFile::Type *debTranslationsIndex::GetType() const
  652. {
  653. return &_apt_Trans;
  654. }
  655. const pkgIndexFile::Type *debStatusIndex::GetType() const
  656. {
  657. return &_apt_Status;
  658. }
  659. /*}}}*/