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