libzypp 17.31.7
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
15#include <zypp/base/LogTools.h>
16#include <zypp/base/Gettext.h>
17#include <zypp/base/Xml.h>
18#include <zypp/CheckSum.h>
19
20using std::endl;
21
23namespace 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 str::Format( text[lhsSolvable().isSystem()?0:1][rhsSolvable().isSystem()?0:1] )
60 % lhsFilename()
63 }
64 else
65 {
66 static const char * text[2][2] = {{ // [lhs][rhs] 0 = installed; 1 = to be installed
67 // TranslatorExplanation %1%(filename1) %2%(package1) %%3%(filename2) 4%(package2)
68 N_( "File %1%\n"
69 " from package\n"
70 " %2%\n"
71 " conflicts with file\n"
72 " %3%\n"
73 " from package\n"
74 " %4%" ),
75 // TranslatorExplanation %1%(filename1) %2%(package1) %3%(filename2) %4%(package2)
76 N_( "File %1%\n"
77 " from package\n"
78 " %2%\n"
79 " conflicts with file\n"
80 " %3%\n"
81 " from install of\n"
82 " %4%" )
83 },{
84 // TranslatorExplanation %1%(filename1) %2%(package1) %3%(filename2) %4%(package2)
85 N_( "File %1%\n"
86 " from install of\n"
87 " %2%\n"
88 " conflicts with file\n"
89 " %3%\n"
90 " from package\n"
91 " %4%" ),
92 // TranslatorExplanation %1%(filename1) %2%(package1) %3%(filename2) %4%(package2)
93 N_( "File %1%\n"
94 " from install of\n"
95 " %2%\n"
96 " conflicts with file\n"
97 " %3%\n"
98 " from install of\n"
99 " %4%" )
100 }};
101 return str::Format( text[lhsSolvable().isSystem()?0:1][rhsSolvable().isSystem()?0:1] )
102 % lhsFilename()
104 % rhsFilename()
106 }
107 }
108
109 std::ostream & operator<<( std::ostream & str, const FileConflicts & obj )
110 { return dumpRange( str << "(" << obj.size() << ") ", obj.begin(), obj.end() ); }
111
112 std::ostream & operator<<( std::ostream & str, const FileConflicts::Conflict & obj )
113 {
114 if ( obj.lhsFilename() == obj.rhsFilename() )
115 return str << str::Format( "%s:\n %s[%s]\n %s[%s]" )
116 % obj.lhsFilename()
117 % obj.lhsSolvable()
118 % obj.lhsFilemd5()
119 % obj.rhsSolvable()
120 % obj.rhsFilemd5();
121
122 return str << str::Format( "%s - %s:\n %s[%s]\n %s[%s]" )
123 % obj.lhsFilename()
124 % obj.rhsFilename()
125 % obj.lhsSolvable()
126 % obj.lhsFilemd5()
127 % obj.rhsSolvable()
128 % obj.rhsFilemd5();
129 }
130
131
132 std::ostream & dumpAsXmlOn( std::ostream & str, const FileConflicts & obj )
133 {
134 xmlout::Node guard( str, "fileconflicts", { "size", obj.size() } );
135 if ( ! obj.empty() )
136 {
137 *guard << "\n";
138 for ( const auto & el : obj )
139 dumpAsXmlOn( *guard, el ) << "\n";
140 }
141 return str;
142 }
143
144 namespace
145 {
146 std::ostream & dumpAsXmlHelper( std::ostream & str, const std::string & tag_r, IdString filename_r, IdString md5sum_r, Solvable solv_r )
147 {
148 xmlout::Node guard( str, tag_r );
149 *xmlout::Node( *guard, "file" ) << filename_r;
150 dumpAsXmlOn( *guard, CheckSum( md5sum_r.asString() ) );
151 dumpAsXmlOn( *guard, solv_r );
152 return str;
153 }
154 }
155
156 std::ostream & dumpAsXmlOn( std::ostream & str, const FileConflicts::Conflict & obj )
157 {
158 xmlout::Node guard( str, "fileconflict" );
159 dumpAsXmlHelper( *guard<<"\n", "lhs", obj.lhsFilename(), obj.lhsFilemd5(), obj.lhsSolvable() );
160 dumpAsXmlHelper( *guard<<"\n", "rhs", obj.rhsFilename(), obj.rhsFilemd5(), obj.rhsSolvable() );
161 return str;
162 }
163
164 } // namespace sat
166} // namespace zypp
Access to the sat-pools string space.
Definition: IdString.h:43
std::string asString() const
Conversion to std::string
Definition: IdString.h:98
Libsolv queue representing file conflicts.
Definition: FileConflicts.h:31
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Stream output.
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
XML output.
const_iterator begin() const
Definition: FileConflicts.h:64
const_iterator end() const
Definition: FileConflicts.h:65
bool empty() const
Definition: Queue.cc:46
size_type size() const
Definition: FileConflicts.h:63
A Solvable object within the sat Pool.
Definition: Solvable.h:54
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition: Solvable.cc:457
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator 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
std::string asUserString() const
Ready to use (translated) string describing the Conflict.
Convenient building of std::string with boost::format.
Definition: String.h:253
RAII writing a nodes start/end tag.
Definition: Xml.h:85
#define N_(MSG)