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