3 #include <apt-pkg/debmetaindex.h> 
   4 #include <apt-pkg/debindexfile.h> 
   5 #include <apt-pkg/strutl.h> 
   6 #include <apt-pkg/fileutl.h> 
   7 #include <apt-pkg/acquire-item.h> 
   8 #include <apt-pkg/configuration.h> 
   9 #include <apt-pkg/aptconfiguration.h> 
  10 #include <apt-pkg/indexrecords.h> 
  11 #include <apt-pkg/sourcelist.h> 
  12 #include <apt-pkg/hashes.h> 
  13 #include <apt-pkg/macros.h> 
  14 #include <apt-pkg/metaindex.h> 
  26 string 
debReleaseIndex::Info(const char *Type
, string 
const &Section
, string 
const &Arch
) const 
  28    string Info 
= ::URI::SiteOnly(URI
) + ' '; 
  29    if (Dist
[Dist
.size() - 1] == '/') 
  36       Info 
+= Dist 
+ '/' + Section
; 
  37       if (Arch
.empty() != true) 
  45 string 
debReleaseIndex::MetaIndexInfo(const char *Type
) const 
  47    string Info 
= ::URI::SiteOnly(URI
) + ' '; 
  48    if (Dist
[Dist
.size() - 1] == '/') 
  60 string 
debReleaseIndex::MetaIndexFile(const char *Type
) const 
  62    return _config
->FindDir("Dir::State::lists") + 
  63       URItoFileName(MetaIndexURI(Type
)); 
  66 string 
debReleaseIndex::MetaIndexURI(const char *Type
) const 
  72    else if (Dist
[Dist
.size()-1] == '/') 
  75       Res 
= URI 
+ "dists/" + Dist 
+ "/"; 
  81 std::string 
debReleaseIndex::LocalFileName() const 
  83    // see if we have a InRelease file 
  84    std::string PathInRelease 
=  MetaIndexFile("InRelease"); 
  85    if (FileExists(PathInRelease
)) 
  88    // and if not return the normal one 
  89    if (FileExists(PathInRelease
)) 
  90       return MetaIndexFile("Release"); 
  95 string 
debReleaseIndex::IndexURISuffix(const char *Type
, string 
const &Section
, string 
const &Arch
) const 
  98    if (Dist
[Dist
.size() - 1] != '/') 
 100       if (Arch 
== "native") 
 101          Res 
+= Section 
+ "/binary-" + _config
->Find("APT::Architecture") + '/'; 
 103          Res 
+= Section 
+ "/binary-" + Arch 
+ '/'; 
 109 string 
debReleaseIndex::IndexURI(const char *Type
, string 
const &Section
, string 
const &Arch
) const 
 111    if (Dist
[Dist
.size() - 1] == '/') 
 121       return URI 
+ "dists/" + Dist 
+ '/' + IndexURISuffix(Type
, Section
, Arch
); 
 124 string 
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string 
&Section
) const 
 127    if (Dist
[Dist
.size() - 1] != '/') 
 128       Res 
+= Section 
+ "/source/"; 
 132 string 
debReleaseIndex::SourceIndexURI(const char *Type
, const string 
&Section
) const 
 135    if (Dist
[Dist
.size() - 1] == '/') 
 144       return URI 
+ "dists/" + Dist 
+ "/" + SourceIndexURISuffix(Type
, Section
); 
 147 string 
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string 
&Section
) const 
 150    if (Dist
[Dist
.size() - 1] != '/') 
 151       Res 
+= Section 
+ "/i18n/Translation-"; 
 155 string 
debReleaseIndex::TranslationIndexURI(const char *Type
, const string 
&Section
) const 
 158    if (Dist
[Dist
.size() - 1] == '/') 
 167       return URI 
