d9379a7267d94a6b290edf9527f0ba8fde872ff2
[apt.git] / apt-pkg / rpm / rpmindexfile.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description                                                          /*{{{*/
3 // $Id: rpmindexfile.cc,v 1.4 2002/11/27 16:22:40 niemeyer Exp $
4 /* ######################################################################
5
6    RPM Specific sources.list types and the three sorts of RPM
7    index files.
8    
9    ##################################################################### */
10                                                                         /*}}}*/
11 // Include Files                                                        /*{{{*/
12 #ifdef __GNUG__
13 #pragma implementation "apt-pkg/rpmindexfile.h"
14 #endif
15
16 #include <config.h>
17
18 #ifdef HAVE_RPM
19
20 #include <apt-pkg/rpmindexfile.h>
21 #include <apt-pkg/rpmsrcrecords.h>
22 #include <apt-pkg/rpmlistparser.h>
23 #include <apt-pkg/rpmrecords.h>
24 #include <apt-pkg/rpmsystem.h>
25 #include <apt-pkg/rpmhandler.h>
26 #include <apt-pkg/rpmpackagedata.h>
27 #include <apt-pkg/sourcelist.h>
28 #include <apt-pkg/configuration.h>
29 #include <apt-pkg/progress.h>
30 #include <apt-pkg/error.h>
31 #include <apt-pkg/strutl.h>
32 #include <apt-pkg/acquire-item.h>
33 #include <apt-pkg/repository.h>
34
35 #include <apti18n.h>
36
37 #include <sys/stat.h>
38                                                                         /*}}}*/
39 vector<pkgRepository *> RepList;
40
41 // rpmListIndex::Release* - Return the URI to the release file          /*{{{*/
42 // ---------------------------------------------------------------------
43 /* */
44 inline string rpmListIndex::ReleaseFile(string Type) const
45 {
46    return URItoFileName(ReleaseURI(Type));
47 }
48
49 string rpmListIndex::ReleaseURI(string Type) const
50 {
51    RPMPackageData *rpmdata = RPMPackageData::Singleton();
52    string Res;
53    if (Dist[Dist.size() - 1] == '/')
54    {
55       if (Dist != "/")
56          Res = URI + Dist;
57       else
58          Res = URI;
59    }
60    else
61       Res = URI + Dist + "/base/";
62
63    Res += Type;
64    
65    if (rpmdata->HasIndexTranslation() == true)
66    {
67       map<string,string> Dict;
68       Dict["uri"] = URI;
69       Dict["dist"] = Dist;
70       Dict["sect"] = "";
71       Dict["type"] = Type;
72       rpmdata->TranslateIndex(Res, Dict);
73    }
74
75    return Res;
76 }
77                                                                         /*}}}*/
78 // rpmListIndex::ReleaseInfo - One liner describing the index URI       /*{{{*/
79 // ---------------------------------------------------------------------
80 /* */
81 string rpmListIndex::ReleaseInfo(string Type) const 
82 {
83    string Info = ::URI::SiteOnly(URI) + ' ';
84    if (Dist[Dist.size() - 1] == '/')
85    {
86       if (Dist != "/")
87          Info += Dist;
88    }
89    else
90       Info += Dist;   
91    Info += " ";
92    Info += Type;
93    return Info;
94 }
95                                                                         /*}}}*/
96 // rpmListIndex::GetReleases - Fetch the index files                    /*{{{*/
97 // ---------------------------------------------------------------------
98 /* */
99 bool rpmListIndex::GetReleases(pkgAcquire *Owner) const
100 {
101    if (!Repository->Acquire)
102       return true;
103    Repository->Acquire = false;
104    new pkgAcqIndexRel(Owner,Repository,ReleaseURI("release"),
105                       ReleaseInfo("release"), "release", true);
106    return true;
107 }
108                                                                         /*}}}*/
109 // rpmListIndex::Info - One liner describing the index URI              /*{{{*/
110 // ---------------------------------------------------------------------
111 /* */
112 string rpmListIndex::Info(string Type) const 
113 {
114    string Info = ::URI::SiteOnly(URI) + ' ';
115    if (Dist[Dist.size() - 1] == '/')
116    {
117       if (Dist != "/")
118          Info += Dist;
119    }
120    else
121       Info += Dist + '/' + Section;   
122    Info += " ";
123    Info += Type;
124    return Info;
125 }
126                                                                         /*}}}*/
127 // rpmListIndex::Index* - Return the URI to the index files             /*{{{*/
128 // ---------------------------------------------------------------------
129 /* */
130 inline string rpmListIndex::IndexFile(string Type) const
131 {
132    return _config->FindDir("Dir::State::lists")+URItoFileName(IndexURI(Type));
133 }
134
135
136 string rpmListIndex::IndexURI(string Type) const
137 {
138    RPMPackageData *rpmdata = RPMPackageData::Singleton();
139    string Res;
140    if (Dist[Dist.size() - 1] == '/')
141    {
142       if (Dist != "/")
143          Res = URI + Dist;
144       else 
145          Res = URI;
146    }
147    else
148       Res = URI + Dist + "/base/";
149    
150    Res += Type + '.' + Section;
151
152    if (rpmdata->HasIndexTranslation() == true)
153    {
154       map<string,string> Dict;
155       Dict["uri"] = URI;
156       Dict["dist"] = Dist; 
157       Dict["sect"] = Section;
158       Dict["type"] = Type;
159       rpmdata->TranslateIndex(Res, Dict);
160    }
161
162    return Res;
163 }
164                                                                         /*}}}*/
165 // rpmListIndex::Exists - Check if the index is available               /*{{{*/
166 // ---------------------------------------------------------------------
167 /* */
168 bool rpmListIndex::Exists() const
169 {
170    return FileExists(IndexPath());
171 }
172                                                                         /*}}}*/
173 // rpmListIndex::Size - Return the size of the index                    /*{{{*/
174 // ---------------------------------------------------------------------
175 /* */
176 unsigned long rpmListIndex::Size() const
177 {
178    struct stat S;
179    if (stat(IndexPath().c_str(),&S) != 0)
180       return 0;
181    return S.st_size;
182 }
183                                                                         /*}}}*/
184 // rpmListIndex::Describe - Give a descriptive path to the index        /*{{{*/
185 // ---------------------------------------------------------------------
186 /* */
187 string rpmListIndex::Describe(bool Short) const
188 {
189    char S[300];
190    if (Short == true)
191       snprintf(S,sizeof(S),"%s",Info(MainType()).c_str());
192    else
193       snprintf(S,sizeof(S),"%s (%s)",Info(MainType()).c_str(),
194          IndexFile(MainType()).c_str());
195    return S;
196 }
197                                                                         /*}}}*/
198
199 // SrcListIndex::SourceInfo - Short 1 liner describing a source         /*{{{*/
200 // ---------------------------------------------------------------------
201 string rpmSrcListIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
202                                    pkgSrcRecords::File const &File) const
203 {
204    string Res;
205    Res = ::URI::SiteOnly(URI) + ' ';
206    if (Dist[Dist.size() - 1] == '/')
207    {
208       if (Dist != "/")
209          Res += Dist;
210    }      
211    else
212       Res += Dist + '/' + Section;
213    
214    Res += " ";
215    Res += Record.Package();
216    Res += " ";
217    Res += Record.Version();
218    if (File.Type.empty() == false)
219       Res += " (" + File.Type + ")";
220    return Res;
221 }
222                                                                         /*}}}*/
223 // SrcListIndex::ArchiveURI - URI for the archive                       /*{{{*/
224 // ---------------------------------------------------------------------
225 string rpmSrcListIndex::ArchiveURI(string File) const
226 {
227    RPMPackageData *rpmdata = RPMPackageData::Singleton();
228    string Res;
229    
230    if (Dist[Dist.size() - 1] == '/')
231    {
232       if (Dist != "/")
233          Res = URI + Dist;
234       else
235          Res = URI;
236    }
237    else
238       Res = URI + Dist;
239    
240    if (File.find("/") != string::npos)
241       Res += '/' + File;
242    else
243       Res += "/SRPMS."+Section + '/' + File;
244
245    if (rpmdata->HasSourceTranslation() == true)
246    {
247       map<string,string> Dict;
248       Dict["uri"] = URI;
249       Dict["dist"] = Dist; 
250       Dict["sect"] = Section;
251       string::size_type pos = File.rfind("/");
252       if (pos != string::npos)
253          Dict["file"] = string(File, pos+1);
254       else
255          Dict["file"] = File;
256       
257       rpmdata->TranslateSource(Res, Dict);
258    }
259          
260    return Res;
261 }
262                                                                         /*}}}*/
263 // SrcListIndex::CreateSrcParser - Get a parser for the source files    /*{{{*/
264 // ---------------------------------------------------------------------
265 /* */
266 pkgSrcRecords::Parser *rpmSrcListIndex::CreateSrcParser() const
267 {
268    return new rpmSrcRecordParser(IndexPath(), this);
269 }
270                                                                         /*}}}*/
271 // SrcListIndex::GetIndexes - Fetch the index files                     /*{{{*/
272 // ---------------------------------------------------------------------
273 /* */
274 bool rpmSrcListIndex::GetIndexes(pkgAcquire *Owner) const
275 {
276    // Ignore indexes for repositories that could not be authenticated
277    if (Repository->IsAuthenticated() == true && 
278        Repository->HasRelease() == false)
279       return true;
280    new pkgAcqIndex(Owner,Repository,IndexURI("srclist"),Info("srclist"),
281                    "srclist");
282    return true;
283 }
284                                                                         /*}}}*/
285
286 // PkgListIndex::ArchiveInfo - Short version of the archive url         /*{{{*/
287 // ---------------------------------------------------------------------
288 /* This is a shorter version that is designed to be < 60 chars or so */
289 string rpmPkgListIndex::ArchiveInfo(pkgCache::VerIterator Ver) const
290 {
291    string Res = ::URI::SiteOnly(URI) + ' ';
292    if (Dist[Dist.size() - 1] == '/')
293    {
294       if (Dist != "/")
295          Res += Dist;
296    }
297    else
298       Res += Dist + '/' + Section;
299    
300    Res += " ";
301    Res += Ver.ParentPkg().Name();
302    Res += " ";
303    Res += Ver.VerStr();
304    return Res;
305 }
306                                                                         /*}}}*/
307 // PkgListIndex::ArchiveURI - URI for the archive                       /*{{{*/
308 // ---------------------------------------------------------------------
309 string rpmPkgListIndex::ArchiveURI(string File) const
310 {
311    RPMPackageData *rpmdata = RPMPackageData::Singleton();
312    string Res;
313    if (Dist[Dist.size() - 1] == '/')
314    {
315       if (Dist != "/")
316          Res = URI + Dist;
317       else
318          Res = URI;
319    }
320    else
321       Res = URI + Dist;
322
323    if (File.find("/") != string::npos)
324       Res += '/' + File;
325    else
326       Res += "/RPMS." + Section + '/' + File;
327
328    if (rpmdata->HasBinaryTranslation() == true)
329    {
330       map<string,string> Dict;
331       Dict["uri"] = URI;
332       Dict["dist"] = Dist; 
333       Dict["sect"] = Section;
334       string::size_type pos = File.rfind("/");
335       if (pos != string::npos)
336          Dict["file"] = string(File, pos+1);
337       else
338          Dict["file"] = File;
339       rpmdata->TranslateBinary(Res, Dict);
340    }
341          
342    return Res;
343 }
344                                                                         /*}}}*/
345 // PkgListIndex::GetIndexes - Fetch the index files                     /*{{{*/
346 // ---------------------------------------------------------------------
347 /* */
348 bool rpmPkgListIndex::GetIndexes(pkgAcquire *Owner) const
349 {
350    // Ignore indexes for repositories that could not be authenticated
351    if (Repository->IsAuthenticated() == true && 
352        Repository->HasRelease() == false)
353       return true;
354    new pkgAcqIndex(Owner,Repository,IndexURI("pkglist"),Info("pkglist"),
355                    "pkglist");
356    new pkgAcqIndexRel(Owner,Repository,IndexURI("release"),Info("release"),
357                       "release");
358    return true;
359 }
360                                                                         /*}}}*/
361 // PkgListIndex::Merge - Load the index file into a cache               /*{{{*/
362 // ---------------------------------------------------------------------
363 /* */
364 bool rpmPkgListIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
365 {
366    string PackageFile = IndexPath();
367    RPMHandler *Handler = CreateHandler();
368
369    Prog.SubProgress(0,Info(MainType()));
370    ::URI Tmp(URI);
371    if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
372    {
373       delete Handler;
374       return _error->Error(_("Problem with SelectFile %s"),PackageFile.c_str());
375    }
376
377    // Store the IMS information
378    pkgCache::PkgFileIterator File = Gen.GetCurFile();
379    struct stat St;
380    if (stat(PackageFile.c_str(),&St) != 0) 
381    {
382       delete Handler;
383       return _error->Errno("stat",_("Failed to stat %s"), PackageFile.c_str());
384    }
385    File->Size = St.st_size;
386    File->mtime = St.st_mtime;
387    
388    rpmListParser Parser(Handler);
389    if (_error->PendingError() == true) 
390    {
391       delete Handler;
392       return _error->Error(_("Problem opening %s"),PackageFile.c_str());
393    }
394    
395    if (Gen.MergeList(Parser) == false)
396    {
397       delete Handler;
398       return _error->Error(_("Problem with MergeList %s"),PackageFile.c_str());
399    }
400    
401    delete Handler;
402
403    // Check the release file
404    string RelFile = ReleasePath();
405    if (FileExists(RelFile) == true)
406    {
407       FileFd Rel(RelFile,FileFd::ReadOnly);
408       if (_error->PendingError() == true)
409          return false;
410       Parser.LoadReleaseInfo(File,Rel);
411       Rel.Seek(0);
412    }
413
414    return true;
415 }
416                                                                         /*}}}*/
417 // PkgListIndex::MergeFileProvides - Process file dependencies if any   /*{{{*/
418 // ---------------------------------------------------------------------
419 /* */
420 bool rpmPkgListIndex::MergeFileProvides(pkgCacheGenerator &Gen,
421                                         OpProgress &Prog) const
422 {
423    string PackageFile = IndexPath();
424    RPMHandler *Handler = CreateHandler();
425    rpmListParser Parser(Handler);
426    if (_error->PendingError() == true) {
427       delete Handler;
428       return _error->Error(_("Problem opening %s"),PackageFile.c_str());
429    }
430    // We call SubProgress with Size(), since we won't call SelectFile() here.
431    Prog.SubProgress(Size(),Info("pkglist"));
432    if (Gen.MergeFileProvides(Parser) == false)
433       return _error->Error(_("Problem with MergeFileProvides %s"),
434                            PackageFile.c_str());
435    delete Handler;
436    return true;
437 }
438                                                                         /*}}}*/
439 // PkgListIndex::FindInCache - Find this index                          /*{{{*/
440 // ---------------------------------------------------------------------
441 /* */
442 pkgCache::PkgFileIterator rpmPkgListIndex::FindInCache(pkgCache &Cache) const
443 {
444    string FileName = IndexPath();
445    pkgCache::PkgFileIterator File = Cache.FileBegin();
446    for (; File.end() == false; File++)
447    {
448       if (FileName != File.FileName())
449          continue;
450       
451       struct stat St;
452       if (stat(File.FileName(),&St) != 0)
453          return pkgCache::PkgFileIterator(Cache);
454
455       if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
456          return pkgCache::PkgFileIterator(Cache);
457       return File;
458    }
459    
460    return File;
461 }
462                                                                         /*}}}*/
463
464 // PkgDirIndex::Index* - Return the URI to the index files              /*{{{*/
465 // ---------------------------------------------------------------------
466 /* */
467 string rpmPkgDirIndex::IndexPath() const
468 {
469    return ::URI(ArchiveURI("")).Path;
470 }
471                                                                         /*}}}*/
472 // PkgDirIndex::Release* - Return the URI to the index files            /*{{{*/
473 // ---------------------------------------------------------------------
474 /* */
475 string rpmPkgDirIndex::ReleasePath() const
476 {
477    return ::URI(IndexURI("release")).Path;
478 }
479                                                                         /*}}}*/
480 // PkgDirIndex::Size - Return the size of the index                     /*{{{*/
481 // ---------------------------------------------------------------------
482 /* This is really only used for progress reporting. */
483 unsigned long rpmPkgDirIndex::Size() const
484 {
485    // XXX: Must optimize this somehow.
486    RPMHandler *Handler = CreateHandler();
487    unsigned long Res = Handler->Size();
488    delete Handler;
489    return Res;
490 }
491                                                                         /*}}}*/
492
493 // SrcDirIndex::Index* - Return the URI to the index files              /*{{{*/
494 // ---------------------------------------------------------------------
495 /* */
496 string rpmSrcDirIndex::IndexPath() const
497 {
498    return ::URI(ArchiveURI("")).Path;
499 }
500                                                                         /*}}}*/
501 // SrcDirIndex::Size - Return the size of the index                     /*{{{*/
502 // ---------------------------------------------------------------------
503 /* This is really only used for progress reporting. */
504 unsigned long rpmSrcDirIndex::Size() const
505 {
506    // XXX: Must optimize this somehow.
507    RPMHandler *Handler = CreateHandler();
508    unsigned long Res = Handler->Size();
509    delete Handler;
510    return Res;
511 }
512
513 // SinglePkgIndex::ArchiveURI - URI for the archive                     /*{{{*/
514 // ---------------------------------------------------------------------
515 string rpmSinglePkgIndex::ArchiveURI(string File) const
516 {
517    char *cwd = getcwd(NULL,0);
518    if (File[0] == '.' && File[1] == '/')
519       File = string(File, 2);
520    string URI = "file://"+flCombine(cwd, File);
521    free(cwd);
522    return URI;
523 }
524                                                                         /*}}}*/
525 // SinglePkgIndex::ArchiveURI - URI for the archive                     /*{{{*/
526 // ---------------------------------------------------------------------
527 string rpmSingleSrcIndex::ArchiveURI(string File) const
528 {
529    char *cwd = getcwd(NULL,0);
530    if (File[0] == '.' && File[1] == '/')
531       File = string(File, 2);
532    string URI = "file://"+flCombine(cwd, File);
533    free(cwd);
534    return URI;
535 }
536                                                                         /*}}}*/
537
538 // DatabaseIndex::rpmDatabaseIndex - Constructor                        /*{{{*/
539 // ---------------------------------------------------------------------
540 /* */
541 rpmDatabaseIndex::rpmDatabaseIndex()
542 {
543 }
544                                                                         /*}}}*/
545 // DatabaseIndex::Size - Return the size of the index                   /*{{{*/
546 // ---------------------------------------------------------------------
547 /* */
548 unsigned long rpmDatabaseIndex::Size() const
549 {
550    return rpmSys.GetDBHandler()->Size();
551 }
552                                                                         /*}}}*/
553 // DatabaseIndex::CreateHandler - Create a RPMHandler for this file     /*{{{*/
554 // ---------------------------------------------------------------------
555 RPMHandler *rpmDatabaseIndex::CreateHandler() const
556 {
557    return rpmSys.GetDBHandler();
558 }
559                                                                         /*}}}*/
560 // DatabaseIndex::Merge - Load the index file into a cache              /*{{{*/
561 // ---------------------------------------------------------------------
562 /* */
563 bool rpmDatabaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
564 {
565    RPMDBHandler *Handler = rpmSys.GetDBHandler();
566    rpmListParser Parser(Handler);
567    if (_error->PendingError() == true)
568       return _error->Error(_("Problem opening RPM database"));
569    
570    Prog.SubProgress(0,"RPM Database");
571    if (Gen.SelectFile(Handler->DataPath(false),string(),*this,pkgCache::Flag::NotSource) == false)
572       return _error->Error(_("Problem with SelectFile RPM Database"));
573
574    // Store the IMS information
575    pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
576    struct stat St;
577    if (stat(Handler->DataPath(false).c_str(),&St) != 0)
578       return _error->Errno("fstat",_("Failed to stat %s"), Handler->DataPath(false).c_str());
579    CFile->Size = St.st_size;
580    CFile->mtime = Handler->Mtime();
581    
582    if (Gen.MergeList(Parser) == false)
583       return _error->Error(_("Problem with MergeList %s"),
584                            Handler->DataPath(false).c_str());
585    return true;
586 }
587                                                                         /*}}}*/
588 // DatabaseIndex::MergeFileProvides - Process file dependencies if any  /*{{{*/
589 // ---------------------------------------------------------------------
590 /* */
591 bool rpmDatabaseIndex::MergeFileProvides(pkgCacheGenerator &Gen,
592                                          OpProgress &Prog) const
593 {
594    RPMDBHandler *Handler = rpmSys.GetDBHandler();
595    rpmListParser Parser(Handler);
596    if (_error->PendingError() == true)
597       return _error->Error(_("Problem opening RPM database"));
598    // We call SubProgress with Size(), since we won't call SelectFile() here.
599    Prog.SubProgress(Size(),"RPM Database");
600    if (Gen.MergeFileProvides(Parser) == false)
601       return _error->Error(_("Problem with MergeFileProvides %s"),
602                            Handler->DataPath(false).c_str());
603    return true;
604 }
605                                                                         /*}}}*/
606 // DatabaseIndex::FindInCache - Find this index                         /*{{{*/
607 // ---------------------------------------------------------------------
608 /* */
609 pkgCache::PkgFileIterator rpmDatabaseIndex::FindInCache(pkgCache &Cache) const
610 {
611    pkgCache::PkgFileIterator File = Cache.FileBegin();
612    for (; File.end() == false; File++)
613    {
614       if (rpmSys.GetDBHandler()->DataPath(false) != File.FileName())
615          continue;
616       struct stat St;
617       if (stat(File.FileName(),&St) != 0)
618          return pkgCache::PkgFileIterator(Cache);
619       if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
620          return pkgCache::PkgFileIterator(Cache);
621       return File;
622    }   
623    return File;
624 }
625                                                                         /*}}}*/
626
627 // Source List types for rpm                                            /*{{{*/
628
629 class rpmSLTypeGen : public pkgSourceList::Type
630 {
631    public:
632
633    rpmSLTypeGen()
634    {
635       Name = "rpm";
636       Label = "Standard RPM source tree";
637    }   
638
639    pkgRepository *FindRepository(string URI,string Dist,
640                                  const pkgSourceList::Vendor *Vendor) const
641    {
642       for (vector<pkgRepository *>::const_iterator iter = RepList.begin();
643            iter != RepList.end(); iter++) 
644       {
645          if ((*iter)->URI == URI && (*iter)->Dist == Dist) 
646          {       
647             if (Vendor != NULL)
648                (*iter)->FingerPrint = Vendor->FingerPrint;
649             return *iter;
650          }
651       }
652       return NULL;
653    }
654
655    pkgRepository *GetRepository(string URI,string Dist,
656                                 const pkgSourceList::Vendor *Vendor) const
657    {
658       pkgRepository *Rep = FindRepository(URI,Dist,Vendor);
659       if (Rep != NULL)
660          return Rep;
661
662       string BaseURI;
663       if (Dist[Dist.size() - 1] == '/')
664       {
665          if (Dist != "/")
666             BaseURI = URI + Dist;
667          else 
668             BaseURI = URI + '/';
669       }
670       else
671          BaseURI = URI + Dist + '/';
672
673       Rep = new pkgRepository(URI,Dist,Vendor,BaseURI);
674       RepList.push_back(Rep);
675       return Rep;
676    }
677 };
678
679
680 class rpmSLTypeRpm : public rpmSLTypeGen
681 {
682    public:
683
684    bool CreateItem(vector<pkgIndexFile *> &List,
685                    string URI, string Dist, string Section,
686                    pkgSourceList::Vendor const *Vendor) const 
687    {
688       pkgRepository *Rep = GetRepository(URI,Dist,Vendor);
689       List.push_back(new rpmPkgListIndex(URI,Dist,Section,Rep));
690       return true;
691    };
692
693    rpmSLTypeRpm()
694    {
695       Name = "rpm";
696       Label = "Standard RPM binary tree";
697    }   
698 };
699
700 class rpmSLTypeSrpm : public rpmSLTypeGen
701 {
702    public:
703
704    bool CreateItem(vector<pkgIndexFile *> &List,
705                    string URI, string Dist, string Section,
706                    pkgSourceList::Vendor const *Vendor) const 
707    {
708       pkgRepository *Rep = GetRepository(URI,Dist,Vendor);
709       List.push_back(new rpmSrcListIndex(URI,Dist,Section,Rep));
710       return true;
711    };  
712    
713    rpmSLTypeSrpm()
714    {
715       Name = "rpm-src";
716       Label = "Standard RPM source tree";
717    }   
718 };
719
720 class rpmSLTypeRpmDir : public rpmSLTypeGen
721 {
722    public:
723
724    bool CreateItem(vector<pkgIndexFile *> &List,
725                    string URI, string Dist, string Section,
726                    pkgSourceList::Vendor const *Vendor) const 
727    {
728       pkgRepository *Rep = GetRepository(URI,Dist,Vendor);
729       List.push_back(new rpmPkgDirIndex(URI,Dist,Section,Rep));
730       return true;
731    };
732
733    rpmSLTypeRpmDir()
734    {
735       Name = "rpm-dir";
736       Label = "Local RPM directory tree";
737    }   
738 };
739
740 class rpmSLTypeSrpmDir : public rpmSLTypeGen
741 {
742    public:
743
744    bool CreateItem(vector<pkgIndexFile *> &List,
745                    string URI, string Dist, string Section,
746                    pkgSourceList::Vendor const *Vendor) const 
747    {
748       pkgRepository *Rep = GetRepository(URI,Dist,Vendor);
749       List.push_back(new rpmSrcDirIndex(URI,Dist,Section,Rep));
750       return true;
751    };
752
753    rpmSLTypeSrpmDir()
754    {
755       Name = "rpm-src-dir";
756       Label = "Local SRPM directory tree";
757    }   
758 };
759
760 rpmSLTypeRpm _apt_rpmType;
761 rpmSLTypeSrpm _apt_rpmSrcType;
762 rpmSLTypeRpmDir _apt_rpmDirType;
763 rpmSLTypeSrpmDir _apt_rpmSrcDirType;
764                                                                         /*}}}*/
765 // Index File types for rpm                                             /*{{{*/
766 class rpmIFTypeSrc : public pkgIndexFile::Type
767 {
768    public:
769    
770    rpmIFTypeSrc() {Label = "RPM Source Index";};
771 };
772 class rpmIFTypePkg : public pkgIndexFile::Type
773 {
774    public:
775    
776    virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
777    {
778       return new rpmRecordParser(File.FileName(),*File.Cache());
779    };
780    rpmIFTypePkg() {Label = "RPM Package Index";};
781 };
782 class rpmIFTypeDatabase : public pkgIndexFile::Type
783 {
784    public:
785    
786    virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
787    {
788       return new rpmRecordParser(File.FileName(),*File.Cache());
789    };
790    rpmIFTypeDatabase() {Label = "RPM Database";};
791 };
792 static rpmIFTypeSrc _apt_Src;
793 static rpmIFTypePkg _apt_Pkg;
794 static rpmIFTypeDatabase _apt_DB;
795
796 const pkgIndexFile::Type *rpmSrcListIndex::GetType() const
797 {
798    return &_apt_Src;
799 }
800 const pkgIndexFile::Type *rpmPkgListIndex::GetType() const
801 {
802    return &_apt_Pkg;
803 }
804 const pkgIndexFile::Type *rpmSrcDirIndex::GetType() const
805 {
806    return &_apt_Src;
807 }
808 const pkgIndexFile::Type *rpmPkgDirIndex::GetType() const
809 {
810    return &_apt_Pkg;
811 }
812 const pkgIndexFile::Type *rpmSinglePkgIndex::GetType() const
813 {
814    return &_apt_Pkg;
815 }
816 const pkgIndexFile::Type *rpmSingleSrcIndex::GetType() const
817 {
818    return &_apt_Src;
819 }
820 const pkgIndexFile::Type *rpmDatabaseIndex::GetType() const
821 {
822    return &_apt_DB;
823 }
824
825                                                                         /*}}}*/
826 #endif /* HAVE_RPM */
827
828 // vim:sts=3:sw=3