1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debindexfile.cc,v 1.3 2001/02/23 06:41:55 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() const
80 snprintf(S
,sizeof(S
),"%s (%s)",Info("Packages").c_str(),
81 IndexFile("Sources").c_str());
85 // SourcesIndex::Info - One liner describing the index URI /*{{{*/
86 // ---------------------------------------------------------------------
88 string
debSourcesIndex::Info(const char *Type
) const
90 string Info
= ::URI::SiteOnly(URI
) + ' ';
91 if (Dist
[Dist
.size() - 1] == '/')
97 Info
+= Dist
+ '/' + Section
;
103 // SourcesIndex::Index* - Return the URI to the index files /*{{{*/
104 // ---------------------------------------------------------------------
106 inline string
debSourcesIndex::IndexFile(const char *Type
) const
108 return URItoFileName(IndexURI(Type
));
110 string
debSourcesIndex::IndexURI(const char *Type
) const
113 if (Dist
[Dist
.size() - 1] == '/')
121 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
128 // SourcesIndex::GetIndexes - Fetch the index files /*{{{*/
129 // ---------------------------------------------------------------------
131 bool debSourcesIndex::GetIndexes(pkgAcquire
*Owner
) const
133 new pkgAcqIndex(Owner
,IndexURI("Sources"),Info("Sources"),"Sources");
134 new pkgAcqIndexRel(Owner
,IndexURI("Release"),Info("Release"),"Release");
138 // SourcesIndex::Exists - Check if the index is available /*{{{*/
139 // ---------------------------------------------------------------------
141 bool debSourcesIndex::Exists() const
143 return FileExists(IndexFile("Sources"));
146 // SourcesIndex::Size - Return the size of the index /*{{{*/
147 // ---------------------------------------------------------------------
149 unsigned long debSourcesIndex::Size() const
152 if (stat(IndexFile("Sources").c_str(),&S
) != 0)
158 // PackagesIndex::debPackagesIndex - Contructor /*{{{*/
159 // ---------------------------------------------------------------------
161 debPackagesIndex::debPackagesIndex(string URI
,string Dist
,string Section
) :
162 URI(URI
), Dist(Dist
), Section(Section
)
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
171 string Res
= ::URI::SiteOnly(URI
) + ' ';
172 if (Dist
[Dist
.size() - 1] == '/')
178 Res
+= Dist
+ '/' + Section
;
181 Res
+= Ver
.ParentPkg().Name();
187 // PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/
188 // ---------------------------------------------------------------------
189 /* This should help the user find the index in the sources.list and
190 in the filesystem for problem solving */
191 string
debPackagesIndex::Describe() const
194 snprintf(S
,sizeof(S
),"%s (%s)",Info("Packages").c_str(),
195 IndexFile("Packages").c_str());
199 // PackagesIndex::Info - One liner describing the index URI /*{{{*/
200 // ---------------------------------------------------------------------
202 string
debPackagesIndex::Info(const char *Type
) const
204 string Info
= ::URI::SiteOnly(URI
) + ' ';
205 if (Dist
[Dist
.size() - 1] == '/')
211 Info
+= Dist
+ '/' + Section
;
217 // PackagesIndex::Index* - Return the URI to the index files /*{{{*/
218 // ---------------------------------------------------------------------
220 inline string
debPackagesIndex::IndexFile(const char *Type
) const
222 return _config
->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type
));
224 string
debPackagesIndex::IndexURI(const char *Type
) const
227 if (Dist
[Dist
.size() - 1] == '/')
235 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
236 "/binary-" + _config
->Find("APT::Architecture") + '/';
242 // PackagesIndex::GetIndexes - Fetch the index files /*{{{*/
243 // ---------------------------------------------------------------------
245 bool debPackagesIndex::GetIndexes(pkgAcquire
*Owner
) const
247 new pkgAcqIndex(Owner
,IndexURI("Packages"),Info("Packages"),"Packages");
248 new pkgAcqIndexRel(Owner
,IndexURI("Release"),Info("Release"),"Release");
252 // PackagesIndex::Exists - Check if the index is available /*{{{*/
253 // ---------------------------------------------------------------------
255 bool debPackagesIndex::Exists() const
257 return FileExists(IndexFile("Packages"));
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
266 if (stat(IndexFile("Packages").c_str(),&S
) != 0)
271 // PackagesIndex::Merge - Load the index file into a cache /*{{{*/
272 // ---------------------------------------------------------------------
274 bool debPackagesIndex::Merge(pkgCacheGenerator
&Gen
,OpProgress
&Prog
) const
276 string PackageFile
= IndexFile("Packages");
277 FileFd
Pkg(PackageFile
,FileFd::ReadOnly
);
278 debListParser
Parser(&Pkg
);
279 if (_error
->PendingError() == true)
280 return _error
->Error("Problem opening %s",PackageFile
.c_str());
282 Prog
.SubProgress(0,Info("Packages"));
284 if (Gen
.SelectFile(PackageFile
,Tmp
.Host
,*this) == false)
285 return _error
->Error("Problem with SelectFile %s",PackageFile
.c_str());
287 // Store the IMS information
288 pkgCache::PkgFileIterator File
= Gen
.GetCurFile();
290 if (fstat(Pkg
.Fd(),&St
) != 0)
291 return _error
->Errno("fstat","Failed to stat");
292 File
->Size
= St
.st_size
;
293 File
->mtime
= St
.st_mtime
;
295 if (Gen
.MergeList(Parser
) == false)
296 return _error
->Error("Problem with MergeList %s",PackageFile
.c_str());
298 // Check the release file
299 string ReleaseFile
= IndexFile("Release");
300 if (FileExists(ReleaseFile
) == true)
302 FileFd
Rel(ReleaseFile
,FileFd::ReadOnly
);
303 if (_error
->PendingError() == true)
305 Parser
.LoadReleaseInfo(File
,Rel
);
311 // PackagesIndex::FindInCache - Find this index /*{{{*/
312 // ---------------------------------------------------------------------
314 pkgCache::PkgFileIterator
debPackagesIndex::FindInCache(pkgCache
&Cache
) const
316 string FileName
= IndexFile("Packages");
317 pkgCache::PkgFileIterator File
= Cache
.FileBegin();
318 for (; File
.end() == false; File
++)
320 if (FileName
!= File
.FileName())
324 if (stat(File
.FileName(),&St
) != 0)
325 return pkgCache::PkgFileIterator(Cache
);
326 if ((unsigned)St
.st_size
!= File
->Size
|| St
.st_mtime
!= File
->mtime
)
327 return pkgCache::PkgFileIterator(Cache
);
335 // StatusIndex::debStatusIndex - Constructor /*{{{*/
336 // ---------------------------------------------------------------------
338 debStatusIndex::debStatusIndex(string File
) : File(File
)
342 // StatusIndex::Size - Return the size of the index /*{{{*/
343 // ---------------------------------------------------------------------
345 unsigned long debStatusIndex::Size() const
348 if (stat(File
.c_str(),&S
) != 0)
353 // StatusIndex::Merge - Load the index file into a cache /*{{{*/
354 // ---------------------------------------------------------------------
356 bool debStatusIndex::Merge(pkgCacheGenerator
&Gen
,OpProgress
&Prog
) const
358 FileFd
Pkg(File
,FileFd::ReadOnly
);
359 if (_error
->PendingError() == true)
361 debListParser
Parser(&Pkg
);
362 if (_error
->PendingError() == true)
365 Prog
.SubProgress(0,File
);
366 if (Gen
.SelectFile(File
,string(),*this,pkgCache::Flag::NotSource
) == false)
367 return _error
->Error("Problem with SelectFile %s",File
.c_str());
369 // Store the IMS information
370 pkgCache::PkgFileIterator CFile
= Gen
.GetCurFile();
372 if (fstat(Pkg
.Fd(),&St
) != 0)
373 return _error
->Errno("fstat","Failed to stat");
374 CFile
->Size
= St
.st_size
;
375 CFile
->mtime
= St
.st_mtime
;
376 CFile
->Archive
= Gen
.WriteUniqString("now");
378 if (Gen
.MergeList(Parser
) == false)
379 return _error
->Error("Problem with MergeList %s",File
.c_str());
383 // StatusIndex::FindInCache - Find this index /*{{{*/
384 // ---------------------------------------------------------------------
386 pkgCache::PkgFileIterator
debStatusIndex::FindInCache(pkgCache
&Cache
) const
388 pkgCache::PkgFileIterator File
= Cache
.FileBegin();
389 for (; File
.end() == false; File
++)
391 if (this->File
!= File
.FileName())
395 if (stat(File
.FileName(),&St
) != 0)
396 return pkgCache::PkgFileIterator(Cache
);
397 if ((unsigned)St
.st_size
!= File
->Size
|| St
.st_mtime
!= File
->mtime
)
398 return pkgCache::PkgFileIterator(Cache
);
404 // StatusIndex::Exists - Check if the index is available /*{{{*/
405 // ---------------------------------------------------------------------
407 bool debStatusIndex::Exists() const
409 // Abort if the file does not exist.
414 // Source List types for Debian /*{{{*/
415 class debSLTypeDeb
: public pkgSourceList::Type
419 bool CreateItem(vector
<pkgIndexFile
*> &List
,string URI
,
420 string Dist
,string Section
) const
422 List
.push_back(new debPackagesIndex(URI
,Dist
,Section
));
429 Label
= "Standard Debian binary tree";
433 class debSLTypeDebSrc
: public pkgSourceList::Type
437 bool CreateItem(vector
<pkgIndexFile
*> &List
,string URI
,
438 string Dist
,string Section
) const
440 List
.push_back(new debSourcesIndex(URI
,Dist
,Section
));
447 Label
= "Standard Debian source tree";
451 debSLTypeDeb _apt_DebType
;
452 debSLTypeDebSrc _apt_DebSrcType
;
454 // Index File types for Debian /*{{{*/
455 class debIFTypeSrc
: public pkgIndexFile::Type
459 debIFTypeSrc() {Label
= "Debian Source Index";};
461 class debIFTypePkg
: public pkgIndexFile::Type
465 virtual pkgRecords::Parser
*CreatePkgParser(pkgCache::PkgFileIterator File
) const
467 return new debRecordParser(File
.FileName(),*File
.Cache());
469 debIFTypePkg() {Label
= "Debian Package Index";};
471 class debIFTypeStatus
: public pkgIndexFile::Type
475 virtual pkgRecords::Parser
*CreatePkgParser(pkgCache::PkgFileIterator File
) const
477 return new debRecordParser(File
.FileName(),*File
.Cache());
479 debIFTypeStatus() {Label
= "Debian dpkg status file";};
481 static debIFTypeSrc _apt_Src
;
482 static debIFTypePkg _apt_Pkg
;
483 static debIFTypeStatus _apt_Status
;
485 const pkgIndexFile::Type
*debSourcesIndex::GetType() const
489 const pkgIndexFile::Type
*debPackagesIndex::GetType() const
493 const pkgIndexFile::Type
*debStatusIndex::GetType() const