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>
37 using APT::StringView
;
39 static const debListParser::WordList PrioList
[] = {
40 {"required",pkgCache::State::Required
},
41 {"important",pkgCache::State::Important
},
42 {"standard",pkgCache::State::Standard
},
43 {"optional",pkgCache::State::Optional
},
44 {"extra",pkgCache::State::Extra
},
47 // ListParser::debListParser - Constructor /*{{{*/
48 // ---------------------------------------------------------------------
49 /* Provide an architecture and only this one and "all" will be accepted
50 in Step(), if no Architecture is given we will accept every arch
51 we would accept in general with checkArchitecture() */
52 debListParser::debListParser(FileFd
*File
) :
53 pkgCacheListParser(), Tags(File
)
55 // this dance allows an empty value to override the default
56 if (_config
->Exists("pkgCacheGen::ForceEssential"))
58 forceEssential
= _config
->FindVector("pkgCacheGen::ForceEssential");
59 if (forceEssential
.empty() == false && _config
->Find("pkgCacheGen::ForceEssential").empty())
60 forceEssential
.emplace_back("apt");
63 forceEssential
.emplace_back("apt");
64 forceImportant
= _config
->FindVector("pkgCacheGen::ForceImportant");
67 // ListParser::Package - Return the package name /*{{{*/
68 // ---------------------------------------------------------------------
69 /* This is to return the name of the package this section describes */
70 string
debListParser::Package() {
71 string Result
= Section
.Find("Package").to_string();
73 // Normalize mixed case package names to lower case, like dpkg does
74 // See Bug#807012 for details
75 std::transform(Result
.begin(), Result
.end(), Result
.begin(), tolower_ascii
);
77 if(unlikely(Result
.empty() == true))
78 _error
->Error("Encountered a section with no Package: header");
82 // ListParser::Architecture - Return the package arch /*{{{*/
83 // ---------------------------------------------------------------------
84 /* This will return the Architecture of the package this section describes */
85 APT::StringView
debListParser::Architecture() {
86 auto const Arch
= Section
.Find("Architecture");
87 return Arch
.empty() ? "none" : Arch
;
90 // ListParser::ArchitectureAll /*{{{*/
91 // ---------------------------------------------------------------------
93 bool debListParser::ArchitectureAll() {
94 return Section
.Find("Architecture") == "all";
97 // ListParser::Version - Return the version string /*{{{*/
98 // ---------------------------------------------------------------------
99 /* This is to return the string describing the version in debian form,
100 epoch:upstream-release. If this returns the blank string then the
101 entry is assumed to only describe package properties */
102 APT::StringView
debListParser::Version()
104 return Section
.Find("Version");
107 unsigned char debListParser::ParseMultiArch(bool const showErrors
) /*{{{*/
110 auto const MultiArch
= Section
.Find("Multi-Arch");
111 if (MultiArch
.empty() == true || MultiArch
== "no")
112 MA
= pkgCache::Version::No
;
113 else if (MultiArch
== "same") {
114 if (ArchitectureAll() == true)
116 if (showErrors
== true)
117 _error
->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
118 Section
.FindS("Package").c_str());
119 MA
= pkgCache::Version::No
;
122 MA
= pkgCache::Version::Same
;
124 else if (MultiArch
== "foreign")
125 MA
= pkgCache::Version::Foreign
;
126 else if (MultiArch
== "allowed")
127 MA
= pkgCache::Version::Allowed
;
130 if (showErrors
== true)
131 _error
->Warning("Unknown Multi-Arch type '%s' for package '%s'",
132 MultiArch
.to_string().c_str(), Section
.FindS("Package").c_str());
133 MA
= pkgCache::Version::No
;
136 if (ArchitectureAll() == true)
137 MA
|= pkgCache::Version::All
;
142 // ListParser::NewVersion - Fill in the version structure /*{{{*/
143 // ---------------------------------------------------------------------
145 bool debListParser::NewVersion(pkgCache::VerIterator
&Ver
)
151 if (Section
.Find("Section",Start
,Stop
) == true)
153 map_stringitem_t
const idx
= StoreString(pkgCacheGenerator::SECTION
, Start
, Stop
- Start
);
156 // Parse the source package name
157 pkgCache::GrpIterator G
= Ver
.ParentPkg().Group();
158 Ver
->SourcePkgName
= G
->Name
;
159 Ver
->SourceVerStr
= Ver
->VerStr
;
160 if (Section
.Find("Source",Start
,Stop
) == true)
162 const char * const Space
= (const char * const) memchr(Start
, ' ', Stop
- Start
);
163 pkgCache::VerIterator V
;
167 const char * const Open
= (const char * const) memchr(Space
, '(', Stop
- Space
);
168 if (likely(Open
!= NULL
))
170 const char * const Close
= (const char * const) memchr(Open
, ')', Stop
- Open
);
171 if (likely(Close
!= NULL
))
173 APT::StringView
const version(Open
+ 1, (Close
- Open
) - 1);
174 if (version
!= Ver
.VerStr())
176 map_stringitem_t
const idx
= StoreString(pkgCacheGenerator::VERSIONNUMBER
, version
);
177 G
= Ver
.ParentPkg().Group();
178 Ver
->SourceVerStr
= idx
;
185 APT::StringView
const pkgname(Start
, Stop
- Start
);
186 if (pkgname
!= G
.Name())
188 for (pkgCache::PkgIterator P
= G
.PackageList(); P
.end() == false; P
= G
.NextPkg(P
))
190 for (V
= P
.VersionList(); V
.end() == false; ++V
)
192 if (pkgname
== V
.SourcePkgName())
194 Ver
->SourcePkgName
= V
->SourcePkgName
;
198 if (V
.end() == false)
203 map_stringitem_t
const idx
= StoreString(pkgCacheGenerator::PKGNAME
, pkgname
);
204 G
= Ver
.ParentPkg().Group();
205 Ver
->SourcePkgName
= idx
;
210 Ver
->MultiArch
= ParseMultiArch(true);
212 Ver
->Size
= Section
.FindULL("Size");
213 // Unpacked Size (in K)
214 Ver
->InstalledSize
= Section
.FindULL("Installed-Size");
215 Ver
->InstalledSize
*= 1024;
218 if (Section
.Find("Priority",Start
,Stop
) == true)
220 if (GrabWord(StringView(Start
,Stop
-Start
),PrioList
,Ver
->Priority
) == false)
221 Ver
->Priority
= pkgCache::State::Extra
;
224 if (ParseDepends(Ver
,"Pre-Depends",pkgCache::Dep::PreDepends
) == false)
226 if (ParseDepends(Ver
,"Depends",pkgCache::Dep::Depends
) == false)
228 if (ParseDepends(Ver
,"Conflicts",pkgCache::Dep::Conflicts
) == false)
230 if (ParseDepends(Ver
,"Breaks",pkgCache::Dep::DpkgBreaks
) == false)
232 if (ParseDepends(Ver
,"Recommends",pkgCache::Dep::Recommends
) == false)
234 if (ParseDepends(Ver
,"Suggests",pkgCache::Dep::Suggests
) == false)
236 if (ParseDepends(Ver
,"Replaces",pkgCache::Dep::Replaces
) == false)
238 if (ParseDepends(Ver
,"Enhances",pkgCache::Dep::Enhances
) == false)
241 if (ParseDepends(Ver
,"Optional",pkgCache::Dep::Suggests
) == false)
244 if (ParseProvides(Ver
) == false)
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 static constexpr int prefixLen
= 12;
256 static constexpr int avgLanguageLen
= 5;
259 tagname
.reserve(prefixLen
+ avgLanguageLen
);
260 tagname
.assign("Description-");
261 if (Section
.Exists("Description") == true)
263 for (std::vector
<std::string
>::const_iterator lang
= understood
.begin(); lang
!= understood
.end(); ++lang
)
265 tagname
.resize(prefixLen
);
266 tagname
.append(*lang
);
267 if (Section
.Exists(tagname
) == true)
268 avail
.push_back(*lang
);
273 // ListParser::Description_md5 - Return the description_md5 MD5SumValue /*{{{*/
274 // ---------------------------------------------------------------------
275 /* This is to return the md5 string to allow the check if it is the right
276 description. If no Description-md5 is found in the section it will be
279 MD5SumValue
debListParser::Description_md5()
281 StringView
const value
= Section
.Find("Description-md5");
282 if (value
.empty() == true)
284 StringView
const desc
= Section
.Find("Description");
286 return MD5SumValue();
289 md5
.Add(desc
.data(), desc
.size());
293 else if (likely(value
.size() == 32))
295 MD5SumValue sumvalue
;
296 if (sumvalue
.Set(value
))
299 _error
->Error("Malformed Description-md5 line; includes invalid character '%.*s'", (int)value
.length(), value
.data());
300 return MD5SumValue();
302 _error
->Error("Malformed Description-md5 line; doesn't have the required length (32 != %d) '%.*s'", (int)value
.size(), (int)value
.length(), value
.data());
303 return MD5SumValue();
306 // ListParser::UsePackage - Update a package structure /*{{{*/
307 // ---------------------------------------------------------------------
308 /* This is called to update the package with any new information
309 that might be found in the section */
310 bool debListParser::UsePackage(pkgCache::PkgIterator
&Pkg
,
311 pkgCache::VerIterator
&Ver
)
313 string
const static myArch
= _config
->Find("APT::Architecture");
314 // Possible values are: "all", "native", "installed" and "none"
315 // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
316 string
const static essential
= _config
->Find("pkgCacheGen::Essential", "all");
317 if (essential
== "all" ||
318 (essential
== "native" && Pkg
->Arch
!= 0 && myArch
== Pkg
.Arch()))
319 if (Section
.FindFlag("Essential",Pkg
->Flags
,pkgCache::Flag::Essential
) == false)
321 if (Section
.FindFlag("Important",Pkg
->Flags
,pkgCache::Flag::Important
) == false)
324 if (std::find(forceEssential
.begin(), forceEssential
.end(), Pkg
.Name()) != forceEssential
.end())
326 if ((essential
== "native" && Pkg
->Arch
!= 0 && myArch
== Pkg
.Arch()) ||
328 Pkg
->Flags
|= pkgCache::Flag::Essential
| pkgCache::Flag::Important
;
330 Pkg
->Flags
|= pkgCache::Flag::Important
;
332 else if (std::find(forceImportant
.begin(), forceImportant
.end(), Pkg
.Name()) != forceImportant
.end())
333 Pkg
->Flags
|= pkgCache::Flag::Important
;
335 if (ParseStatus(Pkg
,Ver
) == false)
340 // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
341 // ---------------------------------------------------------------------
343 unsigned short debListParser::VersionHash()
345 static const StringView Sections
[] ={"Installed-Size",
353 unsigned long Result
= INIT_FCS
;
355 for (StringView I
: Sections
)
359 if (Section
.Find(I
,Start
,End
) == false)
362 /* Strip out any spaces from the text, this undoes dpkgs reformatting
363 of certain fields. dpkg also has the rather interesting notion of
364 reformatting depends operators < -> <= */
366 for (; Start
!= End
&& (J
- S
) < sizeof(S
); ++Start
)
368 if (isspace_ascii(*Start
) != 0)
370 *J
++ = tolower_ascii(*Start
);
372 /* Normalize <= to < and >= to >. This is the wrong way around, but
373 * more efficient that the right way. And since we're only hashing
374 * it does not matter which way we normalize. */
375 if ((*Start
== '<' || *Start
== '>') && Start
[1] == '=') {
380 Result
= AddCRC16(Result
,S
,J
- S
);
386 // StatusListParser::ParseStatus - Parse the status field /*{{{*/
387 // ---------------------------------------------------------------------
388 /* Status lines are of the form,
389 Status: want flag status
390 want = unknown, install, hold, deinstall, purge
392 status = not-installed, config-files, half-installed, unpacked,
393 half-configured, triggers-awaited, triggers-pending, installed
395 bool debListParser::ParseStatus(pkgCache::PkgIterator
&,
396 pkgCache::VerIterator
&)
400 bool debStatusListParser::ParseStatus(pkgCache::PkgIterator
&Pkg
,
401 pkgCache::VerIterator
&Ver
)
405 if (Section
.Find("Status",Start
,Stop
) == false)
408 // UsePackage() is responsible for setting the flag in the default case
409 bool const static essential
= _config
->Find("pkgCacheGen::Essential", "") == "installed";
410 if (essential
== true &&
411 Section
.FindFlag("Essential",Pkg
->Flags
,pkgCache::Flag::Essential
) == false)
414 // Isolate the first word
415 const char *I
= Start
;
416 for(; I
< Stop
&& *I
!= ' '; I
++);
417 if (I
>= Stop
|| *I
!= ' ')
418 return _error
->Error("Malformed Status line");
420 // Process the want field
421 WordList WantList
[] = {{"unknown",pkgCache::State::Unknown
},
422 {"install",pkgCache::State::Install
},
423 {"hold",pkgCache::State::Hold
},
424 {"deinstall",pkgCache::State::DeInstall
},
425 {"purge",pkgCache::State::Purge
},
427 if (GrabWord(StringView(Start
,I
-Start
),WantList
,Pkg
->SelectedState
) == false)
428 return _error
->Error("Malformed 1st word in the Status line");
430 // Isloate the next word
433 for(; I
< Stop
&& *I
!= ' '; I
++);
434 if (I
>= Stop
|| *I
!= ' ')
435 return _error
->Error("Malformed status line, no 2nd word");
437 // Process the flag field
438 WordList FlagList
[] = {{"ok",pkgCache::State::Ok
},
439 {"reinstreq",pkgCache::State::ReInstReq
},
440 {"hold",pkgCache::State::HoldInst
},
441 {"hold-reinstreq",pkgCache::State::HoldReInstReq
},
443 if (GrabWord(StringView(Start
,I
-Start
),FlagList
,Pkg
->InstState
) == false)
444 return _error
->Error("Malformed 2nd word in the Status line");
446 // Isloate the last word
449 for(; I
< Stop
&& *I
!= ' '; I
++);
451 return _error
->Error("Malformed Status line, no 3rd word");
453 // Process the flag field
454 WordList StatusList
[] = {{"not-installed",pkgCache::State::NotInstalled
},
455 {"config-files",pkgCache::State::ConfigFiles
},
456 {"half-installed",pkgCache::State::HalfInstalled
},
457 {"unpacked",pkgCache::State::UnPacked
},
458 {"half-configured",pkgCache::State::HalfConfigured
},
459 {"triggers-awaited",pkgCache::State::TriggersAwaited
},
460 {"triggers-pending",pkgCache::State::TriggersPending
},
461 {"installed",pkgCache::State::Installed
},
463 if (GrabWord(StringView(Start
,I
-Start
),StatusList
,Pkg
->CurrentState
) == false)
464 return _error
->Error("Malformed 3rd word in the Status line");
466 /* A Status line marks the package as indicating the current
467 version as well. Only if it is actually installed.. Otherwise
468 the interesting dpkg handling of the status file creates bogus
470 if (!(Pkg
->CurrentState
== pkgCache::State::NotInstalled
||
471 Pkg
->CurrentState
== pkgCache::State::ConfigFiles
))
473 if (Ver
.end() == true)
474 _error
->Warning("Encountered status field in a non-version description");
476 Pkg
->CurrentVer
= Ver
.Index();
482 const char *debListParser::ConvertRelation(const char *I
,unsigned int &Op
)
484 // Determine the operator
492 Op
= pkgCache::Dep::LessEq
;
499 Op
= pkgCache::Dep::Less
;
503 // < is the same as <= and << is really Cs < for some reason
504 Op
= pkgCache::Dep::LessEq
;
512 Op
= pkgCache::Dep::GreaterEq
;
519 Op
= pkgCache::Dep::Greater
;
523 // > is the same as >= and >> is really Cs > for some reason
524 Op
= pkgCache::Dep::GreaterEq
;
528 Op
= pkgCache::Dep::Equals
;
532 // HACK around bad package definitions
534 Op
= pkgCache::Dep::Equals
;
540 // ListParser::ParseDepends - Parse a dependency element /*{{{*/
541 // ---------------------------------------------------------------------
542 /* This parses the dependency elements out of a standard string in place,
544 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
545 std::string
&Package
,std::string
&Ver
,unsigned int &Op
)
546 { return ParseDepends(Start
, Stop
, Package
, Ver
, Op
, false, true, false); }
547 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
548 std::string
&Package
,std::string
&Ver
,unsigned int &Op
,
549 bool const &ParseArchFlags
)
550 { return ParseDepends(Start
, Stop
, Package
, Ver
, Op
, ParseArchFlags
, true, false); }
551 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
552 std::string
&Package
,std::string
&Ver
,unsigned int &Op
,
553 bool const &ParseArchFlags
, bool const &StripMultiArch
)
554 { return ParseDepends(Start
, Stop
, Package
, Ver
, Op
, ParseArchFlags
, StripMultiArch
, false); }
555 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
556 string
&Package
,string
&Ver
,
557 unsigned int &Op
, bool const &ParseArchFlags
,
558 bool const &StripMultiArch
,
559 bool const &ParseRestrictionsList
)
561 StringView PackageView
;
564 auto res
= ParseDepends(Start
, Stop
, PackageView
, VerView
, Op
, (bool)ParseArchFlags
,
565 (bool) StripMultiArch
, (bool) ParseRestrictionsList
);
566 Package
= PackageView
.to_string();
567 Ver
= VerView
.to_string();
571 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
572 StringView
&Package
,StringView
&Ver
,
573 unsigned int &Op
, bool ParseArchFlags
,
575 bool ParseRestrictionsList
)
577 // Strip off leading space
578 for (;Start
!= Stop
&& isspace_ascii(*Start
) != 0; ++Start
);
580 // Parse off the package name
581 const char *I
= Start
;
582 for (;I
!= Stop
&& isspace_ascii(*I
) == 0 && *I
!= '(' && *I
!= ')' &&
583 *I
!= ',' && *I
!= '|' && *I
!= '[' && *I
!= ']' &&
584 *I
!= '<' && *I
!= '>'; ++I
);
587 if (I
!= Stop
&& *I
== ')')
593 // Stash the package name
594 Package
= StringView(Start
, I
- Start
);
596 // We don't want to confuse library users which can't handle MultiArch
597 if (StripMultiArch
== true) {
598 string
const arch
= _config
->Find("APT::Architecture");
599 size_t const found
= Package
.rfind(':');
600 if (found
!= StringView::npos
&&
601 (Package
.substr(found
) == ":any" ||
602 Package
.substr(found
) == ":native" ||
603 Package
.substr(found
+1) == arch
))
604 Package
= Package
.substr(0,found
);
607 // Skip white space to the '('
608 for (;I
!= Stop
&& isspace_ascii(*I
) != 0 ; I
++);
611 if (I
!= Stop
&& *I
== '(')
614 for (I
++; I
!= Stop
&& isspace_ascii(*I
) != 0 ; I
++);
617 I
= ConvertRelation(I
,Op
);
620 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
622 I
= (const char*) memchr(I
, ')', Stop
- I
);
623 if (I
== NULL
|| Start
== I
)
626 // Skip trailing whitespace
628 for (; End
> Start
&& isspace_ascii(End
[-1]); End
--);
630 Ver
= StringView(Start
,End
-Start
);
636 Op
= pkgCache::Dep::NoOp
;
640 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
642 if (unlikely(ParseArchFlags
== true))
644 string
const arch
= _config
->Find("APT::Architecture");
645 APT::CacheFilter::PackageArchitectureMatchesSpecification
matchesArch(arch
, false);
647 // Parse an architecture
648 if (I
!= Stop
&& *I
== '[')
652 if (unlikely(I
== Stop
))
657 bool NegArch
= false;
660 // look for whitespace or ending ']'
661 for (;End
!= Stop
&& !isspace_ascii(*End
) && *End
!= ']'; ++End
);
663 if (unlikely(End
== Stop
))
672 std::string
const arch(I
, End
);
673 if (arch
.empty() == false && matchesArch(arch
.c_str()) == true)
678 // we found a match, so fast-forward to the end of the wildcards
679 for (; End
!= Stop
&& *End
!= ']'; ++End
);
688 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
695 Package
= ""; /* not for this arch */
699 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
702 if (unlikely(ParseRestrictionsList
== true))
704 // Parse a restrictions formula which is in disjunctive normal form:
705 // (foo AND bar) OR (blub AND bla)
707 std::vector
<string
> const profiles
= APT::Configuration::getBuildProfiles();
709 // if the next character is a restriction list, then by default the
710 // dependency does not apply and the conditions have to be checked
711 // if the next character is not a restriction list, then by default the
712 // dependency applies
713 bool applies1
= (*I
!= '<');
721 if (unlikely(I
== Stop
))
726 // if of the prior restriction list is already fulfilled, then
727 // we can just skip to the end of the current list
729 for (;End
!= Stop
&& *End
!= '>'; ++End
);
732 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
734 bool applies2
= true;
735 // all the conditions inside a restriction list have to be
736 // met so once we find one that is not met, we can skip to
737 // the end of this list
740 // look for whitespace or ending '>'
741 // End now points to the character after the current term
742 for (;End
!= Stop
&& !isspace_ascii(*End
) && *End
!= '>'; ++End
);
744 if (unlikely(End
== Stop
))
747 bool NegRestriction
= false;
750 NegRestriction
= true;
754 std::string
const restriction(I
, End
);
755 if (restriction
.empty() == false && profiles
.empty() == false &&
756 std::find(profiles
.begin(), profiles
.end(), restriction
) != profiles
.end())
758 if (NegRestriction
) {
760 // since one of the terms does not apply we don't have to check the others
761 for (; End
!= Stop
&& *End
!= '>'; ++End
);
764 if (!NegRestriction
) {
766 // since one of the terms does not apply we don't have to check the others
767 for (; End
!= Stop
&& *End
!= '>'; ++End
);
774 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
780 for (;I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
788 if (applies1
== false) {
789 Package
= ""; //not for this restriction
793 if (I
!= Stop
&& *I
== '|')
794 Op
|= pkgCache::Dep::Or
;
796 if (I
== Stop
|| *I
== ',' || *I
== '|')
799 for (I
++; I
!= Stop
&& isspace_ascii(*I
) != 0; I
++);
806 // ListParser::ParseDepends - Parse a dependency list /*{{{*/
807 // ---------------------------------------------------------------------
808 /* This is the higher level depends parser. It takes a tag and generates
809 a complete depends tree for the given version. */
810 bool debListParser::ParseDepends(pkgCache::VerIterator
&Ver
,
811 StringView Tag
,unsigned int Type
)
815 if (Section
.Find(Tag
,Start
,Stop
) == false || Start
== Stop
)
818 string
const pkgArch
= Ver
.Arch();
826 Start
= ParseDepends(Start
, Stop
, Package
, Version
, Op
, false, false, false);
828 return _error
->Error("Problem parsing dependency %.*s",(int)Tag
.length(), Tag
.data());
829 size_t const found
= Package
.rfind(':');
831 if (found
== string::npos
)
833 if (NewDepends(Ver
,Package
,pkgArch
,Version
,Op
,Type
) == false)
836 else if (Package
.substr(found
) == ":any")
838 if (NewDepends(Ver
,Package
,"any",Version
,Op
,Type
) == false)
843 // Such dependencies are not supposed to be accepted …
844 // … but this is probably the best thing to do anyway
845 if (Package
.substr(found
+ 1) == "native")
847 std::string
const Pkg
= Package
.substr(0, found
).to_string() + ':' + Ver
.Cache()->NativeArch();
848 if (NewDepends(Ver
, Pkg
, "any", Version
, Op
| pkgCache::Dep::ArchSpecific
, Type
) == false)
851 else if (NewDepends(Ver
, Package
, "any", Version
, Op
| pkgCache::Dep::ArchSpecific
, Type
) == false)
861 // ListParser::ParseProvides - Parse the provides list /*{{{*/
862 // ---------------------------------------------------------------------
864 bool debListParser::ParseProvides(pkgCache::VerIterator
&Ver
)
866 /* it is unlikely, but while parsing dependencies, we might have already
867 picked up multi-arch implicit provides which we do not want to duplicate here */
868 bool hasProvidesAlready
= false;
869 std::string
const spzName
= Ver
.ParentPkg().FullName(false);
871 for (pkgCache::PrvIterator Prv
= Ver
.ProvidesList(); Prv
.end() == false; ++Prv
)
873 if (Prv
.IsMultiArchImplicit() == false || (Prv
->Flags
& pkgCache::Flag::ArchSpecific
) == 0)
875 if (spzName
!= Prv
.OwnerPkg().FullName(false))
877 hasProvidesAlready
= true;
882 string
const Arch
= Ver
.Arch();
885 if (Section
.Find("Provides",Start
,Stop
) == true)
893 Start
= ParseDepends(Start
,Stop
,Package
,Version
,Op
, false, false, false);
894 const size_t archfound
= Package
.rfind(':');
896 return _error
->Error("Problem parsing Provides line");
897 if (unlikely(Op
!= pkgCache::Dep::NoOp
&& Op
!= pkgCache::Dep::Equals
)) {
898 _error
->Warning("Ignoring Provides line with non-equal DepCompareOp for package %s", Package
.to_string().c_str());
899 } else if (archfound
!= string::npos
) {
900 StringView spzArch
= Package
.substr(archfound
+ 1);
901 if (spzArch
!= "any")
903 if (NewProvides(Ver
, Package
.substr(0, archfound
), spzArch
, Version
, pkgCache::Flag::MultiArchImplicit
| pkgCache::Flag::ArchSpecific
) == false)
906 if (NewProvides(Ver
, Package
, "any", Version
, pkgCache::Flag::ArchSpecific
) == false)
908 } else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
) {
909 if (APT::Configuration::checkArchitecture(Arch
))
911 if (NewProvidesAllArch(Ver
, Package
, Version
, 0) == false)
914 else if (NewProvides(Ver
, Package
, Arch
, Version
, 0) == false)
917 if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
919 if (NewProvides(Ver
, Package
.to_string().append(":any"), "any", Version
, pkgCache::Flag::MultiArchImplicit
) == false)
922 if (NewProvides(Ver
, Package
, Arch
, Version
, 0) == false)
925 if (archfound
== std::string::npos
)
927 string spzName
= Package
.to_string();
928 spzName
.push_back(':');
929 spzName
.append(Ver
.ParentPkg().Arch());
930 pkgCache::PkgIterator
const spzPkg
= Ver
.Cache()->FindPkg(spzName
, "any");
931 if (spzPkg
.end() == false)
933 if (NewProvides(Ver
, spzName
, "any", Version
, pkgCache::Flag::MultiArchImplicit
| pkgCache::Flag::ArchSpecific
) == false)
937 } while (Start
!= Stop
);
940 if (APT::Configuration::checkArchitecture(Arch
))
942 if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
944 string
const Package
= string(Ver
.ParentPkg().Name()).append(":").append("any");
945 if (NewProvides(Ver
, Package
, "any", Ver
.VerStr(), pkgCache::Flag::MultiArchImplicit
) == false)
948 else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
950 if (NewProvidesAllArch(Ver
, Ver
.ParentPkg().Name(), Ver
.VerStr(), pkgCache::Flag::MultiArchImplicit
) == false)
955 if (hasProvidesAlready
== false)
957 pkgCache::PkgIterator
const spzPkg
= Ver
.Cache()->FindPkg(spzName
, "any");
958 if (spzPkg
.end() == false)
960 if (NewProvides(Ver
, spzName
, "any", Ver
.VerStr(), pkgCache::Flag::MultiArchImplicit
| pkgCache::Flag::ArchSpecific
) == false)
967 // ListParser::GrabWord - Matches a word and returns /*{{{*/
968 // ---------------------------------------------------------------------
969 /* Looks for a word in a list of words - for ParseStatus */
970 bool debListParser::GrabWord(StringView Word
, WordList
const *List
, unsigned char &Out
)
972 for (unsigned int C
= 0; List
[C
].Str
.empty() == false; C
++)
974 if (Word
.length() == List
[C
].Str
.length() &&
975 strncasecmp(Word
.data(), List
[C
].Str
.data(), Word
.length()) == 0)
984 // ListParser::Step - Move to the next section in the file /*{{{*/
985 // ---------------------------------------------------------------------
986 /* This has to be careful to only process the correct architecture */
987 bool debListParser::Step()
989 iOffset
= Tags
.Offset();
990 return Tags
.Step(Section
);
993 // ListParser::GetPrio - Convert the priority from a string /*{{{*/
994 // ---------------------------------------------------------------------
996 unsigned char debListParser::GetPrio(string Str
)
999 if (GrabWord(Str
,PrioList
,Out
) == false)
1000 Out
= pkgCache::State::Extra
;
1005 bool debListParser::SameVersion(unsigned short const Hash
, /*{{{*/
1006 pkgCache::VerIterator
const &Ver
)
1008 if (pkgCacheListParser::SameVersion(Hash
, Ver
) == false)
1010 // status file has no (Download)Size, but all others are fair game
1011 // status file is parsed last, so the first version we encounter is
1012 // probably also the version we have downloaded
1013 unsigned long long const Size
= Section
.FindULL("Size");
1014 if (Size
!= 0 && Ver
->Size
!= 0 && Size
!= Ver
->Size
)
1016 // available everywhere, but easier to check here than to include in VersionHash
1017 unsigned char MultiArch
= ParseMultiArch(false);
1018 if (MultiArch
!= Ver
->MultiArch
)
1020 // for all practical proposes (we can check): same version
1025 debDebFileParser::debDebFileParser(FileFd
*File
, std::string
const &DebFile
)
1026 : debListParser(File
), DebFile(DebFile
)
1030 bool debDebFileParser::UsePackage(pkgCache::PkgIterator
&Pkg
,
1031 pkgCache::VerIterator
&Ver
)
1033 bool res
= debListParser::UsePackage(Pkg
, Ver
);
1034 // we use the full file path as a provides so that the file is found
1036 if(NewProvides(Ver
, DebFile
, Pkg
.Cache()->NativeArch(), Ver
.VerStr(), 0) == false)
1041 debListParser::~debListParser() {}