+ "dists/" + Dist 
+ "/" + TranslationIndexURISuffix(Type
, Section
); 
 170 debReleaseIndex::debReleaseIndex(string 
const &URI
, string 
const &Dist
) : 
 171                                         metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
) 
 174 debReleaseIndex::debReleaseIndex(string 
const &URI
, string 
const &Dist
, bool const Trusted
) : 
 175                                         metaIndex(URI
, Dist
, "deb") { 
 179 debReleaseIndex::~debReleaseIndex() { 
 180         for (map
<string
, vector
<debSectionEntry 
const*> >::const_iterator A 
= ArchEntries
.begin(); 
 181              A 
!= ArchEntries
.end(); ++A
) 
 182                 for (vector
<const debSectionEntry 
*>::const_iterator S 
= A
->second
.begin(); 
 183                      S 
!= A
->second
.end(); ++S
) 
 187 vector 
<IndexTarget 
*>* debReleaseIndex::ComputeIndexTargets() const { 
 188         vector 
<IndexTarget 
*>* IndexTargets 
= new vector 
<IndexTarget 
*>; 
 190         map
<string
, vector
<debSectionEntry 
const*> >::const_iterator 
const src 
= ArchEntries
.find("source"); 
 191         if (src 
!= ArchEntries
.end()) { 
 192                 vector
<debSectionEntry 
const*> const SectionEntries 
= src
->second
; 
 193                 for (vector
<debSectionEntry 
const*>::const_iterator I 
= SectionEntries
.begin(); 
 194                      I 
!= SectionEntries
.end(); ++I
) { 
 195                         char const * const ShortDesc 
= "Sources"; 
 196                         IndexTarget 
* const Target 
= new IndexTarget( 
 197                               SourceIndexURISuffix(ShortDesc
, (*I
)->Section
), 
 199                               Info(ShortDesc
, (*I
)->Section
), 
 200                               SourceIndexURI(ShortDesc
, (*I
)->Section
) 
 202                         IndexTargets
->push_back (Target
); 
 206         // Only source release 
 207         if (IndexTargets
->empty() == false && ArchEntries
.size() == 1) 
 210         std::set
<std::string
> sections
; 
 211         for (map
<string
, vector
<debSectionEntry 
const*> >::const_iterator a 
= ArchEntries
.begin(); 
 212              a 
!= ArchEntries
.end(); ++a
) { 
 213                 if (a
->first 
== "source") 
 215                 for (vector 
<const debSectionEntry 
*>::const_iterator I 
= a
->second
.begin(); 
 216                      I 
!= a
->second
.end(); ++I
) { 
 217                         char const * const ShortDesc 
= "Packages"; 
 218                         IndexTarget 
* const Target 
= new IndexTarget( 
 219                               IndexURISuffix(ShortDesc
, (*I
)->Section
, a
->first
), 
 221                               Info (ShortDesc
, (*I
)->Section
, a
->first
), 
 222                               IndexURI(ShortDesc
, (*I
)->Section
, a
->first
) 
 224                         IndexTargets
->push_back (Target
); 
 225                         sections
.insert((*I
)->Section
); 
 229         std::vector
<std::string
> lang 
= APT::Configuration::getLanguages(true); 
 230         std::vector
<std::string
>::iterator lend 
= std::remove(lang
.begin(), lang
.end(), "none"); 
 231         if (lend 
!= lang
.end()) 
 234         if (lang
.empty() == true) 
 237         // get the Translation-* files, later we will skip download of non-existent if we have an index 
 238         for (std::set
<std::string
>::const_iterator s 
= sections
.begin(); 
 239              s 
!= sections
.end(); ++s
) { 
 240                 for (std::vector
<std::string
>::const_iterator l 
= lang
.begin(); 
 241                      l 
!= lang
.end(); ++l
) { 
 242                         std::string 
const ShortDesc 
= "Translation-" + *l
; 
 243                         IndexTarget 
* const Target 
= new OptionalIndexTarget( 
 244                               TranslationIndexURISuffix(l
->c_str(), *s
), 
 246                               Info (ShortDesc
.c_str(), *s
), 
 247                               TranslationIndexURI(l
->c_str(), *s
) 
 249                         IndexTargets
->push_back(Target
); 
 256 bool debReleaseIndex::GetIndexes(pkgAcquire 
*Owner
, bool const &GetAll
) const 
 258    indexRecords 
* const iR 
= new indexRecords(Dist
); 
 259    if (Trusted 
== ALWAYS_TRUSTED
) 
 260       iR
->SetTrusted(true); 
 261    else if (Trusted 
== NEVER_TRUSTED
) 
 262       iR
->SetTrusted(false); 
 264    // special case for --print-uris 
 265    vector 
<IndexTarget 
*> const * const targets 
= ComputeIndexTargets(); 
 266 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X)) 
 267    pkgAcqMetaBase 
* const TransactionManager 
= new pkgAcqMetaClearSig(Owner
, 
 268          APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), 
 273       for (vector 
<IndexTarget
*>::const_iterator Target 
= targets
->begin(); Target 
!= targets
->end(); ++Target
) 
 274          new pkgAcqIndex(Owner
, TransactionManager
, *Target
); 
 280 void debReleaseIndex::SetTrusted(bool const Trusted
) 
 283                 this->Trusted 
= ALWAYS_TRUSTED
; 
 285                 this->Trusted 
= NEVER_TRUSTED
; 
 288 bool debReleaseIndex::IsTrusted() const 
 290    if (Trusted 
== ALWAYS_TRUSTED
) 
 292    else if (Trusted 
== NEVER_TRUSTED
) 
 296    if(_config
->FindB("APT::Authentication::TrustCDROM", false)) 
 297       if(URI
.substr(0,strlen("cdrom:")) == "cdrom:") 
 300    string VerifiedSigFile 
= _config
->FindDir("Dir::State::lists") + 
 301       URItoFileName(MetaIndexURI("Release")) + ".gpg"; 
 303    if (FileExists(VerifiedSigFile
)) 
 306    VerifiedSigFile 
= _config
->FindDir("Dir::State::lists") + 
 307       URItoFileName(MetaIndexURI("InRelease")); 
 309    return FileExists(VerifiedSigFile
); 
 312 vector 
<pkgIndexFile 
*> *debReleaseIndex::GetIndexFiles() { 
 316         Indexes 
= new vector 
<pkgIndexFile
*>; 
 317         map
<string
, vector
<debSectionEntry 
const*> >::const_iterator 
const src 
= ArchEntries
.find("source"); 
 318         if (src 
!= ArchEntries
.end()) { 
 319                 vector
<debSectionEntry 
const*> const SectionEntries 
= src
->second
; 
 320                 for (vector
<debSectionEntry 
const*>::const_iterator I 
= SectionEntries
.begin(); 
 321                      I 
!= SectionEntries
.end(); ++I
) 
 322                         Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted())); 
 325         // Only source release 
 326         if (Indexes
->empty() == false && ArchEntries
.size() == 1) 
 329         std::vector
<std::string
> const lang 
= APT::Configuration::getLanguages(true); 
 330         map
<string
, set
<string
> > sections
; 
 331         for (map
<string
, vector
<debSectionEntry 
const*> >::const_iterator a 
= ArchEntries
.begin(); 
 332              a 
!= ArchEntries
.end(); ++a
) { 
 333                 if (a
->first 
== "source") 
 335                 for (vector
<debSectionEntry 
const*>::const_iterator I 
= a
->second
.begin(); 
 336                      I 
!= a
->second
.end(); ++I
) { 
 337                         Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
)); 
 338                         sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end()); 
 342         for (map
<string
, set
<string
> >::const_iterator s 
= sections
.begin(); 
 343              s 
!= sections
.end(); ++s
) 
 344                 for (set
<string
>::const_iterator l 
= s
->second
.begin(); 
 345                      l 
!= s
->second
.end(); ++l
) { 
 346                         if (*l 
== "none") continue; 
 347                         Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str())); 
 353 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry 
*Entry
) { 
 354         for (vector
<string
>::const_iterator a 
= Archs
.begin(); 
 355              a 
!= Archs
.end(); ++a
) 
 356                 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
)); 
 360 void debReleaseIndex::PushSectionEntry(string 
const &Arch
, const debSectionEntry 
*Entry
) { 
 361         ArchEntries
[Arch
].push_back(Entry
); 
 364 void debReleaseIndex::PushSectionEntry(const debSectionEntry 
*Entry
) { 
 365         if (Entry
->IsSrc 
== true) 
 366                 PushSectionEntry("source", Entry
); 
 368                 for (map
<string
, vector
<const debSectionEntry 
*> >::iterator a 
= ArchEntries
.begin(); 
 369                      a 
!= ArchEntries
.end(); ++a
) { 
 370                         a
->second
.push_back(Entry
); 
 375 debReleaseIndex::debSectionEntry::debSectionEntry (string 
const &Section
, 
 376                 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
) 
 379 class APT_HIDDEN debSLTypeDebian 
: public pkgSourceList::Type
 
 383    bool CreateItemInternal(vector
<metaIndex 
*> &List
, string 
const &URI
, 
 384                            string 
const &Dist
, string 
const &Section
, 
 385                            bool const &IsSrc
, map
<string
, string
> const &Options
) const 
 387       // parse arch=, arch+= and arch-= settings 
 388       map
<string
, string
>::const_iterator arch 
= Options
.find("arch"); 
 389       vector
<string
> Archs
; 
 390       if (arch 
!= Options
.end()) 
 391          Archs 
= VectorizeString(arch
->second
, ','); 
 393          Archs 
= APT::Configuration::getArchitectures(); 
 395       if ((arch 
= Options
.find("arch+")) != Options
.end()) 
 397          std::vector
<std::string
> const plusArch 
= VectorizeString(arch
->second
, ','); 
 398          for (std::vector
<std::string
>::const_iterator plus 
= plusArch
.begin(); plus 
!= plusArch
.end(); ++plus
) 
 399             if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end()) 
 400                Archs
.push_back(*plus
); 
 402       if ((arch 
= Options
.find("arch-")) != Options
.end()) 
 404          std::vector
<std::string
> const minusArch 
= VectorizeString(arch
->second
, ','); 
 405          for (std::vector
<std::string
>::const_iterator minus 
= minusArch
.begin(); minus 
!= minusArch
.end(); ++minus
) 
 407             std::vector
<std::string
>::iterator kill 
= std::find(Archs
.begin(), Archs
.end(), *minus
); 
 408             if (kill 
!= Archs
.end()) 
 413       map
<string
, string
>::const_iterator 
const trusted 
= Options
.find("trusted"); 
 415       for (vector
<metaIndex 
*>::const_iterator I 
= List
.begin(); 
 416            I 
!= List
.end(); ++I
) 
 418          // We only worry about debian entries here 
 419          if (strcmp((*I
)->GetType(), "deb") != 0) 
 422          debReleaseIndex 
*Deb 
= (debReleaseIndex 
*) (*I
); 
 423          if (trusted 
!= Options
.end()) 
 424             Deb
->SetTrusted(StringToBool(trusted
->second
, false)); 
 426          /* This check insures that there will be only one Release file 
 427             queued for all the Packages files and Sources files it 
 429          if (Deb
->GetURI() == URI 
&& Deb
->GetDist() == Dist
) 
 432                Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
)); 
 435                if (Dist
[Dist
.size() - 1] == '/') 
 436                   Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
)); 
 438                   Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
)); 
 444       // No currently created Release file indexes this entry, so we create a new one. 
 445       debReleaseIndex 
*Deb
; 
 446       if (trusted 
!= Options
.end()) 
 447          Deb 
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false)); 
 449          Deb 
= new debReleaseIndex(URI
, Dist
); 
 452          Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
)); 
 455          if (Dist
[Dist
.size() - 1] == '/') 
 456             Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
)); 
 458             Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
)); 
 465 debDebFileMetaIndex::debDebFileMetaIndex(std::string 
const &DebFile
) 
 466    : metaIndex(DebFile
, "local-uri", "deb-dist"), DebFile(DebFile
) 
 468    DebIndex 
= new debDebPkgFileIndex(DebFile
); 
 469    Indexes 
= new vector
<pkgIndexFile 
*>(); 
 470    Indexes
->push_back(DebIndex
); 
 474 class APT_HIDDEN debSLTypeDeb 
: public debSLTypeDebian
 
 478    bool CreateItem(vector
<metaIndex 
*> &List
, string 
const &URI
, 
 479                    string 
const &Dist
, string 
const &Section
, 
 480                    std::map
<string
, string
> const &Options
) const 
 482       return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
); 
 488       Label 
= "Standard Debian binary tree"; 
 492 class APT_HIDDEN debSLTypeDebSrc 
: public debSLTypeDebian
 
 496    bool CreateItem(vector
<metaIndex 
*> &List
, string 
const &URI
, 
 497                    string 
const &Dist
, string 
const &Section
, 
 498                    std::map
<string
, string
> const &Options
) const 
 500       return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
); 
 506       Label 
= "Standard Debian source tree"; 
 510 class APT_HIDDEN debSLTypeDebFile 
: public pkgSourceList::Type
 
 514    bool CreateItem(vector
<metaIndex 
*> &List
, string 
const &URI
, 
 515                    string 
const &/*Dist*/, string 
const &/*Section*/, 
 516                    std::map
<string
, string
> const &/*Options*/) const 
 518       metaIndex 
*mi 
= new debDebFileMetaIndex(URI
); 
 526       Label 
= "Debian Deb File"; 
 530 APT_HIDDEN debSLTypeDeb _apt_DebType
; 
 531 APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType
; 
 532 APT_HIDDEN debSLTypeDebFile _apt_DebFileType
;