1
/*---------------------------------------------------------------------\
3
| |__ / \ / / . \ . \ |
8
\---------------------------------------------------------------------*/
9
/** \file zypp/source/Applydeltarpm.cc
14
#include "zypp/base/Logger.h"
15
#include "zypp/base/String.h"
16
#include "zypp/base/Regex.h"
17
#include "zypp/repo/Applydeltarpm.h"
18
#include "zypp/ExternalProgram.h"
19
#include "zypp/AutoDispose.h"
20
#include "zypp/PathInfo.h"
21
#include "zypp/TriBool.h"
25
///////////////////////////////////////////////////////////////////
27
{ /////////////////////////////////////////////////////////////////
28
///////////////////////////////////////////////////////////////////
29
namespace applydeltarpm
30
{ /////////////////////////////////////////////////////////////////
31
///////////////////////////////////////////////////////////////////
33
{ /////////////////////////////////////////////////////////////////
35
const Pathname applydeltarpm_prog( "/usr/bin/applydeltarpm" );
36
const str::regex applydeltarpm_tick ( "([0-9]+) percent finished" );
38
/******************************************************************
40
** FUNCTION NAME : applydeltarpm
41
** FUNCTION TYPE : bool
43
bool applydeltarpm( const char *const argv_r[],
44
const Progress & report_r = Progress() )
46
ExternalProgram prog( argv_r, ExternalProgram::Stderr_To_Stdout );
48
for ( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
50
if ( report_r && str::regex_match( line, what, applydeltarpm_tick ) )
52
report_r( str::strtonum<unsigned>( what[1] ) );
55
DBG << "Applydeltarpm : " << line;
57
return( prog.close() == 0 );
60
/////////////////////////////////////////////////////////////////
62
///////////////////////////////////////////////////////////////////
64
/******************************************************************
66
** FUNCTION NAME : haveApplydeltarpm
67
** FUNCTION TYPE : bool
69
bool haveApplydeltarpm()
71
// To track changes in availability of applydeltarpm.
72
static TriBool _last = indeterminate;
73
PathInfo prog( applydeltarpm_prog );
74
bool have = prog.isX();
76
; // TriBool! 'else' is not '_last != have'
79
// _last is 'indeterminate' or '!have'
81
MIL << "Found executable " << prog << endl;
83
WAR << "No executable " << prog << endl;
88
/******************************************************************
90
** FUNCTION NAME : check
91
** FUNCTION TYPE : bool
93
bool check( const std::string & sequenceinfo_r, bool quick_r )
95
if ( ! haveApplydeltarpm() )
98
const char *const argv[] = {
99
"/usr/bin/applydeltarpm",
100
( quick_r ? "-C" : "-c" ),
101
"-s", sequenceinfo_r.c_str(),
105
return( applydeltarpm( argv ) );
108
/******************************************************************
110
** FUNCTION NAME : check
111
** FUNCTION TYPE : bool
113
bool check( const Pathname & delta_r, bool quick_r )
115
if ( ! haveApplydeltarpm() )
118
const char *const argv[] = {
119
"/usr/bin/applydeltarpm",
120
( quick_r ? "-C" : "-c" ),
121
delta_r.asString().c_str(),
125
return( applydeltarpm( argv ) );
128
/******************************************************************
130
** FUNCTION NAME : provide
131
** FUNCTION TYPE : bool
133
bool provide( const Pathname & delta_r, const Pathname & new_r,
134
const Progress & report_r )
137
AutoDispose<const Pathname> guard( new_r, filesystem::unlink );
139
if ( ! haveApplydeltarpm() )
142
const char *const argv[] = {
143
"/usr/bin/applydeltarpm",
144
"-p", "-p", // twice to get percent output one per line
145
delta_r.asString().c_str(),
146
new_r.asString().c_str(),
150
if ( ! applydeltarpm( argv, report_r ) )
153
guard.resetDispose(); // no cleanup on success
157
/******************************************************************
159
** FUNCTION NAME : provide
160
** FUNCTION TYPE : bool
162
bool provide( const Pathname & old_r, const Pathname & delta_r,
163
const Pathname & new_r,
164
const Progress & report_r )
167
AutoDispose<const Pathname> guard( new_r, filesystem::unlink );
169
if ( ! haveApplydeltarpm() )
172
const char *const argv[] = {
173
"/usr/bin/applydeltarpm",
174
"-p", "-p", // twice to get percent output one per line
175
"-r", old_r.asString().c_str(),
176
delta_r.asString().c_str(),
177
new_r.asString().c_str(),
181
if ( ! applydeltarpm( argv, report_r ) )
184
guard.resetDispose(); // no cleanup on success
188
/////////////////////////////////////////////////////////////////
189
} // namespace applydeltarpm
190
///////////////////////////////////////////////////////////////////
191
/////////////////////////////////////////////////////////////////
193
///////////////////////////////////////////////////////////////////