libzypp 17.31.23
RpmHeader.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include "librpm.h"
13
14#include <cstring>
15
16#include <zypp/AutoDispose.h>
17
19// unameToUid and gnameToGid are shamelessly stolen from rpm-4.4.
20// (rpmio/ugid.c) Those functions were dropped in RPM_4_7
21extern "C"
22{
23#include <pwd.h>
24#include <grp.h>
25}
26/* unameToUid(), uidTouname() and the group variants are really poorly
27 implemented. They really ought to use hash tables. I just made the
28 guess that most files would be owned by root or the same person/group
29 who owned the last file. Those two values are cached, everything else
30 is looked up via getpw() and getgr() functions. If this performs
31 too poorly I'll have to implement it properly :-( */
32
33int unameToUid(const char * thisUname, uid_t * uid)
34{
35/*@only@*/ static char * lastUname = NULL;
36 static size_t lastUnameLen = 0;
37 static size_t lastUnameAlloced;
38 static uid_t lastUid;
39 struct passwd * pwent;
40 size_t thisUnameLen;
41
42 if (!thisUname) {
43 lastUnameLen = 0;
44 return -1;
45 } else if (strcmp(thisUname, "root") == 0) {
46/*@-boundswrite@*/
47 *uid = 0;
48/*@=boundswrite@*/
49 return 0;
50 }
51
52 thisUnameLen = strlen(thisUname);
53 if (lastUname == NULL || thisUnameLen != lastUnameLen ||
54 strcmp(thisUname, lastUname) != 0)
55 {
56 if (lastUnameAlloced < thisUnameLen + 1) {
57 lastUnameAlloced = thisUnameLen + 10;
58 lastUname = (char *)realloc(lastUname, lastUnameAlloced); /* XXX memory leak */
59 }
60/*@-boundswrite@*/
61 strcpy(lastUname, thisUname);
62/*@=boundswrite@*/
63
64 pwent = getpwnam(thisUname);
65 if (pwent == NULL) {
66 /*@-internalglobs@*/ /* FIX: shrug */
67 endpwent();
68 /*@=internalglobs@*/
69 pwent = getpwnam(thisUname);
70 if (pwent == NULL) return -1;
71 }
72
73 lastUid = pwent->pw_uid;
74 }
75
76/*@-boundswrite@*/
77 *uid = lastUid;
78/*@=boundswrite@*/
79
80 return 0;
81}
82
83int gnameToGid(const char * thisGname, gid_t * gid)
84{
85/*@only@*/ static char * lastGname = NULL;
86 static size_t lastGnameLen = 0;
87 static size_t lastGnameAlloced;
88 static gid_t lastGid;
89 size_t thisGnameLen;
90 struct group * grent;
91
92 if (thisGname == NULL) {
93 lastGnameLen = 0;
94 return -1;
95 } else if (strcmp(thisGname, "root") == 0) {
96/*@-boundswrite@*/
97 *gid = 0;
98/*@=boundswrite@*/
99 return 0;
100 }
101
102 thisGnameLen = strlen(thisGname);
103 if (lastGname == NULL || thisGnameLen != lastGnameLen ||
104 strcmp(thisGname, lastGname) != 0)
105 {
106 if (lastGnameAlloced < thisGnameLen + 1) {
107 lastGnameAlloced = thisGnameLen + 10;
108 lastGname = (char *)realloc(lastGname, lastGnameAlloced); /* XXX memory leak */
109 }
110/*@-boundswrite@*/
111 strcpy(lastGname, thisGname);
112/*@=boundswrite@*/
113
114 grent = getgrnam(thisGname);
115 if (grent == NULL) {
116 /*@-internalglobs@*/ /* FIX: shrug */
117 endgrent();
118 /*@=internalglobs@*/
119 grent = getgrnam(thisGname);
120 if (grent == NULL) {
121 /* XXX The filesystem package needs group/lock w/o getgrnam. */
122 if (strcmp(thisGname, "lock") == 0) {
123/*@-boundswrite@*/
124 *gid = lastGid = 54;
125/*@=boundswrite@*/
126 return 0;
127 } else
128 if (strcmp(thisGname, "mail") == 0) {
129/*@-boundswrite@*/
130 *gid = lastGid = 12;
131/*@=boundswrite@*/
132 return 0;
133 } else
134 return -1;
135 }
136 }
137 lastGid = grent->gr_gid;
138 }
139
140/*@-boundswrite@*/
141 *gid = lastGid;
142/*@=boundswrite@*/
143
144 return 0;
145}
147
148#include <iostream>
149#include <map>
150#include <set>
151#include <vector>
152
153#include <zypp/base/Easy.h>
154#include <zypp/base/Logger.h>
155#include <zypp/base/Exception.h>
156
159#include <zypp/Package.h>
160#include <zypp/PathInfo.h>
161
162using std::endl;
163
164namespace zypp
165{
166namespace target
167{
168namespace rpm
169{
170
172
174//
175//
176// METHOD NAME : RpmHeader::RpmHeader
177// METHOD TYPE : Constructor
178//
179// DESCRIPTION :
180//
182 : BinHeader( h_r )
183{}
184
186//
187//
188// METHOD NAME : RpmHeader::RpmHeader
189// METHOD TYPE : Constructor
190//
192 : BinHeader( rhs )
193{}
194
196//
197//
198// METHOD NAME : RpmHeader::~RpmHeader
199// METHOD TYPE : Destructor
200//
201// DESCRIPTION :
202//
204{}
205
207//
208//
209// METHOD NAME : RpmHeader::readPackage
210// METHOD TYPE : constRpmHeaderPtr
211//
213 VERIFICATION verification_r )
214{
215
217 zypp::AutoDispose<rpmts> ts ( ::rpmtsCreate(), ::rpmtsFree );
218 unsigned vsflag = RPMVSF_DEFAULT;
219 if ( verification_r & NODIGEST )
220 vsflag |= _RPMVSF_NODIGESTS;
221 if ( verification_r & NOSIGNATURE )
222 vsflag |= _RPMVSF_NOSIGNATURES;
223 ::rpmtsSetVSFlags( ts, rpmVSFlags(vsflag) );
224
225 return readPackage( ts, path_r ).first;
226}
227
228std::pair<RpmHeader::Ptr, int> RpmHeader::readPackage( rpmts ts_r, const zypp::filesystem::Pathname &path_r )
229{
230 PathInfo file( path_r );
231 if ( ! file.isFile() )
232 {
233 ERR << "Not a file: " << file << endl;
234 return std::make_pair( RpmHeader::Ptr(), -1 );
235 }
236
237 FD_t fd = ::Fopen( file.asString().c_str(), "r.ufdio" );
238 if ( fd == 0 || ::Ferror(fd) )
239 {
240 ERR << "Can't open file for reading: " << file << " (" << ::Fstrerror(fd) << ")" << endl;
241 if ( fd )
242 ::Fclose( fd );
243 return std::make_pair( RpmHeader::Ptr(), -1 );
244 }
245
246 Header nh = 0;
247 int res = ::rpmReadPackageFile( ts_r, fd, path_r.asString().c_str(), &nh );
248 ::Fclose( fd );
249
250 if ( ! nh )
251 {
252 WAR << "Error reading header from " << path_r << " error(" << res << ")" << endl;
253 return std::make_pair( RpmHeader::Ptr(), res );
254 }
255
256 RpmHeader::Ptr h( new RpmHeader( nh ) );
257 headerFree( nh ); // clear the reference set in ReadPackageFile
258
259 MIL << h << " from " << path_r << endl;
260 return std::make_pair( h, res );
261}
262
264//
265//
266// METHOD NAME : RpmHeader::dumpOn
267// METHOD TYPE : std::ostream &
268//
269// DESCRIPTION :
270//
271std::ostream & RpmHeader::dumpOn( std::ostream & str ) const
272{
273 BinHeader::dumpOn( str ) << '{' << tag_name() << "-";
274 if ( tag_epoch() != 0 )
275 str << tag_epoch() << ":";
276 str << tag_version()
277 << (tag_release().empty()?"":(std::string("-")+tag_release()))
278 << ( isSrc() ? ".src}" : "}");
279 return str;
280}
281
282
284//
285//
286// METHOD NAME : RpmHeader::isSrc
287// METHOD TYPE : bool
288//
290{
291 return has_tag( RPMTAG_SOURCEPACKAGE );
292}
293
295{
296 return has_tag( RPMTAG_SOURCEPACKAGE ) && ( has_tag( RPMTAG_NOSOURCE ) || has_tag( RPMTAG_NOPATCH ) );
297}
298
299std::string RpmHeader::ident() const
300{
301 static str::Format fmt { "%1%-%2%-%3%.%4%" };
302 std::string ret;
303 if ( not empty() )
304 ret = fmt % tag_name() % tag_version() % tag_release() % tag_arch();
305 return ret;
306}
307
309//
310//
311// METHOD NAME : RpmHeader::tag_name
312// METHOD TYPE : std::string
313//
314// DESCRIPTION :
315//
316std::string RpmHeader::tag_name() const
317{
318 return string_val( RPMTAG_NAME );
319}
320
322//
323//
324// METHOD NAME : RpmHeader::tag_epoch
325// METHOD TYPE : Edition::epoch_t
326//
327// DESCRIPTION :
328//
330{
331 return int_val ( RPMTAG_EPOCH );
332}
333
335//
336//
337// METHOD NAME : RpmHeader::tag_version
338// METHOD TYPE : std::string
339//
340// DESCRIPTION :
341//
342std::string RpmHeader::tag_version() const
343{
344 return string_val ( RPMTAG_VERSION );
345}
346
348//
349//
350// METHOD NAME : RpmHeader::tag_release
351// METHOD TYPE : std::string
352//
353// DESCRIPTION :
354//
355std::string RpmHeader::tag_release() const
356{
357 return string_val( RPMTAG_RELEASE );
358}
359
361//
362//
363// METHOD NAME : RpmHeader::tag_edition
364// METHOD TYPE : Edition
365//
366// DESCRIPTION :
367//
369{
370 return Edition( tag_version(), tag_release(), tag_epoch() );
371}
372
374//
375//
376// METHOD NAME : RpmHeader::tag_arch
377// METHOD TYPE : Arch
378//
379// DESCRIPTION :
380//
382{
383 return Arch( string_val( RPMTAG_ARCH ) );
384}
385
387//
388//
389// METHOD NAME : RpmHeader::tag_installtime
390// METHOD TYPE : Date
391//
392// DESCRIPTION :
393//
395{
396 return int_val( RPMTAG_INSTALLTIME );
397}
398
400//
401//
402// METHOD NAME : RpmHeader::tag_buildtime
403// METHOD TYPE : Date
404//
405// DESCRIPTION :
406//
408{
409 return int_val( RPMTAG_BUILDTIME );
410}
411
413//
414//
415// METHOD NAME : RpmHeader::PkgRelList_val
416// METHOD TYPE : CapabilitySet
417//
418// DESCRIPTION :
419//
420CapabilitySet RpmHeader::PkgRelList_val( tag tag_r, bool pre, std::set<std::string> * freq_r ) const
421 {
422 CapabilitySet ret;
423
424 rpmTag kindFlags = rpmTag(0);
425 rpmTag kindVersion = rpmTag(0);
426
427 switch ( tag_r )
428 {
429 case RPMTAG_REQUIRENAME:
430 kindFlags = RPMTAG_REQUIREFLAGS;
431 kindVersion = RPMTAG_REQUIREVERSION;
432 break;
433 case RPMTAG_PROVIDENAME:
434 kindFlags = RPMTAG_PROVIDEFLAGS;
435 kindVersion = RPMTAG_PROVIDEVERSION;
436 break;
437 case RPMTAG_OBSOLETENAME:
438 kindFlags = RPMTAG_OBSOLETEFLAGS;
439 kindVersion = RPMTAG_OBSOLETEVERSION;
440 break;
441 case RPMTAG_CONFLICTNAME:
442 kindFlags = RPMTAG_CONFLICTFLAGS;
443 kindVersion = RPMTAG_CONFLICTVERSION;
444 break;
445#ifdef RPMTAG_OLDSUGGESTS
446 case RPMTAG_OLDENHANCESNAME:
447 kindFlags = RPMTAG_OLDENHANCESFLAGS;
448 kindVersion = RPMTAG_OLDENHANCESVERSION;
449 break;
450 case RPMTAG_OLDSUGGESTSNAME:
451 kindFlags = RPMTAG_OLDSUGGESTSFLAGS;
452 kindVersion = RPMTAG_OLDSUGGESTSVERSION;
453 break;
454 case RPMTAG_RECOMMENDNAME:
455 kindFlags = RPMTAG_RECOMMENDFLAGS;
456 kindVersion = RPMTAG_RECOMMENDVERSION;
457 break;
458 case RPMTAG_SUPPLEMENTNAME:
459 kindFlags = RPMTAG_SUPPLEMENTFLAGS;
460 kindVersion = RPMTAG_SUPPLEMENTVERSION;
461 break;
462 case RPMTAG_SUGGESTNAME:
463 kindFlags = RPMTAG_SUGGESTFLAGS;
464 kindVersion = RPMTAG_SUGGESTVERSION;
465 break;
466 case RPMTAG_ENHANCENAME:
467 kindFlags = RPMTAG_ENHANCEFLAGS;
468 kindVersion = RPMTAG_ENHANCEVERSION;
469 break;
470#else
471 case RPMTAG_ENHANCESNAME:
472 kindFlags = RPMTAG_ENHANCESFLAGS;
473 kindVersion = RPMTAG_ENHANCESVERSION;
474 break;
475 case RPMTAG_SUGGESTSNAME:
476 kindFlags = RPMTAG_SUGGESTSFLAGS;
477 kindVersion = RPMTAG_SUGGESTSVERSION;
478 break;
479#endif
480 default:
481 INT << "Illegal RPMTAG_dependencyNAME " << tag_r << endl;
482 return ret;
483 break;
484 }
485
486 stringList names;
487 unsigned count = string_list( tag_r, names );
488 if ( !count )
489 return ret;
490
491 intList flags;
492 int_list( kindFlags, flags );
493
494 stringList versions;
495 string_list( kindVersion, versions );
496
497 for ( unsigned i = 0; i < count; ++i )
498 {
499
500 std::string n( names[i] );
501
502 Rel op = Rel::ANY;
503 int32_t f = flags[i];
504 std::string v = versions[i];
505
506 if ( n[0] == '/' )
507 {
508 if ( freq_r )
509 {
510 freq_r->insert( n );
511 }
512 }
513 else
514 {
515 if ( v.size() )
516 {
517 switch ( f & RPMSENSE_SENSEMASK )
518 {
519 case RPMSENSE_LESS:
520 op = Rel::LT;
521 break;
522 case RPMSENSE_LESS|RPMSENSE_EQUAL:
523 op = Rel::LE;
524 break;
525 case RPMSENSE_GREATER:
526 op = Rel::GT;
527 break;
528 case RPMSENSE_GREATER|RPMSENSE_EQUAL:
529 op = Rel::GE;
530 break;
531 case RPMSENSE_EQUAL:
532 op = Rel::EQ;
533 break;
534 }
535 }
536 }
537 if ((pre && (f & RPMSENSE_PREREQ))
538 || ((! pre) && !(f & RPMSENSE_PREREQ)))
539 {
540 try
541 {
542 ret.insert( Capability( n, op, Edition(v) ) );
543 }
544 catch (Exception & excpt_r)
545 {
546 ZYPP_CAUGHT(excpt_r);
547 WAR << "Invalid capability: " << n << " " << op << " "
548 << v << endl;
549 }
550 }
551 }
552
553 return ret;
554 }
555
557//
558//
559// METHOD NAME : RpmHeader::tag_provides
560// METHOD TYPE : CapabilitySet
561//
562// DESCRIPTION :
563//
564CapabilitySet RpmHeader::tag_provides( std::set<std::string> * freq_r ) const
565 {
566 return PkgRelList_val( RPMTAG_PROVIDENAME, false, freq_r );
567 }
568
570//
571//
572// METHOD NAME : RpmHeader::tag_requires
573// METHOD TYPE : CapabilitySet
574//
575// DESCRIPTION :
576//
577CapabilitySet RpmHeader::tag_requires( std::set<std::string> * freq_r ) const
578 {
579 return PkgRelList_val( RPMTAG_REQUIRENAME, false, freq_r );
580 }
581
583//
584//
585// METHOD NAME : RpmHeader::tag_requires
586// METHOD TYPE : CapabilitySet
587//
588// DESCRIPTION :
589//
590CapabilitySet RpmHeader::tag_prerequires( std::set<std::string> * freq_r ) const
591 {
592 return PkgRelList_val( RPMTAG_REQUIRENAME, true, freq_r );
593 }
594
596//
597//
598// METHOD NAME : RpmHeader::tag_conflicts
599// METHOD TYPE : CapabilitySet
600//
601// DESCRIPTION :
602//
603CapabilitySet RpmHeader::tag_conflicts( std::set<std::string> * freq_r ) const
604 {
605 return PkgRelList_val( RPMTAG_CONFLICTNAME, false, freq_r );
606 }
607
609//
610//
611// METHOD NAME : RpmHeader::tag_obsoletes
612// METHOD TYPE : CapabilitySet
613//
614// DESCRIPTION :
615//
616CapabilitySet RpmHeader::tag_obsoletes( std::set<std::string> * freq_r ) const
617 {
618 return PkgRelList_val( RPMTAG_OBSOLETENAME, false, freq_r );
619 }
620
622//
623//
624// METHOD NAME : RpmHeader::tag_enhances
625// METHOD TYPE : CapabilitySet
626//
627// DESCRIPTION :
628//
629CapabilitySet RpmHeader::tag_enhances( std::set<std::string> * freq_r ) const
630 {
631#ifdef RPMTAG_OLDSUGGESTS
632 return PkgRelList_val( RPMTAG_ENHANCENAME, false, freq_r );
633#else
634 return PkgRelList_val( RPMTAG_ENHANCESNAME, false, freq_r );
635#endif
636 }
637
639//
640//
641// METHOD NAME : RpmHeader::tag_suggests
642// METHOD TYPE : CapabilitySet
643//
644// DESCRIPTION :
645//
646CapabilitySet RpmHeader::tag_suggests( std::set<std::string> * freq_r ) const
647 {
648#ifdef RPMTAG_OLDSUGGESTS
649 return PkgRelList_val( RPMTAG_SUGGESTNAME, false, freq_r );
650#else
651 return PkgRelList_val( RPMTAG_SUGGESTSNAME, false, freq_r );
652#endif
653 }
654
656//
657//
658// METHOD NAME : RpmHeader::tag_supplements
659// METHOD TYPE : CapabilitySet
660//
661// DESCRIPTION :
662//
663CapabilitySet RpmHeader::tag_supplements( std::set<std::string> * freq_r ) const
664 {
665#ifdef RPMTAG_OLDSUGGESTS
666 return PkgRelList_val( RPMTAG_SUPPLEMENTNAME, false, freq_r );
667#else
668 return CapabilitySet();
669#endif
670 }
671
673//
674//
675// METHOD NAME : RpmHeader::tag_recommends
676// METHOD TYPE : CapabilitySet
677//
678// DESCRIPTION :
679//
680CapabilitySet RpmHeader::tag_recommends( std::set<std::string> * freq_r ) const
681 {
682#ifdef RPMTAG_OLDSUGGESTS
683 return PkgRelList_val( RPMTAG_RECOMMENDNAME, false, freq_r );
684#else
685 return CapabilitySet();
686#endif
687 }
688
690//
691//
692// METHOD NAME : RpmHeader::tag_size
693// METHOD TYPE : ByteCount
694//
695// DESCRIPTION :
696//
698{
699 return int_val( RPMTAG_SIZE );
700}
701
703//
704//
705// METHOD NAME : RpmHeader::tag_archivesize
706// METHOD TYPE : ByteCount
707//
708// DESCRIPTION :
709//
711{
712 return int_val( RPMTAG_ARCHIVESIZE );
713}
714
716//
717//
718// METHOD NAME : RpmHeader::tag_summary
719// METHOD TYPE : std::string
720//
721// DESCRIPTION :
722//
723std::string RpmHeader::tag_summary() const
724{
725 return string_val( RPMTAG_SUMMARY );
726}
727
729//
730//
731// METHOD NAME : RpmHeader::tag_description
732// METHOD TYPE : std::string
733//
734// DESCRIPTION :
735//
736std::string RpmHeader::tag_description() const
737{
738 return string_val( RPMTAG_DESCRIPTION );
739}
740
742//
743//
744// METHOD NAME : RpmHeader::tag_group
745// METHOD TYPE : std::string
746//
747// DESCRIPTION :
748//
749std::string RpmHeader::tag_group() const
750{
751 return string_val( RPMTAG_GROUP );
752}
753
755//
756//
757// METHOD NAME : RpmHeader::tag_vendor
758// METHOD TYPE : std::string
759//
760// DESCRIPTION :
761//
762std::string RpmHeader::tag_vendor() const
763{
764 return string_val( RPMTAG_VENDOR );
765}
766
768//
769//
770// METHOD NAME : RpmHeader::tag_distribution
771// METHOD TYPE : std::string
772//
773// DESCRIPTION :
774//
776{
777 return string_val( RPMTAG_DISTRIBUTION );
778}
779
781//
782//
783// METHOD NAME : RpmHeader::tag_license
784// METHOD TYPE : std::string
785//
786// DESCRIPTION :
787//
788std::string RpmHeader::tag_license() const
789{
790 return string_val( RPMTAG_LICENSE );
791}
792
794//
795//
796// METHOD NAME : RpmHeader::tag_buildhost
797// METHOD TYPE : std::string
798//
799// DESCRIPTION :
800//
801std::string RpmHeader::tag_buildhost() const
802{
803 return string_val( RPMTAG_BUILDHOST );
804}
805
807//
808//
809// METHOD NAME : RpmHeader::tag_packager
810// METHOD TYPE : std::string
811//
812// DESCRIPTION :
813//
814std::string RpmHeader::tag_packager() const
815{
816 return string_val( RPMTAG_PACKAGER );
817}
818
820//
821//
822// METHOD NAME : RpmHeader::tag_url
823// METHOD TYPE : std::string
824//
825// DESCRIPTION :
826//
827std::string RpmHeader::tag_url() const
828{
829 return string_val( RPMTAG_URL );
830}
831
833//
834//
835// METHOD NAME : RpmHeader::tag_os
836// METHOD TYPE : std::string
837//
838// DESCRIPTION :
839//
840std::string RpmHeader::tag_os() const
841{
842 return string_val( RPMTAG_OS );
843
844}
845
846std::string RpmHeader::tag_prein() const
847{ return string_val( RPMTAG_PREIN ); }
848
849std::string RpmHeader::tag_preinprog() const
850{ return string_val( RPMTAG_PREINPROG ); }
851
852std::string RpmHeader::tag_postin() const
853{ return string_val( RPMTAG_POSTIN ); }
854
855std::string RpmHeader::tag_postinprog() const
856{ return string_val( RPMTAG_POSTINPROG ); }
857
858std::string RpmHeader::tag_preun() const
859{ return string_val( RPMTAG_PREUN ); }
860
861std::string RpmHeader::tag_preunprog() const
862{ return string_val( RPMTAG_PREUNPROG ); }
863
864std::string RpmHeader::tag_postun() const
865{ return string_val( RPMTAG_POSTUN ); }
866
867std::string RpmHeader::tag_postunprog() const
868{ return string_val( RPMTAG_POSTUNPROG ); }
869
870std::string RpmHeader::tag_pretrans() const
871{ return string_val( RPMTAG_PRETRANS ); }
872
874{ return string_val( RPMTAG_PRETRANSPROG ); }
875
876std::string RpmHeader::tag_posttrans() const
877{ return string_val( RPMTAG_POSTTRANS ); }
878
880{ return string_val( RPMTAG_POSTTRANSPROG ); }
881
883//
884//
885// METHOD NAME : RpmHeader::tag_sourcerpm
886// METHOD TYPE : std::string
887//
888// DESCRIPTION :
889//
890std::string RpmHeader::tag_sourcerpm() const
891{
892 return string_val( RPMTAG_SOURCERPM );
893}
894
895std::string RpmHeader::signatureKeyID() const
896{
897 std::string sigInfo = format("%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|");
898
899 //no signature, return empty string
900 if ( sigInfo == "(none)" )
901 return std::string();
902
903 std::vector<std::string> words;
904 str::split( sigInfo, std::back_inserter(words), ",");
905 if ( words.size() < 3)
906 return std::string();
907
908 const std::string &keyId = words[2];
909 if ( !str::startsWith(keyId, " Key ID "))
910 return std::string();
911
912 return str::toUpper( words[2].substr(8) );
913}
914
916//
917//
918// METHOD NAME : RpmHeader::tag_filenames
919// METHOD TYPE : std::list<std::string>
920//
921// DESCRIPTION :
922//
923std::list<std::string> RpmHeader::tag_filenames() const
924{
925 std::list<std::string> ret;
926
927 stringList basenames;
928 if ( string_list( RPMTAG_BASENAMES, basenames ) )
929 {
930 stringList dirnames;
931 string_list( RPMTAG_DIRNAMES, dirnames );
932 intList dirindexes;
933 int_list( RPMTAG_DIRINDEXES, dirindexes );
934 for ( unsigned i = 0; i < basenames.size(); ++ i )
935 {
936 ret.push_back( dirnames[dirindexes[i]] + basenames[i] );
937 }
938 }
939
940 return ret;
941}
942
944//
945//
946// METHOD NAME : RpmHeader::tag_fileinfos
947// METHOD TYPE : std::list<FileInfo>
948//
949// DESCRIPTION :
950//
951std::list<FileInfo> RpmHeader::tag_fileinfos() const
952{
953 std::list<FileInfo> ret;
954
955 stringList basenames;
956 if ( string_list( RPMTAG_BASENAMES, basenames ) )
957 {
958 stringList dirnames;
959 string_list( RPMTAG_DIRNAMES, dirnames );
960 intList dirindexes;
961 int_list( RPMTAG_DIRINDEXES, dirindexes );
962 intList filesizes;
963 int_list( RPMTAG_FILESIZES, filesizes );
964 stringList md5sums;
965 string_list( RPMTAG_FILEMD5S, md5sums );
966 stringList usernames;
967 string_list( RPMTAG_FILEUSERNAME, usernames );
968 stringList groupnames;
969 string_list( RPMTAG_FILEGROUPNAME, groupnames );
970 intList uids;
971 int_list( RPMTAG_FILEUIDS, uids );
972 intList gids;
973 int_list( RPMTAG_FILEGIDS, gids );
974 intList filemodes;
975 int_list( RPMTAG_FILEMODES, filemodes );
976 intList filemtimes;
977 int_list( RPMTAG_FILEMTIMES, filemtimes );
978 intList fileflags;
979 int_list( RPMTAG_FILEFLAGS, fileflags );
980 stringList filelinks;
981 string_list( RPMTAG_FILELINKTOS, filelinks );
982
983 for ( unsigned i = 0; i < basenames.size(); ++ i )
984 {
985 uid_t uid;
986 if (uids.empty())
987 {
988 uid = unameToUid( usernames[i].c_str(), &uid );
989 }
990 else
991 {
992 uid =uids[i];
993 }
994
995 gid_t gid;
996 if (gids.empty())
997 {
998 gid = gnameToGid( groupnames[i].c_str(), &gid );
999 }
1000 else
1001 {
1002 gid = gids[i];
1003 }
1004
1005 FileInfo info = {
1006 dirnames[dirindexes[i]] + basenames[i],
1007 filesizes[i],
1008 md5sums[i],
1009 uid,
1010 gid,
1011 mode_t(filemodes[i]),
1012 filemtimes[i],
1013 bool(fileflags[i] & RPMFILE_GHOST),
1014 filelinks[i]
1015 };
1016
1017 ret.push_back( info );
1018 }
1019 }
1020
1021 return ret;
1022}
1023
1025//
1026//
1027// METHOD NAME : RpmHeader::tag_changelog
1028// METHOD TYPE : Changelog
1029//
1030// DESCRIPTION :
1031//
1033{
1034 Changelog ret;
1035
1036 intList times;
1037 if ( int_list( RPMTAG_CHANGELOGTIME, times ) )
1038 {
1039 stringList names;
1040 string_list( RPMTAG_CHANGELOGNAME, names );
1041 stringList texts;
1042 string_list( RPMTAG_CHANGELOGTEXT, texts );
1043 for ( unsigned i = 0; i < times.size(); ++ i )
1044 {
1045 ret.push_back( ChangelogEntry( times[i], names[i], texts[i] ) );
1046 }
1047 }
1048
1049 return ret;
1050}
1051
1052} // namespace rpm
1053} // namespace target
1054} // namespace zypp
int gnameToGid(const char *thisGname, gid_t *gid)
Definition: RpmHeader.cc:83
int unameToUid(const char *thisUname, uid_t *uid)
Definition: RpmHeader.cc:33
Architecture.
Definition: Arch.h:37
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:94
Store and operate with byte count.
Definition: ByteCount.h:31
A sat capability.
Definition: Capability.h:63
Single entry in a change log.
Definition: Changelog.h:31
Store and operate on date (time_t).
Definition: Date.h:33
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
unsigned epoch_t
Type of an epoch.
Definition: Edition.h:64
Base class for Exception.
Definition: Exception.h:146
Wrapper class for stat/lstat.
Definition: PathInfo.h:221
const std::string & asString() const
Return current Pathname as String.
Definition: PathInfo.h:248
const std::string & asString() const
String representation.
Definition: Pathname.h:91
std::string string_val(tag tag_r) const
Definition: BinHeader.cc:375
unsigned string_list(tag tag_r, stringList &lst_r) const
Definition: BinHeader.cc:279
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Definition: BinHeader.cc:444
std::string format(const char *fmt) const
Definition: BinHeader.cc:398
intrusive_ptr< BinHeader > Ptr
Definition: BinHeader.h:48
int int_val(tag tag_r) const
Definition: BinHeader.cc:310
bool has_tag(tag tag_r) const
Definition: BinHeader.cc:227
unsigned int_list(tag tag_r, intList &lst_r) const
Definition: BinHeader.cc:240
Wrapper class for rpm header struct.
Definition: RpmHeader.h:62
std::string ident() const
N-V-R.A or empty.
Definition: RpmHeader.cc:299
CapabilitySet tag_requires(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:577
std::string tag_vendor() const
Definition: RpmHeader.cc:762
CapabilitySet tag_recommends(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:680
std::string tag_prein() const
Definition: RpmHeader.cc:846
Edition::epoch_t tag_epoch() const
Definition: RpmHeader.cc:329
std::string tag_pretrans() const
Definition: RpmHeader.cc:870
CapabilitySet tag_supplements(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:663
static RpmHeader::constPtr readPackage(const Pathname &path, VERIFICATION verification=VERIFY)
Get an accessible packages data from disk.
Definition: RpmHeader.cc:212
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Definition: RpmHeader.cc:271
ByteCount tag_archivesize() const
Definition: RpmHeader.cc:710
CapabilitySet tag_obsoletes(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:616
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
bool isNosrc() const
Only 'nosrc'.
Definition: RpmHeader.cc:294
std::string tag_summary() const
Definition: RpmHeader.cc:723
std::string tag_preunprog() const
Definition: RpmHeader.cc:861
std::string tag_os() const
Definition: RpmHeader.cc:840
std::string tag_version() const
Definition: RpmHeader.cc:342
std::string tag_postun() const
Definition: RpmHeader.cc:864
CapabilitySet tag_prerequires(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:590
CapabilitySet tag_provides(std::set< std::string > *freq_r=0) const
If freq_r is not NULL, file dependencies found are inserted.
Definition: RpmHeader.cc:564
std::string tag_description() const
Definition: RpmHeader.cc:736
std::string tag_name() const
Definition: RpmHeader.cc:316
std::string tag_pretransprog() const
Definition: RpmHeader.cc:873
std::string tag_buildhost() const
Definition: RpmHeader.cc:801
Edition tag_edition() const
Definition: RpmHeader.cc:368
std::string tag_preinprog() const
Definition: RpmHeader.cc:849
std::string tag_url() const
Definition: RpmHeader.cc:827
Changelog tag_changelog() const
Definition: RpmHeader.cc:1032
std::string tag_posttransprog() const
Definition: RpmHeader.cc:879
CapabilitySet PkgRelList_val(tag tag_r, bool pre, std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:420
std::string signatureKeyID() const
Uses headerFormat to query the signature info from the header.
Definition: RpmHeader.cc:895
std::string tag_postunprog() const
Definition: RpmHeader.cc:867
std::string tag_distribution() const
Definition: RpmHeader.cc:775
std::string tag_postinprog() const
Definition: RpmHeader.cc:855
std::string tag_group() const
Definition: RpmHeader.cc:749
std::string tag_license() const
Definition: RpmHeader.cc:788
std::string tag_sourcerpm() const
Definition: RpmHeader.cc:890
CapabilitySet tag_conflicts(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:603
ByteCount tag_size() const
Definition: RpmHeader.cc:697
std::string tag_packager() const
Definition: RpmHeader.cc:814
std::string tag_release() const
Definition: RpmHeader.cc:355
bool isSrc() const
Either 'src' or 'nosrc'.
Definition: RpmHeader.cc:289
std::string tag_preun() const
Definition: RpmHeader.cc:858
CapabilitySet tag_suggests(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:646
std::string tag_postin() const
Definition: RpmHeader.cc:852
intrusive_ptr< RpmHeader > Ptr
Definition: RpmHeader.h:64
std::list< FileInfo > tag_fileinfos() const
complete information about the files (extended version of tag_filenames())
Definition: RpmHeader.cc:951
std::string tag_posttrans() const
Definition: RpmHeader.cc:876
VERIFICATION
Digest and signature verification flags.
Definition: RpmHeader.h:194
CapabilitySet tag_enhances(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:629
std::list< std::string > tag_filenames() const
just the list of names
Definition: RpmHeader.cc:923
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:111
String related utilities and Regular expression matching.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:1085
std::string toUpper(const std::string &s)
Return uppercase version of s.
Definition: String.cc:200
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
Definition: String.h:531
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:35
std::list< ChangelogEntry > Changelog
List of ChangelogEntry.
Definition: Changelog.h:53
Relational operators.
Definition: Rel.h:44
static const Rel LT
Definition: Rel.h:52
static const Rel GT
Definition: Rel.h:54
static const Rel LE
Definition: Rel.h:53
static const Rel GE
Definition: Rel.h:55
static const Rel ANY
Definition: Rel.h:56
static const Rel EQ
Definition: Rel.h:50
Convenient building of std::string with boost::format.
Definition: String.h:253
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:436
#define MIL
Definition: Logger.h:96
#define ERR
Definition: Logger.h:98
#define WAR
Definition: Logger.h:97
#define INT
Definition: Logger.h:100