libzypp: zypp/sat/FileConflicts.cc Source File

libzypp 17.38.8

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-core/base/LogTools.h>
16#include <zypp-core/base/Gettext.h>
17#include <zypp-core/base/Xml.h>
18#include <zypp/CheckSum.h>
19
20using std::endl;
21
23namespace zypp
24{
26 namespace sat
27 {
28 std::string FileConflicts::Conflict::asUserString() const
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()
61 % lhsSolvable().asUserString()
62 % rhsSolvable().asUserString();
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()
103 % lhsSolvable().asUserString()
104 % rhsFilename()
105 % rhsSolvable().asUserString();
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
FileConflicts.h
Gettext.h
N_
#define N_(MSG)
Definition Gettext.h:36
LogTools.h
Xml.h
zypp::CheckSum
Definition CheckSum.h:34
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::asString
std::string asString() const
Conversion to std::string.
Definition IdString.h:110
zypp::sat::FileConflicts
Libsolv queue representing file conflicts.
Definition FileConflicts.h:31
zypp::sat::FileConflicts::begin
const_iterator begin() const
Definition FileConflicts.h:64
zypp::sat::FileConflicts::end
const_iterator end() const
Definition FileConflicts.h:65
zypp::sat::FileConflicts::empty
bool empty() const
Definition Queue.cc:46
zypp::sat::FileConflicts::size
size_type size() const
Definition FileConflicts.h:63
zypp::sat::Solvable::asUserString
std::string asUserString() const
String representation "ident-edition.arch(repo)" or "noSolvable".
Definition Solvable.cc:461
str
String related utilities and Regular expression matching.
zypp::sat
Libsolv interface
zypp::sat::dumpAsXmlOn
std::ostream & dumpAsXmlOn(std::ostream &str, const FileConflicts &obj)
relates: FileConflicts XML output
Definition FileConflicts.cc:132
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
relates: FileConflicts Stream output
Definition FileConflicts.cc:109
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::dumpRange
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:409
zypp::sat::FileConflicts::Conflict
A file conflict.
Definition FileConflicts.h:41
zypp::sat::FileConflicts::Conflict::lhsFilename
IdString lhsFilename() const
Definition FileConflicts.h:42
zypp::sat::FileConflicts::Conflict::lhsFilemd5
IdString lhsFilemd5() const
Definition FileConflicts.h:44
zypp::sat::FileConflicts::Conflict::rhsFilename
IdString rhsFilename() const
Definition FileConflicts.h:46
zypp::sat::FileConflicts::Conflict::lhsSolvable
Solvable lhsSolvable() const
Definition FileConflicts.h:43
zypp::sat::FileConflicts::Conflict::asUserString
std::string asUserString() const
Ready to use (translated) string describing the Conflict.
Definition FileConflicts.cc:28
zypp::sat::FileConflicts::Conflict::rhsFilemd5
IdString rhsFilemd5() const
Definition FileConflicts.h:48
zypp::sat::FileConflicts::Conflict::rhsSolvable
Solvable rhsSolvable() const
Definition FileConflicts.h:47
zypp::str::Format
Convenient building of std::string with boost::format.
Definition String.h:254
zypp::xmlout::Node
RAII writing a nodes start/end tag.
Definition Xml.h:85
CheckSum.h