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