libzypp  15.3.0
FileConflicts.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
11 #include <iostream>
12 #include <string>
13 
14 #include "zypp/sat/FileConflicts.h"
15 #include "zypp/base/LogTools.h"
16 #include "zypp/base/Gettext.h"
17 #include "zypp/base/Xml.h"
18 #include "zypp/CheckSum.h"
19 
20 using std::endl;
21 
23 namespace zypp
24 {
26  namespace sat
27  {
29  {
30  if ( lhsFilename() == rhsFilename() )
31  {
32  static const char * text[2][2] = {{ // [lhs][rhs] 0 = installed; 1 = to be installed
33  // TranslatorExplanation %1%(filename) %2%(package1) %3%(package2)
34  N_( "File %1%\n"
35  " from package\n"
36  " %2%\n"
37  " conflicts with file from package\n"
38  " %3%" ),
39  // TranslatorExplanation %1%(filename) %2%(package1) %3%(package2)
40  N_( "File %1%\n"
41  " from package\n"
42  " %2%\n"
43  " conflicts with file from install of\n"
44  " %3%" )
45  },{
46  // TranslatorExplanation %1%(filename) %2%(package1) %3%(package2)
47  N_( "File %1%\n"
48  " from install of\n"
49  " %2%\n"
50  " conflicts with file from package\n"
51  " %3%" ),
52  // TranslatorExplanation %1%(filename) %2%(package1) %3%(package2)
53  N_( "File %1%\n"
54  " from install of\n"
55  " %2%\n"
56  " conflicts with file from install of\n"
57  " %3%" )
58  }};
59  return( boost::formatNAC( text[lhsSolvable().isSystem()?0:1][rhsSolvable().isSystem()?0:1] )
60  % lhsFilename()
63  ).str();
64  }
65  else
66  {
67  static const char * text[2][2] = {{ // [lhs][rhs] 0 = installed; 1 = to be installed
68  // TranslatorExplanation %1%(filename1) %2%(package1) %%3%(filename2) 4%(package2)
69  N_( "File %1%\n"
70  " from package\n"
71  " %2%\n"
72  " conflicts with file\n"
73  " %3%\n"
74  " from package\n"
75  " %4%" ),
76  // TranslatorExplanation %1%(filename1) %2%(package1) %3%(filename2) %4%(package2)
77  N_( "File %1%\n"
78  " from package\n"
79  " %2%\n"
80  " conflicts with file\n"
81  " %3%\n"
82  " from install of\n"
83  " %4%" )
84  },{
85  // TranslatorExplanation %1%(filename1) %2%(package1) %3%(filename2) %4%(package2)
86  N_( "File %1%\n"
87  " from install of\n"
88  " %2%\n"
89  " conflicts with file\n"
90  " %3%\n"
91  " from package\n"
92  " %4%" ),
93  // TranslatorExplanation %1%(filename1) %2%(package1) %3%(filename2) %4%(package2)
94  N_( "File %1%\n"
95  " from install of\n"
96  " %2%\n"
97  " conflicts with file\n"
98  " %3%\n"
99  " from install of\n"
100  " %4%" )
101  }};
102  return( boost::formatNAC( text[lhsSolvable().isSystem()?0:1][rhsSolvable().isSystem()?0:1] )
103  % lhsFilename()
105  % rhsFilename()
107  ).str();
108  }
109  }
110 
111  std::ostream & operator<<( std::ostream & str, const FileConflicts & obj )
112  { return dumpRange( str << "(" << obj.size() << ") ", obj.begin(), obj.end() ); }
113 
114  std::ostream & operator<<( std::ostream & str, const FileConflicts::Conflict & obj )
115  {
116  if ( obj.lhsFilename() == obj.rhsFilename() )
117  return str << boost::format( "%s:\n %s[%s]\n %s[%s]" )
118  % obj.lhsFilename()
119  % obj.lhsSolvable()
120  % obj.lhsFilemd5()
121  % obj.rhsSolvable()
122  % obj.rhsFilemd5();
123 
124  return str << boost::format( "%s - %s:\n %s[%s]\n %s[%s]" )
125  % obj.lhsFilename()
126  % obj.rhsFilename()
127  % obj.lhsSolvable()
128  % obj.lhsFilemd5()
129  % obj.rhsSolvable()
130  % obj.rhsFilemd5();
131  }
132 
133 
134  std::ostream & dumpAsXmlOn( std::ostream & str, const FileConflicts & obj )
135  {
136  xmlout::Node guard( str, "fileconflicts", { "size", obj.size() } );
137  if ( ! obj.empty() )
138  {
139  *guard << "\n";
140  for ( const auto & el : obj )
141  dumpAsXmlOn( *guard, el ) << "\n";
142  }
143  return str;
144  }
145 
146  namespace
147  {
148  std::ostream & dumpAsXmlHelper( std::ostream & str, const std::string & tag_r, IdString filename_r, IdString md5sum_r, Solvable solv_r )
149  {
150  xmlout::Node guard( str, tag_r );
151  *xmlout::Node( *guard, "file" ) << filename_r;
152  dumpAsXmlOn( *guard, CheckSum( md5sum_r.asString() ) );
153  dumpAsXmlOn( *guard, solv_r );
154  return str;
155  }
156  }
157 
158  std::ostream & dumpAsXmlOn( std::ostream & str, const FileConflicts::Conflict & obj )
159  {
160  xmlout::Node guard( str, "fileconflict" );
161  dumpAsXmlHelper( *guard<<"\n", "lhs", obj.lhsFilename(), obj.lhsFilemd5(), obj.lhsSolvable() );
162  dumpAsXmlHelper( *guard<<"\n", "rhs", obj.rhsFilename(), obj.rhsFilemd5(), obj.rhsSolvable() );
163  return str;
164  }
165 
166  } // namespace sat
168 } // namespace zypp
Interface to gettext.
std::string asUserString() const
Ready to use (translated) string describing the Conflict.
RAII writing a nodes start/end tag.
Definition: Xml.h:84
#define N_(MSG)
Just tag text for translation.
Definition: Gettext.h:18
String related utilities and Regular expression matching.
Access to the sat-pools string space.
Definition: IdString.h:39
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
const_iterator begin() const
Definition: FileConflicts.h:64
std::string asString() const
Conversion to std::string
Definition: IdString.h:83
Libsolv queue representing file conflicts.
Definition: FileConflicts.h:30
std::ostream & dumpRange(std::ostream &str, _Iterator begin, _Iterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition: LogTools.h:91
format formatNAC(const std::string &string_r)
A formater with (N)o (A)rgument (C)heck.
Definition: String.h:40
size_type size() const
Definition: FileConflicts.h:63
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
const_iterator end() const
Definition: FileConflicts.h:65
bool empty() const
Definition: Queue.cc:46