{ return true; }
virtual Action problem(
- Resolvable::Ptr resolvable_ptr
+ Resolvable::constPtr resolvable_ptr
, Error error
, std::string description
) { return ABORT; }
};
virtual void start(
- Resolvable::Ptr resolvable
+ Resolvable::constPtr resolvable
) {}
- virtual bool progress(int value, Resolvable::Ptr resolvable)
+ virtual bool progress(int value, Resolvable::constPtr resolvable)
{ return true; }
virtual Action problem(
- Resolvable::Ptr resolvable
+ Resolvable::constPtr resolvable
, Error error
, std::string description
) { return ABORT; }
virtual void finish(
- Resolvable::Ptr resolvable
+ Resolvable::constPtr resolvable
, Error error
, std::string reason
) {}
enum Error {
NO_ERROR,
- NOT_FOUND, // the requested Url was not found
- IO, // IO error
- INVALID // th resolvable is invalid
+ FAILED // failed to rebuild
};
- virtual void start(
- Pathname path
- ) {}
+ virtual void start(Pathname path) {}
virtual bool progress(int value, Pathname path)
{ return true; }
virtual Action problem(
Pathname path
- , Error error
+ , Error error
, std::string description
) { return ABORT; }
enum Error {
NO_ERROR,
- NOT_FOUND, // the requested Url was not found
- IO, // IO error
- INVALID // th resolvable is invalid
+ FAILED // conversion failed
};
virtual void start(
) {}
};
+ // progress for scanning the database
+ struct ScanDBReport : public callback::ReportBase
+ {
+ enum Action {
+ ABORT, // abort and return error
+ RETRY, // retry
+ IGNORE // ignore the failure
+ };
+
+ enum Error {
+ NO_ERROR,
+ FAILED // conversion failed
+ };
+
+ virtual void start(
+ ) {}
+
+ virtual bool progress(int value)
+ { return true; }
+
+ virtual Action problem(
+ Error error
+ , std::string description
+ ) { return ABORT; }
+
+ virtual void finish(
+ Error error
+ , std::string reason
+ ) {}
+ };
+
/////////////////////////////////////////////////////////////////
} // namespace rpm
///////////////////////////////////////////////////////////////////
_level = level_r;
}
+
+ /////////////////////////////////////////////////////////////////
+ /// RpmRemovePackageReceiver
+ /////////////////////////////////////////////////////////////////
+
+ RpmRemovePackageReceiver::RpmRemovePackageReceiver (Resolvable::constPtr res)
+ : callback::ReceiveReport<rpm::RpmRemoveReport> ()
+ , _resolvable (res)
+ {
+ }
+
+ RpmRemovePackageReceiver::~RpmRemovePackageReceiver ()
+ {
+ }
+
+ void RpmRemovePackageReceiver::reportbegin()
+ {
+ }
+
+ void RpmRemovePackageReceiver::reportend()
+ {
+ }
+
+ /** Start the operation */
+ void RpmRemovePackageReceiver::start( const Pathname & name )
+ {
+ _report->start( _resolvable );
+ }
+
+ /**
+ * Inform about progress
+ * Return true on abort
+ */
+ bool RpmRemovePackageReceiver::progress( unsigned percent )
+ {
+ return _report->progress( percent, _resolvable );
+ }
+
+ rpm::RpmRemoveReport::Action
+ RpmRemovePackageReceiver::problem( Exception & excpt_r )
+ {
+ rpm::RemoveResolvableReport::Action user =
+ _report->problem( _resolvable
+ , rpm::RemoveResolvableReport::INVALID
+ , excpt_r.msg()
+ );
+
+ switch (user) {
+ case rpm::RemoveResolvableReport::RETRY:
+ return rpm::RpmRemoveReport::RETRY;
+ case rpm::RemoveResolvableReport::ABORT:
+ return rpm::RpmRemoveReport::ABORT;
+ case rpm::RemoveResolvableReport::IGNORE:
+ return rpm::RpmRemoveReport::IGNORE;
+ }
+
+ return rpm::RpmRemoveReport::problem( excpt_r );
+ }
+
+ /** Finish operation in case of success */
+ void RpmRemovePackageReceiver::finish()
+ {
+ _report->finish( _resolvable, rpm::RemoveResolvableReport::NO_ERROR, std::string() );
+ }
+
+ /** Finish operation in case of success */
+ void RpmRemovePackageReceiver::finish( Exception & excpt_r )
+ {
+ _report->finish( _resolvable, rpm::RemoveResolvableReport::INVALID, std::string() );
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace target
///////////////////////////////////////////////////////////////////
virtual void finish( Exception & excpt_r );
};
+ class RpmRemovePackageReceiver
+ : public callback::ReceiveReport<rpm::RpmRemoveReport>
+ {
+ callback::SendReport <rpm::RemoveResolvableReport> _report;
+ Resolvable::constPtr _resolvable;
+
+ public:
+
+ RpmRemovePackageReceiver (Resolvable::constPtr res);
+ virtual ~RpmRemovePackageReceiver ();
+
+ virtual void reportbegin();
+
+ virtual void reportend();
+
+ /** Start the operation */
+ virtual void start( const Pathname & name );
+
+ /**
+ * Inform about progress
+ * Return true on abort
+ */
+ virtual bool progress( unsigned percent );
+
+ /** inform user about a problem */
+ virtual rpm::RpmRemoveReport::Action problem( Exception & excpt_r );
+
+ /** Finish operation in case of success */
+ virtual void finish();
+
+ /** Finish operatin in case of fail, report fail exception */
+ virtual void finish( Exception & excpt_r );
+ };
+
/////////////////////////////////////////////////////////////////
} // namespace target
///////////////////////////////////////////////////////////////////
}
else
{
+ RpmRemovePackageReceiver progress(it->resolvable());
+
+ progress.connect();
+
try {
rpm().removePackage(p);
}
WAR << "Remove failed, retrying with --nodeps" << endl;
rpm().removePackage(p, rpm::RpmDb::RPMINST_NODEPS);
}
+ progress.disconnect();
}
+
MIL << "Successful, resetting transact for " << *it << endl;
it->status().setNoTransact(ResStatus::USER);
}
///////////////////////////////////////////////////////////////////
// Reporting progress of package removing
///////////////////////////////////////////////////////////////////
- class RpmRemoveReport : public HACK::Callback {
- public:
- virtual ~RpmRemoveReport()
- {}
+ struct RpmRemoveReport : public callback::ReportBase {
+
+ enum Action {
+ ABORT, // abort and return error
+ RETRY, // retry
+ IGNORE // ignore
+ };
+
/** Start the operation */
virtual void start( const std::string & name )
{ }
*/
virtual bool progress( unsigned percent )
{ return false; }
+
+ virtual Action problem( Exception & excpt_r )
+ { return ABORT; }
+
/** Finish operation in case of success */
- virtual void end()
+ virtual void finish()
{ }
- /** Finish operatino in case of fail, report fail exception */
- virtual void end( Exception & excpt_r )
+ /** Finish operation in case of fail, report fail exception */
+ virtual void finish( Exception & excpt_r )
{ }
};
- extern RpmRemoveReport rpmRemoveReport;
-
///////////////////////////////////////////////////////////////////
// Reporting progress of package installation
///////////////////////////////////////////////////////////////////
{ }
};
- ///////////////////////////////////////////////////////////////////
- // Reporting database scanning
- ///////////////////////////////////////////////////////////////////
- class ScanDbReport : public HACK::Callback {
- public:
- virtual ~ScanDbReport()
- {}
- /** Start the operation */
- virtual void start()
- { }
- /**
- * Inform about progress
- * Return true on abort
- */
- virtual bool progress( unsigned percent )
- { return false; }
- /** Finish operation in case of success */
- virtual void end()
- { }
- /** Finish operatino in case of fail, report fail exception */
- virtual void end( Exception & excpt_r )
- { }
- };
-
- extern ScanDbReport scanDbReport;
-
- ///////////////////////////////////////////////////////////////////
- // Reporting progress of database rebuild
- ///////////////////////////////////////////////////////////////////
- class RebuildDbReport : public HACK::Callback {
- public:
- virtual ~RebuildDbReport()
- {}
- /** Start the operation */
- virtual void start()
- { }
- /**
- * Inform about progress
- * Return true on abort
- */
- virtual bool progress( unsigned percent )
- { return false; }
- /** Finish operation in case of success */
- virtual void end()
- { }
- /** Finish operatino in case of fail, report fail exception */
- virtual void end( Exception & excpt_r )
- { }
- };
-
- extern RebuildDbReport rebuildDbReport;
-
- ///////////////////////////////////////////////////////////////////
- // Reporting progress of database rebuild
- ///////////////////////////////////////////////////////////////////
- class ConvertDbReport : public HACK::Callback {
- public:
- virtual ~ConvertDbReport()
- {}
- /** Start the operation */
- virtual void start()
- { }
- /**
- * Inform about progress
- * Return true on abort
- */
- virtual bool progress( unsigned percent )
- { return false; }
- /** Finish operation in case of success */
- virtual void end()
- { }
- /** Finish operatino in case of fail, report fail exception */
- virtual void end( Exception & excpt_r )
- { }
- };
-
- extern ConvertDbReport convertDbReport;
-
} // namespace rpm
} // namespace target
} // namespace zypp
//
void RpmDb::rebuildDatabase()
{
- RebuildDbReport report;
+ callback::SendReport<RebuildDBReport> report;
+
+ report->start( root() + dbPath() );
+
try {
doRebuildDatabase(report);
}
catch (RpmException & excpt_r)
{
- report.end(excpt_r);
+ report->finish(root() + dbPath(), RebuildDBReport::FAILED, excpt_r.msg());
ZYPP_RETHROW(excpt_r);
}
- report.end();
+ report->finish(root() + dbPath(), RebuildDBReport::NO_ERROR, "");
}
-void RpmDb::doRebuildDatabase(RebuildDbReport & report)
+void RpmDb::doRebuildDatabase(callback::SendReport<RebuildDBReport> & report)
{
FAILIFNOTINITIALIZED;
while ( systemReadLine( line ) ) {
if ( newMaster() ) { // file is removed at the end of rebuild.
// current size should be upper limit for new db
- report.progress( (100 * newMaster.size()) / dbMaster.size());
+ report->progress( (100 * newMaster.size()) / dbMaster.size(), root() + dbPath());
}
if ( line.compare( 0, 2, "D:" ) ) {
if ( rpm_status != 0 ) {
ZYPP_THROW(RpmSubprocessException(string("rpm failed with message: ") + errmsg));
} else {
- report.progress( 100 ); // 100%
+ report->progress( 100, root() + dbPath() ); // 100%
}
}
//
const std::list<Package::Ptr> & RpmDb::getPackages()
{
- ScanDbReport report;
+ callback::SendReport<ScanDBReport> report;
+
+ report->start ();
+
try {
const std::list<Package::Ptr> & ret = doGetPackages(report);
- report.end();
+ report->finish(ScanDBReport::NO_ERROR, "");
return ret;
}
catch (RpmException & excpt_r)
{
- report.end(excpt_r);
+ report->finish(ScanDBReport::FAILED, excpt_r.msg ());
ZYPP_RETHROW(excpt_r);
}
#warning fixme
}
-const std::list<Package::Ptr> & RpmDb::doGetPackages(ScanDbReport & report)
+const std::list<Package::Ptr> & RpmDb::doGetPackages(callback::SendReport<ScanDBReport> & report)
{
if ( packagesValid() ) {
return _packages._list;
unsigned current = 0;
CapFactory _f;
- for ( iter.findAll(); *iter; ++iter, ++current, report.progress( (100*current)/expect)) {
+ for ( iter.findAll(); *iter; ++iter, ++current, report->progress( (100*current)/expect)) {
string name = iter->tag_name();
if ( name == string( "gpg-pubkey" ) ) {
//
void RpmDb::removePackage( const string & name_r, unsigned flags )
{
- RpmRemoveReport report;
+ callback::SendReport<RpmRemoveReport> report;
+
+ report->start( name_r );
+
try {
doRemovePackage(name_r, flags, report);
}
catch (RpmException & excpt_r)
{
- report.end(excpt_r);
+ report->finish(excpt_r);
ZYPP_RETHROW(excpt_r);
}
- report.end();
+ report->finish();
}
-void RpmDb::doRemovePackage( const string & name_r, unsigned flags, RpmRemoveReport & report )
+void RpmDb::doRemovePackage( const string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report )
{
FAILIFNOTINITIALIZED;
Logfile progresslog;
if ( ! backupPackage( name_r ) ) {
ERR << "backup of " << name_r << " failed" << endl;
}
- report.progress( 0 );
+ report->progress( 0 );
} else {
- report.progress( 100 );
+ report->progress( 100 );
}
// run rpm
// 5 - command started
// 50 - command completed
// 100 if no error
- report.progress( 5 );
+ report->progress( 5 );
while (systemReadLine(line))
{
rpmmsg += line+'\n';
}
- report.progress( 50 );
+ report->progress( 50 );
int rpm_status = systemStatus();
if ( rpm_status != 0 ) {
#include "zypp/target/rpm/RpmHeader.h"
#include "zypp/target/rpm/RpmCallbacks.h"
+#include "zypp/ZYppCallbacks.h"
namespace zypp {
namespace target {
static bool setInstallationLogfile( const Pathname & filename );
protected:
- void doRemovePackage( const std::string & name_r, unsigned flags, RpmRemoveReport & report );
+ void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
- const std::list<Package::Ptr> & doGetPackages(ScanDbReport & report);
- void doRebuildDatabase(RebuildDbReport & report);
+ const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
+ void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
};
#include "zypp/target/rpm/librpmDb.h"
#include "zypp/target/rpm/RpmCallbacks.h"
+#include "zypp/ZYppCallbacks.h"
extern "C" {
#include <string.h>
** FUNCTION TYPE : int
*/
void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r,
- ConvertDbReport & report )
+ callback::SendReport<ConvertDBReport> & report )
{
// Timecount _t( "convert V3 to V4" );
MIL << "Convert rpm3 database to rpm4" << endl;
unsigned failed = 0;
unsigned ignored = 0;
unsigned alreadyInV4 = 0;
- report.progress( (100 * (failed + ignored + alreadyInV4) / max) );
+ report->progress( (100 * (failed + ignored + alreadyInV4) / max), v3db_r );
if ( !max ) {
Fclose( fd );
bool proceed = true;
for ( int offset = fadFirstOffset(fd); offset && proceed /*!= CBSuggest::CANCEL*/;
offset = fadNextOffset(fd, offset),
- report.progress( (100 * (failed + ignored + alreadyInV4) / max) ) )
+ report->progress( (100 * (failed + ignored + alreadyInV4) / max), v3db_r ) )
{
// have to use lseek instead of Fseek because headerRead
void convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r )
{
// report
- ConvertDbReport report;
- report.start();
+ callback::SendReport<ConvertDBReport> report;
+ report->start(v3db_r);
try {
internal_convertV3toV4( v3db_r, v4db_r, report );
}
catch (RpmException & excpt_r)
{
- report.end(excpt_r);
+ report->finish(v3db_r, ConvertDBReport::FAILED,excpt_r.msg());
ZYPP_RETHROW(excpt_r);
}
- report.end();
+ report->finish(v3db_r, ConvertDBReport::NO_ERROR, "");
}
} // namespace rpm