Skip to content

Commit

Permalink
added support for the file conflicts callbacks (bnc#923590)
Browse files Browse the repository at this point in the history
- 3.1.24
  • Loading branch information
lslezak committed Jun 10, 2015
1 parent b78a268 commit 78645e0
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings-devel-doc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-pkg-bindings-devel-doc
Version: 3.1.23
Version: 3.1.24
Release: 0
License: GPL-2.0
Group: Documentation/HTML
Expand Down
6 changes: 6 additions & 0 deletions package/yast2-pkg-bindings.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jun 10 15:09:51 UTC 2015 - lslezak@suse.cz

- added support for the file conflicts callbacks (bnc#923590)
- 3.1.24

-------------------------------------------------------------------
Tue Mar 31 11:39:34 UTC 2015 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-pkg-bindings
Version: 3.1.23
Version: 3.1.24
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
4 changes: 4 additions & 0 deletions src/Callbacks.YCP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
ENUM_OUT( ProcessNextStage );
ENUM_OUT( ProcessProgress );
ENUM_OUT( ProcessFinished );
ENUM_OUT( FileConflictStart );
ENUM_OUT( FileConflictProgress );
ENUM_OUT( FileConflictReport );
ENUM_OUT( FileConflictFinish );
#undef ENUM_OUT
// no default! let compiler warn missing values
}
Expand Down
4 changes: 3 additions & 1 deletion src/Callbacks.YCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class PkgFunctions::CallbackHandler::YCPCallbacks
CB_FinishDeltaDownload, CB_FinishDeltaApply,
CB_StartDownload, CB_ProgressDownload, CB_DoneDownload, CB_InitDownload, CB_DestDownload,

CB_SourceProbeStart, CB_SourceProbeFailed, CB_SourceProbeSucceeded, CB_SourceProbeEnd, CB_SourceProbeProgress, CB_SourceProbeError,
CB_FileConflictStart, CB_FileConflictProgress, CB_FileConflictReport, CB_FileConflictFinish,

CB_SourceProbeStart, CB_SourceProbeFailed, CB_SourceProbeSucceeded, CB_SourceProbeEnd, CB_SourceProbeProgress, CB_SourceProbeError,
CB_SourceReportStart, CB_SourceReportProgress, CB_SourceReportError, CB_SourceReportEnd, CB_SourceReportInit, CB_SourceReportDestroy,

CB_ScriptStart, CB_ScriptProgress, CB_ScriptProblem, CB_ScriptFinish,
Expand Down
86 changes: 86 additions & 0 deletions src/Callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "zypp/PublicKey.h"
#include "zypp/Digest.h"
#include "zypp/base/String.h"
#include "zypp/sat/FileConflicts.h"

#include <ctime>

Expand Down Expand Up @@ -1697,6 +1698,87 @@ namespace ZyppRecipients {
}
};

///////////////////////////////////////////////////////////////////
// File conflict callbacks
///////////////////////////////////////////////////////////////////
struct FileConflictReceive : public Recipient,
public zypp::callback::ReceiveReport<zypp::target::FindFileConflictstReport>
{
FileConflictReceive( RecipientCtl & construct_r ) : Recipient( construct_r ) {}

virtual void reportbegin() {
CB callback( ycpcb( YCPCallbacks::CB_FileConflictStart) );

if (callback._set) {
callback.evaluate();
}
}

virtual bool start( const zypp::ProgressData & progress_r ) {
return report_progress(progress_r);
}

virtual bool progress( const zypp::ProgressData & progress_r,
const zypp::sat::Queue & noFilelist_r ) {
return report_progress(progress_r);
}

virtual bool result( const zypp::ProgressData & progress_r,
const zypp::sat::Queue & noFilelist_r,
const zypp::sat::FileConflicts & conflicts_r ) {
CB callback( ycpcb( YCPCallbacks::CB_FileConflictReport) );

if (callback._set) {

YCPList excluded_packages;
for_(iter, noFilelist_r.begin(), noFilelist_r.end())
{
// convert solvable ID to a Package
zypp::Package::Ptr pkg(zypp::make<zypp::Package>(zypp::sat::Solvable(*iter)));
if (pkg) {
excluded_packages->add(YCPString(pkg->name() + "-" +
pkg->edition().asString() + "-" + pkg->arch().asString()));
}
}

YCPList conflicts;
for_(iter, conflicts_r.begin(), conflicts_r.end())
{
conflicts->add(YCPString(iter->asUserString()));
}

callback.addList(excluded_packages);
callback.addList(conflicts);

return callback.evaluateBool();
}

// continue
return true;
}

virtual void reportend() {
CB callback( ycpcb( YCPCallbacks::CB_FileConflictFinish) );

if (callback._set) {
callback.evaluate();
}
}

private:

bool report_progress(const zypp::ProgressData & progress_r) {
CB callback( ycpcb( YCPCallbacks::CB_FileConflictProgress) );

if (callback._set) {
callback.addInt(progress_r.reportValue());
return callback.evaluateBool();
}

// continue
return true;
}
};

