1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debindexfile.cc,v 1.5 2001/04/29 05:13:51 jgg Exp $
4 /* ######################################################################
6 Debian Specific sources.list types and the three sorts of Debian
9 ##################################################################### */
11 // Include Files /*{{{*/
13 #pragma implementation "apt-pkg/debindexfile.h"
16 #include <apt-pkg/debindexfile.h>
17 #include <apt-pkg/debsrcrecords.h>
18 #include <apt-pkg/deblistparser.h>
19 #include <apt-pkg/debrecords.h>
20 #include <apt-pkg/sourcelist.h>
21 #include <apt-pkg/configuration.h>
22 #include <apt-pkg/progress.h>
23 #include <apt-pkg/error.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/acquire-item.h>
30 // SourcesIndex::debSourcesIndex - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 debSourcesIndex::debSourcesIndex(string URI
,string Dist
,string Section
) :
34 URI(URI
), Dist(Dist
), Section(Section
)
38 // SourcesIndex::SourceInfo - Short 1 liner describing a source /*{{{*/
39 // ---------------------------------------------------------------------
40 /* The result looks like:
41 http://foo/ stable/main src 1.1.1 (dsc) */
42 string
debSourcesIndex::SourceInfo(pkgSrcRecords::Parser
const &Record
,
43 pkgSrcRecords::File
const &File
) const
46 Res
= ::URI::SiteOnly(URI
) + ' ';
47 if (Dist
[Dist
.size() - 1] == '/')
53 Res
+= Dist
+ '/' + Section
;
56 Res
+= Record
.Package();
58 Res
+= Record
.Version();
59 if (File
.Type
.empty() == false)
60 Res
+= " (" + File
.Type
+ ")";
64 // SourcesIndex::CreateSrcParser - Get a parser for the source files /*{{{*/
65 // ---------------------------------------------------------------------
67 pkgSrcRecords::Parser
*debSourcesIndex::CreateSrcParser() const
69 string SourcesURI
= URItoFileName(IndexURI("Sources"));
70 return new debSrcRecordParser(_config
->FindDir("Dir::State::lists") +
74 // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/
75 // ---------------------------------------------------------------------
77 string
debSourcesIndex::Describe(bool Short
) const
81 snprintf(S
,sizeof(S
),"%s",Info("Packages").c_str());
83 snprintf(S
,sizeof(S
),"%s (%s)",Info("Packages").c_str(),
84 IndexFile("Sources").c_str());
89 // SourcesIndex::Info - One liner describing the index URI /*{{{*/
90 // ---------------------------------------------------------------------
92 string
debSourcesIndex::Info(const char *Type
) const
94 string Info
= ::URI::SiteOnly(URI
) + ' ';
95 if (Dist
[Dist
.size() - 1] == '/')
101 Info
+= Dist
+ '/' + Section
;
107 // SourcesIndex::Index* - Return the URI to the index files /*{{{*/
108 // ---------------------------------------------------------------------
110 inline string
debSourcesIndex::IndexFile(const char *Type
) const
112 return URItoFileName(IndexURI(Type
));
114 string
debSourcesIndex::IndexURI(const char *Type
) const
117 if (Dist
[Dist
.size() - 1] == '/')
125 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
132 // SourcesIndex::GetIndexes - Fetch the index files /*{{{*/
133 // ---------------------------------------------------------------------
135 bool debSourcesIndex::GetIndexes(pkgAcquire
*Owner
) const
137 new pkgAcqIndex(Owner
,IndexURI("Sources"),Info("Sources"),"Sources");
138 new pkgAcqIndexRel(Owner
,IndexURI("Release"),Info("Release"),"Release");
142 // SourcesIndex::Exists - Check if the index is available /*{{{*/
143 // ---------------------------------------------------------------------
145 bool debSourcesIndex::Exists() const
147 return FileExists(IndexFile("Sources"));
150 // SourcesIndex::Size - Return the size of the index /*{{{*/
151 // ---------------------------------------------------------------------
153 unsigned long debSourcesIndex::Size() const
156 if (stat(IndexFile("Sources").c_str(),&S
) != 0)
162 // PackagesIndex::debPackagesIndex - Contructor /*{{{*/
163 // ---------------------------------------------------------------------
165 debPackagesIndex::debPackagesIndex(string URI
,string Dist
,string Section
) :
166 URI(URI
), Dist(Dist
), Section(Section
)
170 // PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/
171 // ---------------------------------------------------------------------
172 /* This is a shorter version that is designed to be < 60 chars or so */
173 string
debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver
) const
175 string Res
= ::URI::SiteOnly(URI
) + ' ';
176 if (Dist
[Dist
.size() - 1] == '/')
182 Res
+= Dist
+ '/' + Section
;
185 Res
+= Ver
.ParentPkg().Name();
191 // PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/
192 // ---------------------------------------------------------------------
193 /* This should help the user find the index in the sources.list and
194 in the filesystem for problem solving */
195 string
debPackagesIndex::Describe(bool Short
) const
199 snprintf(S
,sizeof(S
),"%s",Info("Packages").c_str());
201 snprintf(S
,sizeof(S
),"%s (%s)",Info("Packages").c_str(),
202 IndexFile("Packages").c_str());
206 // PackagesIndex::Info - One liner describing the index URI /*{{{*/
207 // ---------------------------------------------------------------------
209 string
debPackagesIndex::Info(const char *Type
) const
211 string Info
= ::URI::SiteOnly(URI
) + ' ';
212 if (Dist
[Dist
.size() - 1] == '/')
218 Info
+= Dist
+ '/' + Section
;
224 // PackagesIndex::Index* - Return the URI to the index files /*{{{*/
225 // ---------------------------------------------------------------------
227 inline string
debPackagesIndex::IndexFile(const char *Type
) const
229 return _config
->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type
));
231 string
debPackagesIndex::IndexURI(const char *Type
) const
234 if (Dist
[Dist
.size() - 1] == '/')
242 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
243 "/binary-" + _config
->Find("APT::Architecture") + '/';
249 // PackagesIndex::GetIndexes - Fetch the index files /*{{{*/
250 // ---------------------------------------------------------------------
252 bool debPackagesIndex::GetIndexes(pkgAcquire
*Owner
) const
254 new pkgAcqIndex(Owner
,IndexURI("Packages"),Info("Packages"),"Packages");
255 new pkgAcqIndexRel(Owner
,IndexURI("Release"),Info("Release"),"Release");
259 // PackagesIndex::Exists - Check if the index is available /*{{{*/
260 // ---------------------------------------------------------------------
262 bool debPackagesIndex::Exists() const
264 return FileExists(IndexFile("Packages"));
267 // PackagesIndex::Size - Return the size of the index /*{{{*/
268 // ---------------------------------------------------------------------
269 /* This is really only used for progress reporting. */
270 unsigned long debPackagesIndex::Size() const
273 if (stat(IndexFile("Packages").c_str(),&S
) != 0)
278 // PackagesIndex::Merge - Load the index file into a cache /*{{{*/
279 // ---------------------------------------------------------------------
281 bool debPackagesIndex::Merge(pkgCacheGenerator
&Gen
,OpProgress
&Prog
) const
283 string PackageFile
= IndexFile("Packages");
284 FileFd
Pkg(PackageFile
,FileFd::ReadOnly
);
285 debListParser
Parser(&Pkg
);
286 if (_error
->PendingError() == true)
287 return _error
->Error("Problem opening %s",PackageFile
.c_str());
289 Prog
.SubProgress(0,Info("Packages"));
291 if (Gen
.SelectFile(PackageFile
,Tmp
.Host
,*this) == false)
292 return _error
->Error("Problem with SelectFile %s",PackageFile
.c_str());
294 // Store the IMS information
295 pkgCache::PkgFileIterator File
= Gen
.GetCurFile();
297 if (fstat(Pkg
.Fd(),&St
) != 0)
298 return _error
->Errno("fstat","Failed to stat");
299 File
->Size
= St
.st_size
;
300 File
->mtime
= St
.st_mtime
;
302 if (Gen
.MergeList(Parser
) == false)
303 return _error
->Error("Problem with MergeList %s",PackageFile
.c_str());
305 // Check the release file
306 string ReleaseFile
= IndexFile("Release");
307 if (FileExists(ReleaseFile
) == true)
309 FileFd
Rel(ReleaseFile
,FileFd::ReadOnly
);
310 if (_error
->PendingError() == true)
312 Parser
.LoadReleaseInfo(File
,Rel
);
318 // PackagesIndex::FindInCache - Find this index /*{{{*/
319 // ---------------------------------------------------------------------
321 pkgCache::PkgFileIterator
debPackagesIndex::FindInCache(pkgCache
&Cache
) const
323 string FileName
= IndexFile("Packages");
324 pkgCache::PkgFileIterator File
= Cache
.FileBegin();
325 for (; File
.end() == false; File
++)
327 if (FileName
!= File
.FileName())
331 if (stat(File
.FileName(),&St
) != 0)
332 return pkgCache::PkgFileIterator(Cache
);
333 if ((unsigned)St
.st_size
!= File
->Size
|| St
.st_mtime
!= File
->mtime
)
334 return pkgCache::PkgFileIterator(Cache
);
342 // StatusIndex::debStatusIndex - Constructor /*{{{*/
343 // ---------------------------------------------------------------------
345 debStatusIndex::debStatusIndex(string File
) : File(File
)
349 // StatusIndex::Size - Return the size of the index /*{{{*/
350 // ---------------------------------------------------------------------
352 unsigned long debStatusIndex::Size() const
355 if (stat(File
.c_str(),&S
) != 0)
360 // StatusIndex::Merge - Load the index file into a cache /*{{{*/
361 // ---------------------------------------------------------------------
363 bool debStatusIndex::Merge(pkgCacheGenerator
&Gen
,OpProgress
&Prog
) const
365 FileFd
Pkg(File
,FileFd::ReadOnly
);
366 if (_error
->PendingError() == true)
368 debListParser
Parser(&Pkg
);
369 if (_error
->PendingError() == true)
372 Prog
.SubProgress(0,File
);
373 if (Gen
.SelectFile(File
,string(),*this,pkgCache::Flag::NotSource
) == false)
374 return _error
->Error("Problem with SelectFile %s",File
.c_str());
376 // Store the IMS information
377 pkgCache::PkgFileIterator CFile
= Gen
.GetCurFile();
379 if (fstat(Pkg
.Fd(),&St
) != 0)
380 return _error
->Errno("fstat","Failed to stat");
381 CFile
->Size
= St
.st_size
;
382 CFile
->mtime
= St
.st_mtime
;
383 CFile
->Archive
= Gen
.WriteUniqString("now");
385 if (Gen
.MergeList(Parser
) == false)
386 return _error
->Error("Problem with MergeList %s",File
.c_str());
390 // StatusIndex::FindInCache - Find this index /*{{{*/
391 // ---------------------------------------------------------------------
393 pkgCache::PkgFileIterator
debStatusIndex::FindInCache(pkgCache
&Cache
) const
395 pkgCache::PkgFileIterator File
= Cache
.FileBegin();
396 for (; File
.end() == false; File
++)
398 if (this->File
!= File
.FileName())
402 if (stat(File
.FileName(),&St
) != 0)
403 return pkgCache::PkgFileIterator(Cache
);
404 if ((unsigned)St
.st_size
!= File
->Size
|| St
.st_mtime
!= File
->mtime
)
405 return pkgCache::PkgFileIterator(Cache
);
411 // StatusIndex::Exists - Check if the index is available /*{{{*/
412 // ---------------------------------------------------------------------
414 bool debStatusIndex::Exists() const
416 // Abort if the file does not exist.
421 // Source List types for Debian /*{{{*/
422 class debSLTypeDeb
: public pkgSourceList::Type
426 bool CreateItem(vector
<pkgIndexFile
*> &List
,string URI
,
427 string Dist
,string Section
,
428 pkgSourceList::Vendor
const *Vendor
) const
430 List
.push_back(new debPackagesIndex(URI
,Dist
,Section
));
437 Label
= "Standard Debian binary tree";
441 class debSLTypeDebSrc
: public pkgSourceList::Type
445 bool CreateItem(vector
<pkgIndexFile
*> &List
,string URI
,
446 string Dist
,string Section
,
447 pkgSourceList::Vendor
const *Vendor
) const
449 List
.push_back(new debSourcesIndex(URI
,Dist
,Section
));
456 Label
= "Standard Debian source tree";
460 debSLTypeDeb _apt_DebType
;
461 debSLTypeDebSrc _apt_DebSrcType
;
463 // Index File types for Debian /*{{{*/
464 class debIFTypeSrc
: public pkgIndexFile::Type
468 debIFTypeSrc() {Label
= "Debian Source Index";};
470 class debIFTypePkg
: public pkgIndexFile::Type
474 virtual pkgRecords::Parser
*CreatePkgParser(pkgCache::PkgFileIterator File
) const
476 return new debRecordParser(File
.FileName(),*File
.Cache());
478 debIFTypePkg() {Label
= "Debian Package Index";};
480 class debIFTypeStatus
: public pkgIndexFile::Type
484 virtual pkgRecords::Parser
*CreatePkgParser(pkgCache::PkgFileIterator File
) const
486 return new debRecordParser(File
.FileName(),*File
.Cache());
488 debIFTypeStatus() {Label
= "Debian dpkg status file";};
490 static debIFTypeSrc _apt_Src
;
491 static debIFTypePkg _apt_Pkg
;
492 static debIFTypeStatus _apt_Status
;
494 const pkgIndexFile::Type
*debSourcesIndex::GetType() const
498 const pkgIndexFile::Type
*debPackagesIndex::GetType() const
502 const pkgIndexFile::Type
*debStatusIndex::GetType() const