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