///////////////////////////////////////////////////////////////////
}; // namespace ZyppRecipients
Expand All @@ -1721,6 +1803,7 @@ class PkgFunctions::CallbackHandler::ZyppReceive : public ZyppRecipients::Recipi
ZyppRecipients::InstallPkgReceive _installPkgReceive;
ZyppRecipients::RemovePkgReceive _removePkgReceive;
ZyppRecipients::DownloadResolvableReceive _providePkgReceive;
ZyppRecipients::FileConflictReceive _fileConflictReceive;

// media callback
ZyppRecipients::MediaChangeReceive _mediaChangeReceive;
Expand Down Expand Up @@ -1758,6 +1841,7 @@ class PkgFunctions::CallbackHandler::ZyppReceive : public ZyppRecipients::Recipi
, _installPkgReceive( *this, pkg )
, _removePkgReceive( *this )
, _providePkgReceive( *this, pkg )
, _fileConflictReceive( *this )
, _mediaChangeReceive( *this )
, _downloadProgressReceive( *this )
, _scriptExecReceive( *this )
Expand All @@ -1777,6 +1861,7 @@ class PkgFunctions::CallbackHandler::ZyppReceive : public ZyppRecipients::Recipi
_installPkgReceive.connect();
_removePkgReceive.connect();
_providePkgReceive.connect();
_fileConflictReceive.connect();
_mediaChangeReceive.connect();
_downloadProgressReceive.connect();
_scriptExecReceive.connect();
Expand All @@ -1799,6 +1884,7 @@ class PkgFunctions::CallbackHandler::ZyppReceive : public ZyppRecipients::Recipi
_installPkgReceive.disconnect();
_removePkgReceive.disconnect();
_providePkgReceive.disconnect();
_fileConflictReceive.disconnect();
_mediaChangeReceive.disconnect();
_downloadProgressReceive.disconnect();
_scriptExecReceive.disconnect();
Expand Down
52 changes: 52 additions & 0 deletions src/Callbacks_Register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,56 @@ YCPValue PkgFunctions::CallbackDoneRefresh( const YCPValue& args )
return SET_YCP_CB( CB_DoneSourceRefresh, args);
}

/**
* @builtin CallbackFileConflictStart
* @short Register a callback function
* @param string args Name of the callback handler function. Required callback prototype is <code>void()</code>.
* The callback function is evaluated when file conflict solving is started.
* @return void
*/
YCPValue PkgFunctions::CallbackFileConflictStart( const YCPValue& args )
{
return SET_YCP_CB( CB_FileConflictStart, args);
}

/**
* @builtin CallbackFileConflictProgress
* @short Register a callback function
* @param string args Name of the callback handler function. Required callback prototype is <code>bool(integer percent)</code>.
* The returned boolean indicates whether to continue (true) or abort (false).
* The callback function is evaluated when file conflict solving is in progress.
* @return void
*/
YCPValue PkgFunctions::CallbackFileConflictProgress( const YCPValue& args )
{
return SET_YCP_CB( CB_FileConflictProgress, args);
}

/**
* @builtin CallbackFileConflictProgress
* @short Register a callback function
* @param string args Name of the callback handler function. Required callback
* prototype is <code>bool(list&lt;string&gt; excluded_packages, list&lt;string&gt; conflicts)</code>.
* The returned boolean indicates whether to continue (true) or abort (false).
* The callback function is evaluated when file conflict solving result is available.
* @return void
*/
YCPValue PkgFunctions::CallbackFileConflictReport( const YCPValue& args )
{
return SET_YCP_CB( CB_FileConflictReport, args);
}

/**
* @builtin CallbackFileConflictFinish
* @short Register a callback function
* @param string args Name of the callback handler function. Required callback prototype is <code>void()</code>.
* The callback function is evaluated when file conflict solving is finished.
* @return void
*/
YCPValue PkgFunctions::CallbackFileConflictFinish( const YCPValue& args )
{
return SET_YCP_CB( CB_FileConflictFinish, args);
}


#undef SET_YCP_CB
9 changes: 9 additions & 0 deletions src/PkgFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ class PkgFunctions
/* TYPEINFO: void(void()) */
YCPValue CallbackDoneRefresh( const YCPValue& /*nil*/ args );

/* TYPEINFO: void(void()) */
YCPValue CallbackFileConflictStart( const YCPValue& args );
/* TYPEINFO: void(boolean(integer)) */
YCPValue CallbackFileConflictProgress( const YCPValue& args );
/* TYPEINFO: void(boolean(list<string>,list<string>)) */
YCPValue CallbackFileConflictReport( const YCPValue& args );
/* TYPEINFO: void(void()) */
YCPValue CallbackFileConflictFinish( const YCPValue& args );

// Script (patch installation) callbacks
/* TYPEINFO: void(void(string,string,string,string)) */
YCPValue CallbackScriptStart( const YCPValue& /*nil*/ args );
Expand Down

0 comments on commit 78645e0

Please sign in to comment.