libzypp 17.31.20
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 <zypp/AutoDispose.h>
15
16#include <cstring>
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
300//
301//
302// METHOD NAME : RpmHeader::tag_name
303// METHOD TYPE : std::string
304//
305// DESCRIPTION :
306//
307std::string RpmHeader::tag_name() const
308{
309 return string_val( RPMTAG_NAME );
310}
311
313//
314//
315// METHOD NAME : RpmHeader::tag_epoch
316// METHOD TYPE : Edition::epoch_t
317//
318// DESCRIPTION :
319//
321{
322 return int_val ( RPMTAG_EPOCH );
323}
324
326//
327//
328// METHOD NAME : RpmHeader::tag_version
329// METHOD TYPE : std::string
330//
331// DESCRIPTION :
332//
333std::string RpmHeader::tag_version() const
334{
335 return string_val ( RPMTAG_VERSION );
336}
337
339//
340//
341// METHOD NAME : RpmHeader::tag_release
342// METHOD TYPE : std::string
343//
344// DESCRIPTION :
345//
346std::string RpmHeader::tag_release() const
347{
348 return string_val( RPMTAG_RELEASE );
349}
350
352//
353//
354// METHOD NAME : RpmHeader::tag_edition
355// METHOD TYPE : Edition
356//
357// DESCRIPTION :
358//
360{
361 return Edition( tag_version(), tag_release(), tag_epoch() );
362}
363
365//
366//
367// METHOD NAME : RpmHeader::tag_arch
368// METHOD TYPE : Arch
369//
370// DESCRIPTION :
371//
373{
374 return Arch( string_val( RPMTAG_ARCH ) );
375}
376
378//
379//
380// METHOD NAME : RpmHeader::tag_installtime
381// METHOD TYPE : Date
382//
383// DESCRIPTION :
384//
386{
387 return int_val( RPMTAG_INSTALLTIME );
388}
389
391//
392//
393// METHOD NAME : RpmHeader::tag_buildtime
394// METHOD TYPE : Date
395//
396// DESCRIPTION :
397//
399{
400 return int_val( RPMTAG_BUILDTIME );
401}
402
404//
405//
406// METHOD NAME : RpmHeader::PkgRelList_val
407// METHOD TYPE : CapabilitySet
408//
409// DESCRIPTION :
410//
411CapabilitySet RpmHeader::PkgRelList_val( tag tag_r, bool pre, std::set<std::string> * freq_r ) const
412 {
413 CapabilitySet ret;
414
415 rpmTag kindFlags = rpmTag(0);
416 rpmTag kindVersion = rpmTag(0);
417
418 switch ( tag_r )
419 {
420 case RPMTAG_REQUIRENAME:
421 kindFlags = RPMTAG_REQUIREFLAGS;
422 kindVersion = RPMTAG_REQUIREVERSION;
423 break;
424 case RPMTAG_PROVIDENAME:
425 kindFlags = RPMTAG_PROVIDEFLAGS;
426 kindVersion = RPMTAG_PROVIDEVERSION;
427 break;
428 case RPMTAG_OBSOLETENAME:
429 kindFlags = RPMTAG_OBSOLETEFLAGS;
430 kindVersion = RPMTAG_OBSOLETEVERSION;
431 break;
432 case RPMTAG_CONFLICTNAME:
433 kindFlags = RPMTAG_CONFLICTFLAGS;
434 kindVersion = RPMTAG_CONFLICTVERSION;
435 break;
436#ifdef RPMTAG_OLDSUGGESTS
437 case RPMTAG_OLDENHANCESNAME:
438 kindFlags = RPMTAG_OLDENHANCESFLAGS;
439 kindVersion = RPMTAG_OLDENHANCESVERSION;
440 break;
441 case RPMTAG_OLDSUGGESTSNAME:
442 kindFlags = RPMTAG_OLDSUGGESTSFLAGS;
443 kindVersion = RPMTAG_OLDSUGGESTSVERSION;
444 break;
445 case RPMTAG_RECOMMENDNAME:
446 kindFlags = RPMTAG_RECOMMENDFLAGS;
447 kindVersion = RPMTAG_RECOMMENDVERSION;
448 break;
449 case RPMTAG_SUPPLEMENTNAME:
450 kindFlags = RPMTAG_SUPPLEMENTFLAGS;
451 kindVersion = RPMTAG_SUPPLEMENTVERSION;
452 break;
453 case RPMTAG_SUGGESTNAME:
454 kindFlags = RPMTAG_SUGGESTFLAGS;
455 kindVersion = RPMTAG_SUGGESTVERSION;
456 break;
457 case RPMTAG_ENHANCENAME:
458 kindFlags = RPMTAG_ENHANCEFLAGS;
459 kindVersion = RPMTAG_ENHANCEVERSION;
460 break;
461#else
462 case RPMTAG_ENHANCESNAME:
463 kindFlags = RPMTAG_ENHANCESFLAGS;
464 kindVersion = RPMTAG_ENHANCESVERSION;
465 break;
466 case RPMTAG_SUGGESTSNAME:
467 kindFlags = RPMTAG_SUGGESTSFLAGS;
468 kindVersion = RPMTAG_SUGGESTSVERSION;
469 break;
470#endif
471 default:
472 INT << "Illegal RPMTAG_dependencyNAME " << tag_r << endl;
473 return ret;
474 break;
475 }
476
477 stringList names;
478 unsigned count = string_list( tag_r, names );
479 if ( !count )
480 return ret;
481
482 intList flags;
483 int_list( kindFlags, flags );
484
485 stringList versions;
486 string_list( kindVersion, versions );
487
488 for ( unsigned i = 0; i < count; ++i )
489 {
490
491 std::string n( names[i] );
492
493 Rel op = Rel::ANY;
494 int32_t f = flags[i];
495 std::string v = versions[i];
496
497 if ( n[0] == '/' )
498 {
499 if ( freq_r )
500 {
501 freq_r->insert( n );
502 }
503 }
504 else
505 {
506 if ( v.size() )
507 {
508 switch ( f & RPMSENSE_SENSEMASK )
509 {
510 case RPMSENSE_LESS:
511 op = Rel::LT;
512 break;
513 case RPMSENSE_LESS|RPMSENSE_EQUAL:
514 op = Rel::LE;
515 break;
516 case RPMSENSE_GREATER:
517 op = Rel::GT;
518 break;
519 case RPMSENSE_GREATER|RPMSENSE_EQUAL:
520 op = Rel::GE;
521 break;
522 case RPMSENSE_EQUAL:
523 op = Rel::EQ;
524 break;
525 }
526 }
527 }
528 if ((pre && (f & RPMSENSE_PREREQ))
529 || ((! pre) && !(f & RPMSENSE_PREREQ)))
530 {
531 try
532 {
533 ret.insert( Capability( n, op, Edition(v) ) );
534 }
535 catch (Exception & excpt_r)
536 {
537 ZYPP_CAUGHT(excpt_r);
538 WAR << "Invalid capability: " << n << " " << op << " "
539 << v << endl;
540 }
541 }
542 }
543
544 return ret;
545 }
546
548//
549//
550// METHOD NAME : RpmHeader::tag_provides
551// METHOD TYPE : CapabilitySet
552//
553// DESCRIPTION :
554//
555CapabilitySet RpmHeader::tag_provides( std::set<std::string> * freq_r ) const
556 {
557 return PkgRelList_val( RPMTAG_PROVIDENAME, false, freq_r );
558 }
559
561//
562//
563// METHOD NAME : RpmHeader::tag_requires
564// METHOD TYPE : CapabilitySet
565//
566// DESCRIPTION :
567//
568CapabilitySet RpmHeader::tag_requires( std::set<std::string> * freq_r ) const
569 {
570 return PkgRelList_val( RPMTAG_REQUIRENAME, false, freq_r );
571 }
572
574//
575//
576// METHOD NAME : RpmHeader::tag_requires
577// METHOD TYPE : CapabilitySet
578//
579// DESCRIPTION :
580//
581CapabilitySet RpmHeader::tag_prerequires( std::set<std::string> * freq_r ) const
582 {
583 return PkgRelList_val( RPMTAG_REQUIRENAME, true, freq_r );
584 }
585
587//
588//
589// METHOD NAME : RpmHeader::tag_conflicts
590// METHOD TYPE : CapabilitySet
591//
592// DESCRIPTION :
593//
594CapabilitySet RpmHeader::tag_conflicts( std::set<std::string> * freq_r ) const
595 {
596 return PkgRelList_val( RPMTAG_CONFLICTNAME, false, freq_r );
597 }
598
600//
601//
602// METHOD NAME : RpmHeader::tag_obsoletes
603// METHOD TYPE : CapabilitySet
604//
605// DESCRIPTION :
606//
607CapabilitySet RpmHeader::tag_obsoletes( std::set<std::string> * freq_r ) const
608 {
609 return PkgRelList_val( RPMTAG_OBSOLETENAME, false, freq_r );
610 }
611
613//
614//
615// METHOD NAME : RpmHeader::tag_enhances
616// METHOD TYPE : CapabilitySet
617//
618// DESCRIPTION :
619//
620CapabilitySet RpmHeader::tag_enhances( std::set<std::string> * freq_r ) const
621 {
622#ifdef RPMTAG_OLDSUGGESTS
623 return PkgRelList_val( RPMTAG_ENHANCENAME, false, freq_r );
624#else
625 return PkgRelList_val( RPMTAG_ENHANCESNAME, false, freq_r );
626#endif
627 }
628
630//
631//
632// METHOD NAME : RpmHeader::tag_suggests
633// METHOD TYPE : CapabilitySet
634//
635// DESCRIPTION :
636//
637CapabilitySet RpmHeader::tag_suggests( std::set<std::string> * freq_r ) const
638 {
639#ifdef RPMTAG_OLDSUGGESTS
640 return PkgRelList_val( RPMTAG_SUGGESTNAME, false, freq_r );
641#else
642 return PkgRelList_val( RPMTAG_SUGGESTSNAME, false, freq_r );
643#endif
644 }
645
647//
648//
649// METHOD NAME : RpmHeader::tag_supplements
650// METHOD TYPE : CapabilitySet
651//
652// DESCRIPTION :
653//
654CapabilitySet RpmHeader::tag_supplements( std::set<std::string> * freq_r ) const
655 {
656#ifdef RPMTAG_OLDSUGGESTS
657 return PkgRelList_val( RPMTAG_SUPPLEMENTNAME, false, freq_r );
658#else
659 return CapabilitySet();
660#endif
661 }
662
664//
665//
666// METHOD NAME : RpmHeader::tag_recommends
667// METHOD TYPE : CapabilitySet
668//
669// DESCRIPTION :
670//
671CapabilitySet RpmHeader::tag_recommends( std::set<std::string> * freq_r ) const
672 {
673#ifdef RPMTAG_OLDSUGGESTS
674 return PkgRelList_val( RPMTAG_RECOMMENDNAME, false, freq_r );
675#else
676 return CapabilitySet();
677#endif
678 }
679
681//
682//
683// METHOD NAME : RpmHeader::tag_size
684// METHOD TYPE : ByteCount
685//
686// DESCRIPTION :
687//
689{
690 return int_val( RPMTAG_SIZE );
691}
692
694//
695//
696// METHOD NAME : RpmHeader::tag_archivesize
697// METHOD TYPE : ByteCount
698//
699// DESCRIPTION :
700//
702{
703 return int_val( RPMTAG_ARCHIVESIZE );
704}
705
707//
708//
709// METHOD NAME : RpmHeader::tag_summary
710// METHOD TYPE : std::string
711//
712// DESCRIPTION :
713//
714std::string RpmHeader::tag_summary() const
715{
716 return string_val( RPMTAG_SUMMARY );
717}
718
720//
721//
722// METHOD NAME : RpmHeader::tag_description
723// METHOD TYPE : std::string
724//
725// DESCRIPTION :
726//
727std::string RpmHeader::tag_description() const
728{
729 return string_val( RPMTAG_DESCRIPTION );
730}
731
733//
734//
735// METHOD NAME : RpmHeader::tag_group
736// METHOD TYPE : std::string
737//
738// DESCRIPTION :
739//
740std::string RpmHeader::tag_group() const
741{
742 return string_val( RPMTAG_GROUP );
743}
744
746//
747//
748// METHOD NAME : RpmHeader::tag_vendor
749// METHOD TYPE : std::string
750//
751// DESCRIPTION :
752//
753std::string RpmHeader::tag_vendor() const
754{
755 return string_val( RPMTAG_VENDOR );
756}
757
759//
760//
761// METHOD NAME : RpmHeader::tag_distribution
762// METHOD TYPE : std::string
763//
764// DESCRIPTION :
765//
767{
768 return string_val( RPMTAG_DISTRIBUTION );
769}
770
772//
773//
774// METHOD NAME : RpmHeader::tag_license
775// METHOD TYPE : std::string
776//
777// DESCRIPTION :
778//
779std::string RpmHeader::tag_license() const
780{
781 return string_val( RPMTAG_LICENSE );
782}
783
785//
786//
787// METHOD NAME : RpmHeader::tag_buildhost
788// METHOD TYPE : std::string
789//
790// DESCRIPTION :
791//
792std::string RpmHeader::tag_buildhost() const
793{
794 return string_val( RPMTAG_BUILDHOST );
795}
796
798//
799//
800// METHOD NAME : RpmHeader::tag_packager
801// METHOD TYPE : std::string
802//
803// DESCRIPTION :
804//
805std::string RpmHeader::tag_packager() const
806{
807 return string_val( RPMTAG_PACKAGER );
808}
809
811//
812//
813// METHOD NAME : RpmHeader::tag_url
814// METHOD TYPE : std::string
815//
816// DESCRIPTION :
817//
818std::string RpmHeader::tag_url() const
819{
820 return string_val( RPMTAG_URL );
821}
822
824//
825//
826// METHOD NAME : RpmHeader::tag_os
827// METHOD TYPE : std::string
828//
829// DESCRIPTION :
830//
831std::string RpmHeader::tag_os() const
832{
833 return string_val( RPMTAG_OS );
834
835}
836
837std::string RpmHeader::tag_prein() const
838{ return string_val( RPMTAG_PREIN ); }
839
840std::string RpmHeader::tag_preinprog() const
841{ return string_val( RPMTAG_PREINPROG ); }
842
843std::string RpmHeader::tag_postin() const
844{ return string_val( RPMTAG_POSTIN ); }
845
846std::string RpmHeader::tag_postinprog() const
847{ return string_val( RPMTAG_POSTINPROG ); }
848
849std::string RpmHeader::tag_preun() const
850{ return string_val( RPMTAG_PREUN ); }
851
852std::string RpmHeader::tag_preunprog() const
853{ return string_val( RPMTAG_PREUNPROG ); }
854
855std::string RpmHeader::tag_postun() const
856{ return string_val( RPMTAG_POSTUN ); }
857
858std::string RpmHeader::tag_postunprog() const
859{ return string_val( RPMTAG_POSTUNPROG ); }
860
861std::string RpmHeader::tag_pretrans() const
862{ return string_val( RPMTAG_PRETRANS ); }
863
865{ return string_val( RPMTAG_PRETRANSPROG ); }
866
867std::string RpmHeader::tag_posttrans() const
868{ return string_val( RPMTAG_POSTTRANS ); }
869
871{ return string_val( RPMTAG_POSTTRANSPROG ); }
872
874//
875//
876// METHOD NAME : RpmHeader::tag_sourcerpm
877// METHOD TYPE : std::string
878//
879// DESCRIPTION :
880//
881std::string RpmHeader::tag_sourcerpm() const
882{
883 return string_val( RPMTAG_SOURCERPM );
884}
885
886std::string RpmHeader::signatureKeyID() const
887{
888 std::string sigInfo = format("%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|");
889
890 //no signature, return empty string
891 if ( sigInfo == "(none)" )
892 return std::string();
893
894 std::vector<std::string> words;
895 str::split( sigInfo, std::back_inserter(words), ",");
896 if ( words.size() < 3)
897 return std::string();
898
899 const std::string &keyId = words[2];
900 if ( !str::startsWith(keyId, " Key ID "))
901 return std::string();
902
903 return str::toUpper( words[2].substr(8) );
904}
905
907//
908//
909// METHOD NAME : RpmHeader::tag_filenames
910// METHOD TYPE : std::list<std::string>
911//
912// DESCRIPTION :
913//
914std::list<std::string> RpmHeader::tag_filenames() const
915{
916 std::list<std::string> ret;
917
918 stringList basenames;
919 if ( string_list( RPMTAG_BASENAMES, basenames ) )
920 {
921 stringList dirnames;
922 string_list( RPMTAG_DIRNAMES, dirnames );
923 intList dirindexes;
924 int_list( RPMTAG_DIRINDEXES, dirindexes );
925 for ( unsigned i = 0; i < basenames.size(); ++ i )
926 {
927 ret.push_back( dirnames[dirindexes[i]] + basenames[i] );
928 }
929 }
930
931 return ret;
932}
933
935//
936//
937// METHOD NAME : RpmHeader::tag_fileinfos
938// METHOD TYPE : std::list<FileInfo>
939//
940// DESCRIPTION :
941//
942std::list<FileInfo> RpmHeader::tag_fileinfos() const
943{
944 std::list<FileInfo> ret;
945
946 stringList basenames;
947 if ( string_list( RPMTAG_BASENAMES, basenames ) )
948 {
949 stringList dirnames;
950 string_list( RPMTAG_DIRNAMES, dirnames );
951 intList dirindexes;
952 int_list( RPMTAG_DIRINDEXES, dirindexes );
953 intList filesizes;
954 int_list( RPMTAG_FILESIZES, filesizes );
955 stringList md5sums;
956 string_list( RPMTAG_FILEMD5S, md5sums );
957 stringList usernames;
958 string_list( RPMTAG_FILEUSERNAME, usernames );
959 stringList groupnames;
960 string_list( RPMTAG_FILEGROUPNAME, groupnames );
961 intList uids;
962 int_list( RPMTAG_FILEUIDS, uids );
963 intList gids;
964 int_list( RPMTAG_FILEGIDS, gids );
965 intList filemodes;
966 int_list( RPMTAG_FILEMODES, filemodes );
967 intList filemtimes;
968 int_list( RPMTAG_FILEMTIMES, filemtimes );
969 intList fileflags;
970 int_list( RPMTAG_FILEFLAGS, fileflags );
971 stringList filelinks;
972 string_list( RPMTAG_FILELINKTOS, filelinks );
973
974 for ( unsigned i = 0; i < basenames.size(); ++ i )
975 {
976 uid_t uid;
977 if (uids.empty())
978 {
979 uid = unameToUid( usernames[i].c_str(), &uid );
980 }
981 else
982 {
983 uid =uids[i];
984 }
985
986 gid_t gid;
987 if (gids.empty())
988 {
989 gid = gnameToGid( groupnames[i].c_str(), &gid );
990 }
991 else
992 {
993 gid = gids[i];
994 }
995
996 FileInfo info = {
997 dirnames[dirindexes[i]] + basenames[i],
998 filesizes[i],
999 md5sums[i],
1000 uid,
1001 gid,
1002 mode_t(filemodes[i]),
1003 filemtimes[i],
1004 bool(fileflags[i] & RPMFILE_GHOST),
1005 filelinks[i]
1006 };
1007
1008 ret.push_back( info );
1009 }
1010 }
1011
1012 return ret;
1013}
1014
1016//
1017//
1018// METHOD NAME : RpmHeader::tag_changelog
1019// METHOD TYPE : Changelog
1020//
1021// DESCRIPTION :
1022//
1024{
1025 Changelog ret;
1026
1027 intList times;
1028 if ( int_list( RPMTAG_CHANGELOGTIME, times ) )
1029 {
1030 stringList names;
1031 string_list( RPMTAG_CHANGELOGNAME, names );
1032 stringList texts;
1033 string_list( RPMTAG_CHANGELOGTEXT, texts );
1034 for ( unsigned i = 0; i < times.size(); ++ i )
1035 {
1036 ret.push_back( ChangelogEntry( times[i], names[i], texts[i] ) );
1037 }
1038 }
1039
1040 return ret;
1041}
1042
1043} // namespace rpm
1044} // namespace target
1045} // 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
CapabilitySet tag_requires(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:568
std::string tag_vendor() const
Definition: RpmHeader.cc:753
CapabilitySet tag_recommends(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:671
std::string tag_prein() const
Definition: RpmHeader.cc:837
Edition::epoch_t tag_epoch() const
Definition: RpmHeader.cc:320
std::string tag_pretrans() const
Definition: RpmHeader.cc:861
CapabilitySet tag_supplements(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:654
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:701
CapabilitySet tag_obsoletes(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:607
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
std::string tag_summary() const
Definition: RpmHeader.cc:714
std::string tag_preunprog() const
Definition: RpmHeader.cc:852
std::string tag_os() const
Definition: RpmHeader.cc:831
std::string tag_version() const
Definition: RpmHeader.cc:333
std::string tag_postun() const
Definition: RpmHeader.cc:855
CapabilitySet tag_prerequires(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:581
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:555
std::string tag_description() const
Definition: RpmHeader.cc:727
std::string tag_name() const
Definition: RpmHeader.cc:307
std::string tag_pretransprog() const
Definition: RpmHeader.cc:864
std::string tag_buildhost() const
Definition: RpmHeader.cc:792
Edition tag_edition() const
Definition: RpmHeader.cc:359
std::string tag_preinprog() const
Definition: RpmHeader.cc:840
std::string tag_url() const
Definition: RpmHeader.cc:818
Changelog tag_changelog() const
Definition: RpmHeader.cc:1023
std::string tag_posttransprog() const
Definition: RpmHeader.cc:870
CapabilitySet PkgRelList_val(tag tag_r, bool pre, std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:411
std::string signatureKeyID() const
Uses headerFormat to query the signature info from the header.
Definition: RpmHeader.cc:886
std::string tag_postunprog() const
Definition: RpmHeader.cc:858
std::string tag_distribution() const
Definition: RpmHeader.cc:766
std::string tag_postinprog() const
Definition: RpmHeader.cc:846
std::string tag_group() const
Definition: RpmHeader.cc:740
std::string tag_license() const
Definition: RpmHeader.cc:779
std::string tag_sourcerpm() const
Definition: RpmHeader.cc:881
CapabilitySet tag_conflicts(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:594
ByteCount tag_size() const
Definition: RpmHeader.cc:688
std::string tag_packager() const
Definition: RpmHeader.cc:805
std::string tag_release() const
Definition: RpmHeader.cc:346
std::string tag_preun() const
Definition: RpmHeader.cc:849
CapabilitySet tag_suggests(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:637
std::string tag_postin() const
Definition: RpmHeader.cc:843
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:942
std::string tag_posttrans() const
Definition: RpmHeader.cc:867
VERIFICATION
Digest and signature verification flags.
Definition: RpmHeader.h:192
CapabilitySet tag_enhances(std::set< std::string > *freq_r=0) const
Definition: RpmHeader.cc:620
std::list< std::string > tag_filenames() const
just the list of names
Definition: RpmHeader.cc:914
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
#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