1 // -*- mode: cpp; mode: fold -*-
3 // $Id: deblistparser.cc,v 1.29.2.5 2004/01/06 01:43:44 mdz Exp $
4 /* ######################################################################
6 Package Cache Generator - Generator for the cache structure.
8 This builds the cache structure from the abstract package list parser.
10 ##################################################################### */
12 // Include Files /*{{{*/
15 #include <apt-pkg/deblistparser.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/configuration.h>
18 #include <apt-pkg/cachefilter.h>
19 #include <apt-pkg/aptconfiguration.h>
20 #include <apt-pkg/strutl.h>
21 #include <apt-pkg/crc-16.h>
22 #include <apt-pkg/md5.h>
23 #include <apt-pkg/pkgcache.h>
24 #include <apt-pkg/cacheiterators.h>
25 #include <apt-pkg/tagfile.h>
26 #include <apt-pkg/macros.h>
38 static const debListParser::WordList PrioList
[] = {
39 {"required",pkgCache::State::Required
},
40 {"important",pkgCache::State::Important
},
41 {"standard",pkgCache::State::Standard
},
42 {"optional",pkgCache::State::Optional
},
43 {"extra",pkgCache::State::Extra
},
46 // ListParser::debListParser - Constructor /*{{{*/
47 // ---------------------------------------------------------------------
48 /* Provide an architecture and only this one and "all" will be accepted
49 in Step(), if no Architecture is given we will accept every arch
50 we would accept in general with checkArchitecture() */
51 debListParser::debListParser(FileFd
*File
) :
52 pkgCacheListParser(), d(NULL
), Tags(File
)
56 // ListParser::Package - Return the package name /*{{{*/
57 // ---------------------------------------------------------------------
58 /* This is to return the name of the package this section describes */
59 string
debListParser::Package() {
60 string Result
= Section
.FindS("Package");
62 // Normalize mixed case package names to lower case, like dpkg does
63 // See Bug#807012 for details
64 std::transform(Result
.begin(), Result
.end(), Result
.begin(), tolower_ascii
);
66 if(unlikely(Result
.empty() == true))
67 _error
->Error("Encountered a section with no Package: header");
71 // ListParser::Architecture - Return the package arch /*{{{*/
72 // ---------------------------------------------------------------------
73 /* This will return the Architecture of the package this section describes */
74 string
debListParser::Architecture() {
75 std::string
const Arch
= Section
.FindS("Architecture");
76 return Arch
.empty() ? "none" : Arch
;
79 // ListParser::ArchitectureAll /*{{{*/
80 // ---------------------------------------------------------------------
82 bool debListParser::ArchitectureAll() {
83 return Section
.FindS("Architecture") == "all";
86 // ListParser::Version - Return the version string /*{{{*/
87 // ---------------------------------------------------------------------
88 /* This is to return the string describing the version in debian form,
89 epoch:upstream-release. If this returns the blank string then the
90 entry is assumed to only describe package properties */
91 string
debListParser::Version()
93 return Section
.FindS("Version");
96 unsigned char debListParser::ParseMultiArch(bool const showErrors
) /*{{{*/
99 string
const MultiArch
= Section
.FindS("Multi-Arch");
100 if (MultiArch
.empty() == true || MultiArch
== "no")
101 MA
= pkgCache::Version::No
;
102 else if (MultiArch
== "same") {
103 if (ArchitectureAll() == true)
105 if (showErrors
== true)
106 _error
->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
107 Section
.FindS("Package").c_str());
108 MA
= pkgCache::Version::No
;
111 MA
= pkgCache::Version::Same
;
113 else if (MultiArch
== "foreign")
114 MA
= pkgCache::Version::Foreign
;
115 else if (MultiArch
== "allowed")
116 MA
= pkgCache::Version::Allowed
;
119 if (showErrors
== true)
120 _error
->Warning("Unknown Multi-Arch type '%s' for package '%s'",
121 MultiArch
.c_str(), Section
.FindS("Package").c_str());
122 MA
= pkgCache::Version::No
;
125 if (ArchitectureAll() == true)
126 MA
|= pkgCache::Version::All
;
131 // ListParser::NewVersion - Fill in the version structure /*{{{*/
132 // ---------------------------------------------------------------------
134 bool debListParser::NewVersion(pkgCache::VerIterator
&Ver
)
140 if (Section
.Find("Section",Start
,Stop
) == true)
142 map_stringitem_t
const idx
= StoreString(pkgCacheGenerator::SECTION
, Start
, Stop
- Start
);
145 // Parse the source package name
146 pkgCache::GrpIterator
const G
= Ver
.ParentPkg().Group();
147 Ver
->SourcePkgName
= G
->Name
;
148 Ver
->SourceVerStr
= Ver
->VerStr
;
149 if (Section
.Find("Source",Start
,Stop
) == true)
151 const char * const Space
= (const char * const) memchr(Start
, ' ', Stop
- Start
);
152 pkgCache::VerIterator V
;
157 const char * const Open
= (const char * const) memchr(Space
, '(', Stop
- Space
);
158 if (likely(Open
!= NULL
))
160 const char * const Close
= (const char * const) memchr(Open
, ')', Stop
- Open
);
161 if (likely(Close
!= NULL
))
163 std::string
const version(Open
+ 1, (Close
- Open
) - 1);
164 if (version
!= Ver
.VerStr())
166 map_stringitem_t
const idx
= StoreString(pkgCacheGenerator::VERSIONNUMBER
, version
);
167 Ver
->SourceVerStr
= idx
;
173 std::string
const pkgname(Start
, Stop
- Start
);
174 if (pkgname
!= G
.Name())
176 for (pkgCache::PkgIterator P
= G
.PackageList(); P
.end() == false; P
= G
.NextPkg(P
))
178 for (V
= P
.VersionList(); V
.end() == false; ++V
)
180 if (pkgname
== V
.SourcePkgName())
182 Ver
->SourcePkgName
= V
->SourcePkgName
;
186 if (V
.end() == false)
191 map_stringitem_t
const idx
= StoreString(pkgCacheGenerator::PKGNAME
, pkgname
);
192 Ver
->SourcePkgName
= idx
;
197 Ver
->MultiArch
= ParseMultiArch(true);
199 Ver
->Size
= Section
.FindULL("Size");
200 // Unpacked Size (in K)
201 Ver
->InstalledSize
= Section
.FindULL("Installed-Size");
202 Ver
->InstalledSize
*= 1024;
205 if (Section
.Find("Priority",Start
,Stop
) == true)
207 if (GrabWord(string(Start
,Stop
-Start
),PrioList
,Ver
->Priority
) == false)
208 Ver
->Priority
= pkgCache::State::Extra
;
211 if (ParseDepends(Ver
,"Pre-Depends",pkgCache::Dep::PreDepends
) == false)
213 if (ParseDepends(Ver
,"Depends",pkgCache::Dep::Depends
) == false)
215 if (ParseDepends(Ver
,"Conflicts",pkgCache::Dep::Conflicts
) == false)
217 if (ParseDepends(Ver
,"Breaks",pkgCache::Dep::DpkgBreaks
) == false)
219 if (ParseDepends(Ver
,"Recommends",pkgCache::Dep::Recommends
) == false)
221 if (ParseDepends(Ver
,"Suggests",pkgCache::Dep::Suggests
) == false)
223 if (ParseDepends(Ver
,"Replaces",pkgCache::Dep::Replaces
) == false)
225 if (ParseDepends(Ver
,"Enhances",pkgCache::Dep::Enhances
) == false)
228 if (ParseDepends(Ver
,"Optional",pkgCache::Dep::Suggests
) == false)
231 if (ParseProvides(Ver
) == false)
237 // ListParser::Description - Return the description string /*{{{*/
238 // ---------------------------------------------------------------------
239 /* This is to return the string describing the package in debian
240 form. If this returns the blank string then the entry is assumed to
241 only describe package properties */
242 string
debListParser::Description(std::string
const &lang
)
245 return Section
.FindS("Description");
247 return Section
.FindS(string("Description-").append(lang
).c_str());
250 // ListParser::AvailableDescriptionLanguages /*{{{*/
251 std::vector
<std::string
> debListParser::AvailableDescriptionLanguages()
253 std::vector
<std::string
> const understood
= APT::Configuration::getLanguages();
254 std::vector
<std::string
> avail
;
255 if (Section
.Exists("Description") == true)
257 for (std::vector
<std::string
>::const_iterator lang
= understood
.begin(); lang
!= understood
.end(); ++lang
)
259 std::string
const tagname
= "Description-" + *lang
;
260 if (Section
.Exists(tagname
.c_str()) == true)
261 avail
.push_back(*lang
);
266 // ListParser::Description_md5 - Return the description_md5 MD5SumValue /*{{{*/
267 // ---------------------------------------------------------------------
268 /* This is to return the md5 string to allow the check if it is the right
269 description. If no Description-md5 is found in the section it will be
272 MD5SumValue
debListParser::Description_md5()
274 string
const value
= Section
.FindS("Description-md5");
275 if (value
.empty() == true)
277 std::string
const desc
= Description("") + "\n";
279 return MD5SumValue();
282 md5
.Add(desc
.c_str());
285 else if (likely(value
.size() == 32))
287 MD5SumValue sumvalue
;
288 if (sumvalue
.Set(value
))
291 _error
->Error("Malformed Description-md5 line; includes invalid character '%s'", value
.c_str());
292 return MD5SumValue();
294 _error
->Error("Malformed Description-md5 line; doesn't have the required length (32 != %d) '%s'", (int)value
.size(), value
.c_str());
295 return MD5SumValue();
298 // ListParser::UsePackage - Update a package structure /*{{{*/
299 // ---------------------------------------------------------------------
300 /* This is called to update the package with any new information
301 that might be found in the section */
302 bool debListParser::UsePackage(pkgCache::PkgIterator
&Pkg
,
303 pkgCache::VerIterator
&Ver
)
305 string
const static myArch
= _config
->Find("APT::Architecture");
306 // Possible values are: "all", "native", "installed" and "none"
307 // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
308 string
const static essential
= _config
->Find("pkgCacheGen::Essential", "all");
309 if (essential
== "all" ||
310 (essential
== "native" && Pkg
->Arch
!= 0 && myArch
== Pkg
.Arch()))
311 if (Section
.FindFlag("Essential",Pkg
->Flags
,pkgCache::Flag::Essential
) == false)
313 if (Section
.FindFlag("Important",Pkg
->Flags
,pkgCache::Flag::Important
) == false)
316 if (strcmp(Pkg
.Name(),"apt") == 0)
318 if ((essential
== "native" && Pkg
->Arch
!= 0 && myArch
== Pkg
.Arch()) ||
320 Pkg
->Flags
|= pkgCache::Flag::Essential
| pkgCache::Flag::Important
;
322 Pkg
->Flags
|= pkgCache::Flag::Important
;
325 if (ParseStatus(Pkg
,Ver
) == false)
330 // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
331 // ---------------------------------------------------------------------
333 unsigned short debListParser::VersionHash()
335 const char *Sections
[] ={"Installed-Size",
343 unsigned long Result
= INIT_FCS
;
345 for (const char * const *I
= Sections
; *I
!= 0; ++I
)
349 if (Section
.Find(*I
,Start
,End
) == false || End
- Start
>= (signed)sizeof(S
))
352 /* Strip out any spaces from the text, this undoes dpkgs reformatting
353 of certain fields. dpkg also has the rather interesting notion of
354 reformatting depends operators < -> <= */
356 for (; Start
!= End
; ++Start
)
358 if (isspace_ascii(*Start
) != 0)
360 *J
++ = tolower_ascii(*Start
);
362 if ((*Start
== '<' || *Start
== '>') && Start
[1] != *Start
&& Start
[1] != '=')
366 Result
= AddCRC16(Result
,S
,J
- S
);
372 // StatusListParser::ParseStatus - Parse the status field /*{{{*/
373 // ---------------------------------------------------------------------
374 /* Status lines are of the form,
375 Status: want flag status
376 want = unknown, install, hold, deinstall, purge
378 status = not-installed, config-files, half-installed, unpacked,
379 half-configured, triggers-awaited, triggers-pending, installed
381 bool debListParser::ParseStatus(pkgCache::PkgIterator
&,
382 pkgCache::VerIterator
&)
386 bool debStatusListParser::ParseStatus(pkgCache::PkgIterator
&Pkg
,
387 pkgCache::VerIterator
&Ver
)
391 if (Section
.Find("Status",Start
,Stop
) == false)
394 // UsePackage() is responsible for setting the flag in the default case
395 bool const static essential
= _config
->Find("pkgCacheGen::Essential", "") == "installed";
396 if (essential
== true &&
397 Section
.FindFlag("Essential",Pkg
->Flags
,pkgCache::Flag::Essential
) == false)
400 // Isolate the first word
401 const char *I
= Start
;
402 for(; I
< Stop
&& *I
!= ' '; I
++);
403 if (I
>= Stop
|| *I
!= ' ')
404 return _error
->Error("Malformed Status line");
406 // Process the want field
407 WordList WantList
[] = {{"unknown",pkgCache::State::Unknown
},
408 {"install",pkgCache::State::Install
},
409 {"hold",pkgCache::State::Hold
},
410 {"deinstall",pkgCache::State::DeInstall
},
411 {"purge",pkgCache::State::Purge
},
413 if (GrabWord(string(Start
,I
-Start
),WantList
,Pkg
->SelectedState
) == false)
414 return _error
->Error("Malformed 1st word in the Status line");
416 // Isloate the next word
419 for(; I
< Stop
&& *I
!= ' '; I
++);
420 if (I
>= Stop
|| *I
!= ' ')
421 return _error
->Error("Malformed status line, no 2nd word");
423 // Process the flag field
424 WordList FlagList
[] = {{"ok",pkgCache::State::Ok
},
425 {"reinstreq",pkgCache::State::ReInstReq
},
426 {"hold",pkgCache::State::HoldInst
},
427 {"hold-reinstreq",pkgCache::State::HoldReInstReq
},
429 if (GrabWord(string(Start
,I
-Start
),FlagList
,Pkg
->InstState
) == false)
430 return _error
->Error("Malformed 2nd word in the Status line");
432 // Isloate the last word
435 for(; I
< Stop
&& *I
!= ' '; I
++);
437 return _error
->Error("Malformed Status line, no 3rd word");
439 // Process the flag field
440 WordList StatusList
[] = {{"not-installed",pkgCache::State::NotInstalled
},
441 {"config-files",pkgCache::State::ConfigFiles
},
442 {"half-installed",pkgCache::State::HalfInstalled
},
443 {"unpacked",pkgCache::State::UnPacked
},
444 {"half-configured",pkgCache::State::HalfConfigured
},
445 {"triggers-awaited",pkgCache::State::TriggersAwaited
},
446 {"triggers-pending",pkgCache::State::TriggersPending
},
447 {"installed",pkgCache::State::Installed
},
449 if (GrabWord(string(Start
,I
-Start
),StatusList
,Pkg
->CurrentState
) == false)
450 return _error
->Error("Malformed 3rd word in the Status line");
452 /* A Status line marks the package as indicating the current
453 version as well. Only if it is actually installed.. Otherwise
454 the interesting dpkg handling of the status file creates bogus
456 if (!(Pkg
->CurrentState
== pkgCache::State::NotInstalled
||
457 Pkg
->CurrentState
== pkgCache::State::ConfigFiles
))
459 if (Ver
.end() == true)
460 _error
->Warning("Encountered status field in a non-version description");
462 Pkg
->CurrentVer
= Ver
.Index();
468 const char *debListParser::ConvertRelation(const char *I
,unsigned int &Op
)
470 // Determine the operator
478 Op
= pkgCache::Dep::LessEq
;
485 Op
= pkgCache::Dep::Less
;
489 // < is the same as <= and << is really Cs < for some reason
490 Op
= pkgCache::Dep::LessEq
;
498 Op
= pkgCache::Dep::GreaterEq
;
505 Op
= pkgCache::Dep::Greater
;
509 // > is the same as >= and >> is really Cs > for some reason
510 Op
= pkgCache::Dep::GreaterEq
;
514 Op
= pkgCache::Dep::Equals
;
518 // HACK around bad package definitions
520 Op
= pkgCache::Dep::Equals
;
526 // ListParser::ParseDepends - Parse a dependency element /*{{{*/
527 // ---------------------------------------------------------------------
528 /* This parses the dependency elements out of a standard string in place,
530 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
531 std::string
&Package
,std::string
&Ver
,unsigned int &Op
)
532 { return ParseDepends(Start
, Stop
, Package
, Ver
, Op
, false, true, false); }
533 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
534 std::string
&Package
,std::string
&Ver
,unsigned int &Op
,
535 bool const &ParseArchFlags
)
536 { return ParseDepends(Start
, Stop
, Package
, Ver
, Op
, ParseArchFlags
, true, false); }
537 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
538 std::string
&Package
,std::string
&Ver
,unsigned int &Op
,
539 bool const &ParseArchFlags
, bool const &StripMultiArch
)
540 { return ParseDepends(Start
, Stop
, Package
, Ver
, Op
, ParseArchFlags
, StripMultiArch
, false); }
541 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
542 string
&Package
,string
&Ver
,
543 unsigned int &Op
, bool const &ParseArchFlags
,
544 bool const &StripMultiArch
,
545 bool const &ParseRestrictionsList
)
547 // Strip off leading space
548 for (;Start
!= Stop
&& isspace_ascii(*Start
) != 0; ++Start
);
550 // Parse off the package name
551 const char *I
= Start
;
552 for (;I
!= Stop
&& isspace_ascii(*I
) == 0 && *I
!= '(' && *I
!= ')' &&
553 *I
!= ',' && *I
!= '|' && *I
!= '[' && *I
!= ']' &&
554 *I
!= '<' && *I
!= '>'; ++I
);
557 if (I
!= Stop
&& *I
== ')')
563 // Stash the package name
564 Package
.assign(Start
,I
- Start
);
566 // We don't want to confuse library users which can't handle MultiArch
567 if (StripMultiArch
== true) {
568 string
const arch
= _config
->Find("APT::Architecture");
569 size_t const found
= Package
.rfind(':');
570 if (found
!= string::npos
&&
571 (strcmp(Package
.c_str() + found
, ":any") == 0 ||
572 strcmp(Package
.c_str() + found
, ":native") == 0 ||
573 strcmp(Package
.c_str() + found
+ 1, arch
.c_str()) == 0))
574 Package
= Package
.substr(0,found
);
577 // Skip white space to the '('
578 for (;I
!= Stop
&& isspace_ascii(*I
) != 0 ; I
++);
581 if (I
!= Stop
&& *I
== '(')
584 for (I
++; I
!= Stop
&& isspace_ascii(*I
) != 0 ; I
++);
587 I
= ConvertRelation(I
,Op
);
590 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
592 I
= (const char*) memchr(I
, ')', Stop
- I
);
593 if (I
== NULL
|| Start
== I
)
596 // Skip trailing whitespace
598 for (; End
> Start
&& isspace_ascii(End
[-1]); End
--);
600 Ver
.assign(Start
,End
-Start
);
606 Op
= pkgCache::Dep::NoOp
;
610 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
612 if (unlikely(ParseArchFlags
== true))
614 string
const arch
= _config
->Find("APT::Architecture");
615 APT::CacheFilter::PackageArchitectureMatchesSpecification
matchesArch(arch
, false);
617 // Parse an architecture
618 if (I
!= Stop
&& *I
== '[')
622 if (unlikely(I
== Stop
))
627 bool NegArch
= false;
630 // look for whitespace or ending ']'
631 for (;End
!= Stop
&& !isspace_ascii(*End
) && *End
!= ']'; ++End
);
633 if (unlikely(End
== Stop
))
642 std::string
arch(I
, End
);
643 if (arch
.empty() == false && matchesArch(arch
.c_str()) == true)
648 // we found a match, so fast-forward to the end of the wildcards
649 for (; End
!= Stop
&& *End
!= ']'; ++End
);
658 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
665 Package
= ""; /* not for this arch */
669 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
672 if (unlikely(ParseRestrictionsList
== true))
674 // Parse a restrictions formula which is in disjunctive normal form:
675 // (foo AND bar) OR (blub AND bla)
677 std::vector
<string
> const profiles
= APT::Configuration::getBuildProfiles();
679 // if the next character is a restriction list, then by default the
680 // dependency does not apply and the conditions have to be checked
681 // if the next character is not a restriction list, then by default the
682 // dependency applies
683 bool applies1
= (*I
!= '<');
691 if (unlikely(I
== Stop
))
696 // if of the prior restriction list is already fulfilled, then
697 // we can just skip to the end of the current list
699 for (;End
!= Stop
&& *End
!= '>'; ++End
);
702 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
704 bool applies2
= true;
705 // all the conditions inside a restriction list have to be
706 // met so once we find one that is not met, we can skip to
707 // the end of this list
710 // look for whitespace or ending '>'
711 // End now points to the character after the current term
712 for (;End
!= Stop
&& !isspace_ascii(*End
) && *End
!= '>'; ++End
);
714 if (unlikely(End
== Stop
))
717 bool NegRestriction
= false;
720 NegRestriction
= true;
724 std::string
restriction(I
, End
);
726 if (restriction
.empty() == false && profiles
.empty() == false &&
727 std::find(profiles
.begin(), profiles
.end(), restriction
) != profiles
.end())
729 if (NegRestriction
) {
731 // since one of the terms does not apply we don't have to check the others
732 for (; End
!= Stop
&& *End
!= '>'; ++End
);
735 if (!NegRestriction
) {
737 // since one of the terms does not apply we don't have to check the others
738 for (; End
!= Stop
&& *End
!= '>'; ++End
);
745 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
751 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
759 if (applies1
== false) {
760 Package
= ""; //not for this restriction
764 if (I
!= Stop
&& *I
== '|')
765 Op
|= pkgCache::Dep::Or
;
767 if (I
== Stop
|| *I
== ',' || *I
== '|')
770 for (I
++; I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
777 // ListParser::ParseDepends - Parse a dependency list /*{{{*/
778 // ---------------------------------------------------------------------
779 /* This is the higher level depends parser. It takes a tag and generates
780 a complete depends tree for the given version. */
781 bool debListParser::ParseDepends(pkgCache::VerIterator
&Ver
,
782 const char *Tag
,unsigned int Type
)
786 if (Section
.Find(Tag
,Start
,Stop
) == false)
789 string
const pkgArch
= Ver
.Arch();
797 Start
= ParseDepends(Start
, Stop
, Package
, Version
, Op
, false, false, false);
799 return _error
->Error("Problem parsing dependency %s",Tag
);
800 size_t const found
= Package
.rfind(':');
802 if (found
== string::npos
)
804 if (NewDepends(Ver
,Package
,pkgArch
,Version
,Op
,Type
) == false)
807 else if (strcmp(Package
.c_str() + found
, ":any") == 0)
809 if (NewDepends(Ver
,Package
,"any",Version
,Op
,Type
) == false)
814 // Such dependencies are not supposed to be accepted …
815 // … but this is probably the best thing to do anyway
816 if (Package
.substr(found
+ 1) == "native")
817 Package
= Package
.substr(0, found
) + ':' + Ver
.Cache()->NativeArch();
819 if (NewDepends(Ver
, Package
, "any", Version
, Op
| pkgCache::Dep::ArchSpecific
, Type
) == false)
829 // ListParser::ParseProvides - Parse the provides list /*{{{*/
830 // ---------------------------------------------------------------------
832 bool debListParser::ParseProvides(pkgCache::VerIterator
&Ver
)
834 /* it is unlikely, but while parsing dependencies, we might have already
835 picked up multi-arch implicit provides which we do not want to duplicate here */
836 bool hasProvidesAlready
= false;
837 std::string
const spzName
= Ver
.ParentPkg().FullName(false);
839 for (pkgCache::PrvIterator Prv
= Ver
.ProvidesList(); Prv
.end() == false; ++Prv
)
841 if (Prv
.IsMultiArchImplicit() == false || (Prv
->Flags
& pkgCache::Flag::ArchSpecific
) == 0)
843 if (spzName
!= Prv
.OwnerPkg().FullName(false))
845 hasProvidesAlready
= true;
850 string
const Arch
= Ver
.Arch();
853 if (Section
.Find("Provides",Start
,Stop
) == true)
861 Start
= ParseDepends(Start
,Stop
,Package
,Version
,Op
, false, false, false);
862 const size_t archfound
= Package
.rfind(':');
864 return _error
->Error("Problem parsing Provides line");
865 if (Op
!= pkgCache::Dep::NoOp
&& Op
!= pkgCache::Dep::Equals
) {
866 _error
->Warning("Ignoring Provides line with non-equal DepCompareOp for package %s", Package
.c_str());
867 } else if (archfound
!= string::npos
) {
868 std::string spzArch
= Package
.substr(archfound
+ 1);
869 if (spzArch
!= "any")
871 if (NewProvides(Ver
, Package
.substr(0, archfound
), spzArch
, Version
, pkgCache::Flag::MultiArchImplicit
| pkgCache::Flag::ArchSpecific
) == false)
874 if (NewProvides(Ver
, Package
, "any", Version
, pkgCache::Flag::ArchSpecific
) == false)
876 } else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
) {
877 if (APT::Configuration::checkArchitecture(Arch
))
878 if (NewProvidesAllArch(Ver
, Package
, Version
, 0) == false)
881 if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
883 if (NewProvides(Ver
, Package
+ ":any", "any", Version
, pkgCache::Flag::MultiArchImplicit
) == false)
886 if (NewProvides(Ver
, Package
, Arch
, Version
, 0) == false)
889 if (archfound
== std::string::npos
)
891 std::string
const spzName
= Package
+ ':' + Ver
.ParentPkg().Arch();
892 pkgCache::PkgIterator
const spzPkg
= Ver
.Cache()->FindPkg(spzName
, "any");
893 if (spzPkg
.end() == false)
895 if (NewProvides(Ver
, spzName
, "any", Version
, pkgCache::Flag::MultiArchImplicit
| pkgCache::Flag::ArchSpecific
) == false)
899 } while (Start
!= Stop
);
902 if (APT::Configuration::checkArchitecture(Arch
))
904 if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
906 string
const Package
= string(Ver
.ParentPkg().Name()).append(":").append("any");
907 if (NewProvides(Ver
, Package
, "any", Ver
.VerStr(), pkgCache::Flag::MultiArchImplicit
) == false)
910 else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
912 if (NewProvidesAllArch(Ver
, Ver
.ParentPkg().Name(), Ver
.VerStr(), pkgCache::Flag::MultiArchImplicit
) == false)
917 if (hasProvidesAlready
== false)
919 pkgCache::PkgIterator
const spzPkg
= Ver
.Cache()->FindPkg(spzName
, "any");
920 if (spzPkg
.end() == false)
922 if (NewProvides(Ver
, spzName
, "any", Ver
.VerStr(), pkgCache::Flag::MultiArchImplicit
| pkgCache::Flag::ArchSpecific
) == false)
929 // ListParser::GrabWord - Matches a word and returns /*{{{*/
930 // ---------------------------------------------------------------------
931 /* Looks for a word in a list of words - for ParseStatus */
932 bool debListParser::GrabWord(string Word
,const WordList
*List
,unsigned char &Out
)
934 for (unsigned int C
= 0; List
[C
].Str
!= 0; C
++)
936 if (strcasecmp(Word
.c_str(),List
[C
].Str
) == 0)
945 // ListParser::Step - Move to the next section in the file /*{{{*/
946 // ---------------------------------------------------------------------
947 /* This has to be careful to only process the correct architecture */
948 bool debListParser::Step()
950 iOffset
= Tags
.Offset();
951 return Tags
.Step(Section
);
954 // ListParser::GetPrio - Convert the priority from a string /*{{{*/
955 // ---------------------------------------------------------------------
957 unsigned char debListParser::GetPrio(string Str
)
960 if (GrabWord(Str
,PrioList
,Out
) == false)
961 Out
= pkgCache::State::Extra
;
966 bool debListParser::SameVersion(unsigned short const Hash
, /*{{{*/
967 pkgCache::VerIterator
const &Ver
)
969 if (pkgCacheListParser::SameVersion(Hash
, Ver
) == false)
971 // status file has no (Download)Size, but all others are fair game
972 // status file is parsed last, so the first version we encounter is
973 // probably also the version we have downloaded
974 unsigned long long const Size
= Section
.FindULL("Size");
975 if (Size
!= 0 && Size
!= Ver
->Size
)
977 // available everywhere, but easier to check here than to include in VersionHash
978 unsigned char MultiArch
= ParseMultiArch(false);
979 if (MultiArch
!= Ver
->MultiArch
)
981 // for all practical proposes (we can check): same version
986 debDebFileParser::debDebFileParser(FileFd
*File
, std::string
const &DebFile
)
987 : debListParser(File
), DebFile(DebFile
)
991 bool debDebFileParser::UsePackage(pkgCache::PkgIterator
&Pkg
,
992 pkgCache::VerIterator
&Ver
)
994 bool res
= debListParser::UsePackage(Pkg
, Ver
);
995 // we use the full file path as a provides so that the file is found
997 if(NewProvides(Ver
, DebFile
, Pkg
.Cache()->NativeArch(), Ver
.VerStr(), 0) == false)
1002 debListParser::~debListParser() {}