include_HEADERS = \
librpm.h \
+ RpmException.h \
BinHeader.h \
RpmHeader.h \
librpmDb.h \
## ##################################################
lib@PACKAGE@_target_rpm_la_SOURCES = \
+ RpmException.cc \
BinHeader.cc \
RpmHeader.cc \
librpmDb.cc \
+ librpmDb.cv3.cc \
RpmCallbacks.cc \
RpmPackageImpl.cc \
RpmDb.cc
-lib@PACKAGE@_target_rpm_la_LIBADD =
+lib@PACKAGE@_target_rpm_la_LIBADD = -lrpm
## ##################################################
///////////////////////////////////////////////////////////////////
// Reporting progress of package removing
///////////////////////////////////////////////////////////////////
- class RemovePkgReport : public HACK::Callback {
+ class RpmRemoveReport : public HACK::Callback {
public:
- virtual ~RemovePkgReport()
+ virtual ~RpmRemoveReport()
{}
/** Start the operation */
virtual void start( const std::string & name )
{ }
};
- extern RemovePkgReport removePkgReport;
+ extern RpmRemoveReport rpmRemoveReport;
///////////////////////////////////////////////////////////////////
// Reporting progress of package installation
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
/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
| |
-| __ __ ____ _____ ____ |
-| \ \ / /_ _/ ___|_ _|___ \ |
-| \ V / _` \___ \ | | __) | |
-| | | (_| |___) || | / __/ |
-| |_|\__,_|____/ |_| |_____| |
-| |
-| Package Management |
-| (C) 2002 SuSE AG |
-\----------------------------------------------------------------------/
-
- File: RpmDb.cc
- Purpose: Interface to installed RPM system
- Author: Stefan Schubert <schubi@suse.de>
- Maintainer: Ludwig Nussel <lnussel@suse.de>
-
- Copied and adapted from agent-targetpkg
-
-/-*/
+\---------------------------------------------------------------------*/
+/** \file zypp/target/rpm/RpmDb.h
+ *
+*/
#include "librpm.h"
#include <cstdlib>
#include "zypp/target/rpm/librpmDb.h"
#include "zypp/target/rpm/RpmPackageImpl.h"
+#include "zypp/target/rpm/RpmException.h"
#include "zypp/CapSet.h"
#ifndef _
//
///////////////////////////////////////////////////////////////////
-#define FAILIFNOTINITIALIZED if( ! initialized() ) { ZYPP_THROW(Exception("Error::E_RpmDB_not_open")); }
+#define FAILIFNOTINITIALIZED if( ! initialized() ) { ZYPP_THROW(RpmDbNotOpenException()); }
///////////////////////////////////////////////////////////////////
if ( ! (root_r.absolute() && dbPath_r.absolute()) ) {
ERR << "Illegal root or dbPath: " << stringPath( root_r, dbPath_r ) << endl;
- ZYPP_THROW(Exception("Error::E_invalid_argument"));
+ ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r));
}
MIL << "Calling initDatabase: " << stringPath( root_r, dbPath_r ) << endl;
if ( root_r == _root && dbPath_r == _dbPath ) {
return;
} else {
- ERR << "Can't switch to " << stringPath( root_r, dbPath_r )
- << " while accessing " << stringPath( _root, _dbPath ) << endl;
- ZYPP_THROW(Exception("Error::E_RpmDB_already_open"));
+ ZYPP_THROW(RpmDbAlreadyOpenException(_root, _dbPath, root_r, dbPath_r));
}
}
try {
internal_initDatabase( root_r, dbPath_r, info );
}
- catch (...)
+ catch (const RpmException & excpt_r)
{
+ ZYPP_CAUGHT(excpt_r);
librpmDb::blockAccess();
ERR << "Cleanup on error: state " << info << endl;
// any backup created on conversion.
removeV4( root_r + dbPath_r, dbsi_has( info, DbSI_MADE_V3TOV4 ) );
}
- #warning FIXME rethrow
-
+ ZYPP_RETHROW(excpt_r);
}
- if ( dbsi_has( info, DbSI_HAVE_V3 ) ) {
- if ( root_r == "/" || dbsi_has( info, DbSI_MODIFIED_V4 ) ) {
- // Move obsolete rpm3 database beside.
- MIL << "Cleanup: state " << info << endl;
- removeV3( root_r + dbPath_r, dbsi_has( info, DbSI_MADE_V3TOV4 ) );
- dbsi_clr( info, DbSI_HAVE_V3 );
- } else {
+ if ( dbsi_has( info, DbSI_HAVE_V3 ) ) {
+ if ( root_r == "/" || dbsi_has( info, DbSI_MODIFIED_V4 ) ) {
+ // Move obsolete rpm3 database beside.
+ MIL << "Cleanup: state " << info << endl;
+ removeV3( root_r + dbPath_r, dbsi_has( info, DbSI_MADE_V3TOV4 ) );
+ dbsi_clr( info, DbSI_HAVE_V3 );
+ } else {
// Performing an update: Keep the original rpm3 database
// and wait if the rpm4 database gets modified by installing
// or removing packages. Cleanup in modifyDatabase or closeDatabase.
MIL << "Update mode: Cleanup delayed until closeOldDatabase." << endl;
- }
}
+ }
#warning CHECK: notify root about conversion backup.
- _root = root_r;
- _dbPath = dbPath_r;
- _dbStateInfo = info;
+ _root = root_r;
+ _dbPath = dbPath_r;
+ _dbStateInfo = info;
-#warning FIXME uncomment code below
+#warning Add rebuild database once have the info about context
#if 0
- if ( ! ( err || Y2PM::runningFromSystem() ) ) {
- if ( dbsi_has( info, DbSI_HAVE_V4 )
- && ! dbsi_has( info, DbSI_MADE_V4 ) ) {
- err = rebuildDatabase();
- }
+ if ( ! ( Y2PM::runningFromSystem() ) ) {
+ if ( dbsi_has( info, DbSI_HAVE_V4 )
+ && ! dbsi_has( info, DbSI_MADE_V4 ) ) {
+ err = rebuildDatabase();
}
+ }
#endif
- // Close the database in case any write acces (create/convert)
- // happened during init. This should drop any lock acquired
- // by librpm. On demand it will be reopened readonly and should
- // not hold any lock.
- librpmDb::dbRelease( true );
- MIL << "InitDatabase: " << *this << endl;
+ // Close the database in case any write acces (create/convert)
+ // happened during init. This should drop any lock acquired
+ // by librpm. On demand it will be reopened readonly and should
+ // not hold any lock.
+ librpmDb::dbRelease( true );
+ MIL << "InitDatabase: " << *this << endl;
}
///////////////////////////////////////////////////////////////////
librpmDb::DbDirInfo dbInfo( root_r, dbPath_r );
if ( dbInfo.illegalArgs() ) {
- ZYPP_THROW(Exception("Error::E_invalid_argument")); // should not happen (checked in initDatabase)
+ // should not happen (checked in initDatabase)
+ ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r));
}
if ( ! dbInfo.usableArgs() ) {
ERR << "Bad database directory: " << dbInfo.dbDir() << endl;
- ZYPP_THROW(Exception("Error::E_invalid_argument"));
+ ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r));
}
if ( dbInfo.hasDbV4() ) {
MIL << "Found rpm3 database " << dbInfo.dbV3() << endl;
if ( dbEmpty ) {
- extern void convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r );
-
+ extern void convertV3toV4( const Pathname & v3db_r, const constlibrpmDbPtr & v4db_r );
+#warning FIXME exception handling for following function
convertV3toV4( dbInfo.dbV3().path(), dbptr );
// create a backup copy
//
void RpmDb::rebuildDatabase()
{
+ RebuildDbReport report;
+ try {
+ doRebuildDatabase(report);
+ }
+ catch (RpmException & excpt_r)
+ {
+ report.end(excpt_r);
+ ZYPP_RETHROW(excpt_r);
+ }
+ report.end();
+}
+
+void RpmDb::doRebuildDatabase(RebuildDbReport & report)
+{
FAILIFNOTINITIALIZED;
MIL << "RpmDb::rebuildDatabase" << *this << endl;
PathInfo dbMaster( root() + dbPath() + "Packages" );
PathInfo dbMasterBackup( dbMaster.path().extend( ".y2backup" ) );
- // report
- RebuildDbReport report;
- report.start();
-
// run rpm
RpmArgVec opts;
opts.push_back("--rebuilddb");
int rpm_status = systemStatus();
if ( rpm_status != 0 ) {
- ERR << "rpm failed, message was:" << endl << errmsg; // has trailing NL
-#warning FIXME error report
-// err.setDetails(errmsg);
-// report.end(err);
- ZYPP_THROW(Exception("Error::E_RpmDB_subprocess_failed"));
+ ZYPP_THROW(RpmSubprocessException(string("rpm failed with message: ") + errmsg));
} else {
report.progress( 100 ); // 100%
- report.end();
}
}
int rpm_status = systemStatus();
if ( rpm_status != 0 ) {
- ERR << "Failed to import public key from file " << pubkey_r << ": rpm returned " << rpm_status << endl;
- ZYPP_THROW(Exception("Error::E_RpmDB_subprocess_failed"));
+ ZYPP_THROW(RpmSubprocessException(string("Failed to import public key from file ") + pubkey_r.asString() + string(": rpm returned ") + str::numstring(rpm_status)));
} else {
MIL << "Imported public key from file " << pubkey_r << endl;
}
FAILIFNOTINITIALIZED;
// create tempfile
- char tmpname[] = "/tmp/y2.pubkey.XXXXXX";
+ char tmpname[] = "/tmp/zypp.pubkey.XXXXXX";
int tmpfd = mkstemp( tmpname );
if ( tmpfd == -1 ) {
- ERR << "Unable to create a unique temporary file for pubkey" << endl;
- ZYPP_THROW(Exception("Error::E_RpmDB_subprocess_failed"));
+ ZYPP_THROW(RpmSubprocessException("Unable to create a unique temporary file for pubkey"));
}
// export keyname from keyring
// launch gpg
ExternalProgram prg( argv, ExternalProgram::Discard_Stderr, false, -1, true );
- string err;
int res = 0;
// read key
- for ( string line( prg.receiveLine() ); line.length(); line = prg.receiveLine() ) {
- ssize_t written = write( tmpfd, line.c_str(), line.length() );
- if ( written == -1 || unsigned(written) != line.length() ) {
- ERR << "Error writing pubkey to " << tmpname << endl;
- err = "Error::E_RpmDB_subprocess_failed";
- break;
+
+ try {
+ for ( string line( prg.receiveLine() ); line.length(); line = prg.receiveLine() ) {
+ ssize_t written = write( tmpfd, line.c_str(), line.length() );
+ if ( written == -1 || unsigned(written) != line.length() ) {
+ ZYPP_THROW(RpmSubprocessException(string("Error writing pubkey to ") + tmpname));
+ }
+ res += written; // empty file indicates key not found
}
- res += written; // empty file indicates key not found
+ }
+ catch (RpmException & excpt_r)
+ {
+ close( tmpfd );
+ filesystem::unlink( tmpname );
+ ZYPP_RETHROW(excpt_r);
}
close( tmpfd );
if ( ! res ) {
- WAR << "gpg: no key '" << keyname_r << "' found in '" << keyring_r << "'" << endl;
- err = "Error::E_RpmDB_subprocess_failed";
+ ZYPP_THROW(RpmSubprocessException(string("gpg: no key '") + keyname_r + string("' found in '") + keyring_r.asString() + string("'")));
}
// check gpg returncode
res = prg.close();
if ( res ) {
- ERR << "gpg: export '" << keyname_r << "' from '" << keyring_r << "' returned " << res << endl;
- err = "Error::E_RpmDB_subprocess_failed";
+ // remove tempfile
+ filesystem::unlink( tmpname );
+ ZYPP_THROW(RpmSubprocessException(string("gpg: export '") + keyname_r + string("' from '") + keyring_r.asString() + "' returned " + str::numstring(res)));
}
- if ( err == "" ) {
- MIL << "Exported '" << keyname_r << "' from '" << keyring_r << "' to " << tmpname << endl;
+ MIL << "Exported '" << keyname_r << "' from '" << keyring_r << "' to " << tmpname << endl;
#warning FIXME handle exception from line below
- importPubkey( tmpname );
- }
-
- // remove tempfile
+ importPubkey( tmpname );
filesystem::unlink( tmpname );
-
- ZYPP_THROW(Exception(err));
}
///////////////////////////////////////////////////////////////////
//
const std::list<Package::Ptr> & RpmDb::getPackages()
{
+ ScanDbReport report;
+ try {
+ const std::list<Package::Ptr> & ret = doGetPackages(report);
+ report.end();
+ return ret;
+ }
+ catch (RpmException & excpt_r)
+ {
+ report.end(excpt_r);
+ ZYPP_RETHROW(excpt_r);
+ }
+}
+
+
+const std::list<Package::Ptr> & RpmDb::doGetPackages(ScanDbReport & report)
+{
if ( packagesValid() ) {
return _packages._list;
}
- // report
// FIXME Timecount _t( "RpmDb::getPackages" );
- ScanDbReport report;
- report.start();
#warning how to detect corrupt db while reading.
// multiple entries for the same string. If so we consider the last
// one installed to be the one we're interesed in.
///////////////////////////////////////////////////////////////////
+ unsigned expect = 0;
librpmDb::db_const_iterator iter; // findAll
{
// quick check
- unsigned expect = 0;
for ( ; *iter; ++iter ) {
++expect;
}
-#warning report error
-#if 0
if ( iter.dbError() ) {
ERR << "No database access: " << iter.dbError() << endl;
- report.end( iter.dbError() );
- return _packages._list;
+ ZYPP_THROW(*(iter.dbError()));
}
-#endif
-#warning progress update
-// report->progress( pd.init( expect ) );
}
+ unsigned current = 0;
-#warning progress update
- for ( iter.findAll(); *iter; ++iter/*, report.progress( pd.incr() )*/ ) {
+ for ( iter.findAll(); *iter; ++iter, ++current, report.progress( (100*current)/expect)) {
string name = iter->tag_name();
if ( name == string( "gpg-pubkey" ) ) {
for ( iter.findByFile( *it ); *iter; ++iter ) {
Package::Ptr pptr = _packages.lookup( iter->tag_name() );
if ( !pptr ) {
- WAR << "rpmdb.findByFile returned unpknown package " << *iter << endl;
+ WAR << "rpmdb.findByFile returned unknown package " << *iter << endl;
continue;
}
Dependencies _deps = pptr->deps();
///////////////////////////////////////////////////////////////////
_packages.buildList();
DBG << "Found installed packages: " << _packages._list.size() << endl;
- report.end();
return _packages._list;
}
librpmDb::db_const_iterator it;
it.findPackage( name_r );
result_r = *it;
-#warning FIXME error handling
-// return it.dbError();
+ if (it.dbError())
+ ZYPP_THROW(*(it.dbError()));
}
///////////////////////////////////////////////////////////////////
librpmDb::db_const_iterator it;
it.findPackage( name_r, ed_r );
result_r = *it;
-#warning FIXME error handling
-// return it.dbError();
+ if (it.dbError())
+ ZYPP_THROW(*(it.dbError()));
}
/*--------------------------------------------------------------*/
exit_code = -1;
if ( ! initialized() ) {
- ERR << "Attempt to run rpm: " << "Error::E_RpmDB_not_open" << endl;
- return;
+ ZYPP_THROW(RpmDbNotOpenException());
}
RpmArgVec args;
//
void RpmDb::installPackage( const Pathname & filename, unsigned flags )
{
+ RpmInstallReport report;
+ try {
+ doInstallPackage(filename, flags, report);
+ }
+ catch (RpmException & excpt_r)
+ {
+ report.end(excpt_r);
+ ZYPP_RETHROW(excpt_r);
+ }
+ report.end();
+
+}
+void RpmDb::doInstallPackage( const Pathname & filename, unsigned flags, RpmInstallReport & report )
+{
FAILIFNOTINITIALIZED;
Logfile progresslog;
MIL << "RpmDb::installPackage(" << filename << "," << flags << ")" << endl;
- // report
- RpmInstallReport report;
- report.start( filename );
-
// backup
if ( _packagebackups ) {
// FIXME report->progress( pd.init( -2, 100 ) ); // allow 1% for backup creation.
_("rpm created %s as %s.\nHere are the first 25 lines of difference:\n"));
}
- string err;
-
if ( rpm_status != 0 ) {
// %s = filename of rpm package
progresslog(/*timestamp*/true) << str::form(_("%s install failed"), Pathname::basename(filename).c_str()) << endl;
progresslog() << _("rpm output:") << endl << rpmmsg << endl;
- ERR << "rpm failed, message was: " << rpmmsg << endl;
- err = "Error::E_RpmDB_subprocess_failed";
-// TODO err.setDetails( rpmmsg );
-#warning TODO throw exception
+ ZYPP_THROW(RpmSubprocessException(string("RPM failed: ") + rpmmsg));
} else {
// %s = filename of rpm package
progresslog(/*timestamp*/true) << str::form(_("%s installed ok"), Pathname::basename(filename).c_str()) << endl;
progresslog() << _("Additional rpm output:") << endl << rpmmsg << endl;
}
}
-
- report.end();
}
///////////////////////////////////////////////////////////////////
//
void RpmDb::removePackage( const string & name_r, unsigned flags )
{
+ RpmRemoveReport report;
+ try {
+ doRemovePackage(name_r, flags, report);
+ }
+ catch (RpmException & excpt_r)
+ {
+ report.end(excpt_r);
+ ZYPP_RETHROW(excpt_r);
+ }
+ report.end();
+}
+
+
+void RpmDb::doRemovePackage( const string & name_r, unsigned flags, RpmRemoveReport & report )
+{
FAILIFNOTINITIALIZED;
Logfile progresslog;
MIL << "RpmDb::removePackage(" << name_r << "," << flags << ")" << endl;
- // report
- RemovePkgReport report;
- report.start( name_r );
-
// backup
if ( _packagebackups ) {
// FIXME solve this status report somehow
report.progress( 50 );
int rpm_status = systemStatus();
- string err;
-
if ( rpm_status != 0 ) {
// %s = name of rpm package
progresslog(/*timestamp*/true) << str::form(_("%s remove failed"), name_r.c_str()) << endl;
progresslog() << _("rpm output:") << endl << rpmmsg << endl;
- ERR << "rpm failed, message was: " << rpmmsg << endl;
-// FIXME err = string("Error::E_RpmDB_subprocess_failed") + endl + rpmmsg;
-#warning Add report->stop(Exception) here
+ ZYPP_THROW(RpmSubprocessException(string("RPM failed: ") + rpmmsg));
} else {
progresslog(/*timestamp*/true) << str::form(_("%s remove ok"), name_r.c_str()) << endl;
if( ! rpmmsg.empty() ) {
progresslog() << _("Additional rpm output:") << endl << rpmmsg << endl;
}
}
-
- report.end();
}
string
// -*- C++ -*-
-#ifndef RpmDb_h
-#define RpmDb_h
+#ifndef ZYPP_TARGET_RPM_RPMDB_H
+#define ZYPP_TARGET_RPM_RPMDB_H
#include <iosfwd>
#include <list>
#include "zypp/Package.h"
#include "zypp/target/rpm/RpmHeader.h"
+#include "zypp/target/rpm/RpmCallbacks.h"
namespace zypp {
namespace target {
/**
* Internal helper for @ref initDatabase.
*
- * \throws Exception
+ * \throws RpmException
*
**/
void internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r,
* (no packages were installed or deleted). Otherwise the new database
* is kept, and the old one is removed.
*
- * \throws Exception
+ * \throws RpmException
*
**/
void initDatabase( Pathname root_r = Pathname(),
* state. On update: Decides what to do with any converted database
* (see @ref initDatabase).
*
- * \throws Exception
+ * \throws RpmException
*
**/
void closeDatabase();
/**
* Rebuild the rpm database (rpm --rebuilddb).
*
- * \throws Exception
+ * \throws RpmException
*
**/
void rebuildDatabase();
/**
* Import ascii armored public key in file pubkey_r.
*
- * \throws Exception
+ * \throws RpmException
*
**/
void importPubkey( const Pathname & pubkey_r );
/**
* Import ascii armored public key keyname_r exported by keyring_r.
*
- * \throws Exception
+ * \throws RpmException
*
**/
void importPubkey( const Pathname & keyring_r, const std::string & keyname_r );
* if packge is not installed (PMError is not set), or RPM database
* could not be read (PMError is set).
*
- * \throws Exception
+ * \throws RpmException
*
* FIXME this and following comment
*
* if packge is not installed (PMError is not set), or RPM database
* could not be read (PMError is set).
*
- * \throws Exception
+ * \throws RpmException
*
**/
void getData( const std::string & name_r, const Edition & ed_r,
* @param n_opts The number of arguments
* @param options Array of the arguments, @ref n_opts elements
* @param stderr_disp How to handle stderr, merged with stdout by default
- */
+ *
+ * \throws RpmException
+ *
+ **/
void run_rpm( const RpmArgVec& options,
ExternalProgram::Stderr_Disposition stderr_disp =
ExternalProgram::Stderr_To_Stdout);
*
* @return success
*
- * \throws Exception
+ * \throws RpmException
*
* */
void installPackage (const Pathname& filename, unsigned flags = 0 );
*
* @return success
*
- * \throws Exception
+ * \throws RpmException
*
* */
void removePackage(const std::string & name_r, unsigned flags = 0);
* Set logfile for progress log. Empty filename to disable logging.
**/
static bool setInstallationLogfile( const Pathname & filename );
+
+ protected:
+ void doRemovePackage( const std::string & name_r, unsigned flags, RpmRemoveReport & report );
+ void doInstallPackage( const Pathname & filename, unsigned flags, RpmInstallReport & report );
+ const std::list<Package::Ptr> & doGetPackages(ScanDbReport & report);
+ void doRebuildDatabase(RebuildDbReport & report);
+
};
} // namespace target
} // namespace zypp
-#endif // RpmDb_h
+#endif // ZYPP_TARGET_RPM_RPMDB_H
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/target/rpm/RpmException.cc
+ *
+*/
+
+#include <string>
+#include <iostream>
+
+#include "zypp/target/rpm/RpmException.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ namespace target {
+ /////////////////////////////////////////////////////////////////
+ namespace rpm {
+ /////////////////////////////////////////////////////////////////
+
+ std::ostream & RpmInvalidRootException::dumpOn( std::ostream & str ) const
+ {
+ return str << "Illegal root " << _root
+ << " or dbPath " << _dbpath << endl;
+ }
+
+ std::ostream & RpmAccessBlockedException::dumpOn( std::ostream & str ) const
+ {
+ return str << "Access is blocked: Root: " << _root
+ << " dbPath: " << _dbpath << endl;
+ }
+
+ std::ostream & RpmSubprocessException::dumpOn( std::ostream & str ) const
+ {
+ return str << "Subprocess failed. Error: " << _errmsg << endl;
+ }
+
+ std::ostream & RpmInitException::dumpOn( std::ostream & str) const
+ {
+ return str << "Failed to initialize database: Root: " << _root
+ << " dbPath: " << _dbpath << endl;
+ }
+
+ std::ostream & RpmDbOpenException::dumpOn( std::ostream & str) const
+ {
+ return str << "Failed to open database: Root: " << _root
+ << " dbPath: " << _dbpath << endl;
+ }
+
+ std::ostream & RpmDbAlreadyOpenException::dumpOn( std::ostream & str) const
+ {
+ return str << "Can't switch to " << _new_root << " " << _new_dbpath
+ << " while accessing " << _old_root << " " << _old_dbpath << endl;
+ }
+
+ std::ostream & RpmDbNotOpenException::dumpOn( std::ostream & str) const
+ {
+ return str << "RPM database not open" << endl;
+ }
+
+ std::ostream & MediaCurlInitException::dumpOn( std::ostream & str) const
+ {
+ return str << "Curl init failed for: " << _url << endl;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace rpm
+ } // namespace target
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/target/rpm/RpmException.h
+ *
+*/
+#ifndef ZYPP_TARGET_RPM_RPMEXCEPTION_H
+#define ZYPP_TARGET_RPM_RPMEXCEPTION_H
+
+#include <iosfwd>
+
+#include <string>
+
+#include "zypp/base/Exception.h"
+#include "zypp/Pathname.h"
+#include "zypp/Url.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ namespace target {
+ ///////////////////////////////////////////////////////////////
+ namespace rpm {
+ ///////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : RpmException
+ /** Just inherits Exception to separate media exceptions
+ *
+ **/
+ class RpmException : public Exception
+ {
+ public:
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ RpmException()
+ : Exception( "Rpm Exception" )
+ {}
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ RpmException( const std::string & msg_r )
+ : Exception( msg_r )
+ {}
+ /** Dtor. */
+ virtual ~RpmException() throw() {};
+ };
+
+ class GlobalRpmInitException : public RpmException
+ {
+ public:
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ GlobalRpmInitException()
+ : RpmException("Global RPM initialization failed")
+ {}
+ /** Dtor. */
+ virtual ~GlobalRpmInitException() throw() {};
+ private:
+ };
+
+ class RpmInvalidRootException : public RpmException
+ {
+ public:
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ RpmInvalidRootException( const Pathname & root_r,
+ const Pathname & dbpath_r )
+ : RpmException()
+ , _root(root_r.asString())
+ , _dbpath(dbpath_r.asString())
+ {}
+ /** Dtor. */
+ virtual ~RpmInvalidRootException() throw() {};
+ std::string root() const { return _root; }
+ std::string dbpath() const { return _dbpath; }
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _root;
+ std::string _dbpath;
+ };
+
+ class RpmAccessBlockedException : public RpmException
+ {
+ public:
+ RpmAccessBlockedException( const Pathname & root_r,
+ const Pathname & dbpath_r )
+ : RpmException()
+ , _root(root_r.asString())
+ , _dbpath(dbpath_r.asString())
+ {}
+ virtual ~RpmAccessBlockedException() throw() {};
+ std::string root() const { return _root; }
+ std::string dbpath() const { return _dbpath; }
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _root;
+ std::string _dbpath;
+ };
+
+ class RpmSubprocessException : public RpmException
+ {
+ public:
+ RpmSubprocessException(const std::string & errmsg_r)
+ : RpmException()
+ , _errmsg(errmsg_r)
+ {}
+ virtual ~RpmSubprocessException() throw() {};
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _errmsg;
+ };
+
+ class RpmInitException : public RpmException
+ {
+ public:
+ RpmInitException(const Pathname & root_r,
+ const Pathname & dbpath_r)
+ : RpmException()
+ , _root(root_r.asString())
+ , _dbpath(dbpath_r.asString())
+ {}
+ virtual ~RpmInitException() throw() {};
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _root;
+ std::string _dbpath;
+ };
+
+ class RpmDbOpenException : public RpmException
+ {
+ public:
+ RpmDbOpenException(const Pathname & root_r,
+ const Pathname & dbpath_r)
+ : RpmException()
+ , _root(root_r.asString())
+ , _dbpath(dbpath_r.asString())
+ {}
+ virtual ~RpmDbOpenException() throw() {};
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _root;
+ std::string _dbpath;
+ };
+
+ class RpmDbAlreadyOpenException : public RpmException
+ {
+ public:
+ RpmDbAlreadyOpenException(const Pathname & old_root_r,
+ const Pathname & old_dbpath_r,
+ const Pathname & new_root_r,
+ const Pathname & new_dbpath_r)
+ : RpmException()
+ , _old_root(old_root_r.asString())
+ , _old_dbpath(old_dbpath_r.asString())
+ , _new_root(new_root_r.asString())
+ , _new_dbpath(new_dbpath_r.asString())
+ {}
+ virtual ~RpmDbAlreadyOpenException() throw() {};
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _old_root;
+ std::string _old_dbpath;
+ std::string _new_root;
+ std::string _new_dbpath;
+ };
+
+ class RpmDbNotOpenException : public RpmException
+ {
+ public:
+ RpmDbNotOpenException()
+ : RpmException()
+ {}
+ virtual ~RpmDbNotOpenException() throw() {};
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ };
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace rpm
+ } // namespace target
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_TARGET_RPM_RPMEXCEPTION_H
//
Edition RpmHeader::tag_edition() const
{
- return Edition( string_val ( RPMTAG_EPOCH ),
- string_val( RPMTAG_VERSION ),
- string_val( RPMTAG_RELEASE ) );
+ return Edition( string_val( RPMTAG_VERSION ),
+ string_val( RPMTAG_RELEASE ),
+ string_val ( RPMTAG_EPOCH ));
}
///////////////////////////////////////////////////////////////////
/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
| |
-| __ __ ____ _____ ____ |
-| \ \ / /_ _/ ___|_ _|___ \ |
-| \ V / _` \___ \ | | __) | |
-| | | (_| |___) || | / __/ |
-| |_|\__,_|____/ |_| |_____| |
-| |
-| core system |
-| (C) SuSE GmbH |
-\----------------------------------------------------------------------/
-
- File: librpm.h
-
- Author: Michael Andres <ma@suse.de>
- Maintainer: Michael Andres <ma@suse.de>
-
- Purpose:
-
-/-*/
-#ifndef librpm_h
-#define librpm_h
+\---------------------------------------------------------------------*/
+/** \file zypp/target/rpm/librpm.h
+ *
+*/
+#ifndef ZYPP_TARGET_RPM_LIBRPM_H
+#define ZYPP_TARGET_RPM_LIBRPM_H
extern "C" {
#include <rpm/rpmlib.h>
#include <fcntl.h>
}
-#endif // librpm_h
+#endif // ZYPP_TARGET_RPM_LIBRPM_H
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
-/** \file zypp/target/rpm/BinHeader.h
+/** \file zypp/target/rpm/librpmDb.cc
*
*/
#include "librpm.h"
#include "zypp/base/Logger.h"
#include "zypp/target/rpm/librpmDb.h"
#include "zypp/target/rpm/RpmHeader.h"
-#include "zypp/base/Exception.h"
+#include "zypp/target/rpm/RpmException.h"
using namespace std;
const Pathname _root; // root directory for all operations
const Pathname _dbPath; // directory (below root) that contains the rpmdb
rpmdb _db; // database handle
-#warning fix string representation of the error
- shared_ptr<Exception> _error; // database error
+ shared_ptr<RpmException> _error; // database error
friend ostream & operator<<( ostream & str, const D & obj ) {
str << "{" << obj._error << "(" << obj._root << ")" << obj._dbPath << "}";
// init database
int res = ::rpmdbInit( root, perms );
if ( res ) {
- _error = shared_ptr<Exception>(new Exception("Error::E_RpmDB_init_failed"));
ERR << "rpmdbInit error(" << res << "): " << *this << endl;
- return;
+ _error = shared_ptr<RpmInitException>(new RpmInitException(_root, _dbPath));
+ ZYPP_THROW(*_error);
}
}
// open database
int res = ::rpmdbOpen( root, &_db, (readonly_r ? O_RDONLY : O_RDWR ), perms );
if ( res || !_db ) {
- _error = shared_ptr<Exception>(new Exception("Error::E_RpmDB_open_failed"));
if ( _db ) {
::rpmdbClose( _db );
_db = 0;
}
ERR << "rpmdbOpen error(" << res << "): " << *this << endl;
+ _error = shared_ptr<RpmDbOpenException>(new RpmDbOpenException(_root, _dbPath));
+ ZYPP_THROW(*_error);
return;
}
{
// check arguments
if ( ! (root_r.absolute() && dbPath_r.absolute()) ) {
- ERR << "Illegal root or dbPath: " << stringPath( root_r, dbPath_r ) << endl;
- ZYPP_THROW(Exception("Error::E_invalid_argument"));
+ ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r));
}
// initialize librpm
if ( ! globalInit() ) {
- ZYPP_THROW(Exception("Error::E_RpmDB_global_init_failed"));
+ ZYPP_THROW(GlobalRpmInitException());
}
// open rpmdb
- librpmDb * ret = new librpmDb( root_r, dbPath_r, readonly_r );
- shared_ptr<Exception> err_r = ret->_d._error;
- if ( err_r ) {
+ librpmDb * ret = 0;
+ try {
+ ret = new librpmDb( root_r, dbPath_r, readonly_r );
+ }
+ catch (const RpmException & excpt_r)
+ {
+ ZYPP_CAUGHT(excpt_r);
delete ret;
ret = 0;
-#warning FIXME uncomment
-#if 0
- ZYPP_THROW(ret->_d._error);
-#endif
+ ZYPP_RETHROW(excpt_r);
}
return ret;
}
{
// check arguments
if ( ! (root_r.absolute() && dbPath_r.absolute()) ) {
- ERR << "Illegal root or dbPath: " << stringPath( root_r, dbPath_r ) << endl;
- ZYPP_THROW(Exception("Error::E_invalid_argument"));
+ ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r));
}
if ( _defaultDb ) {
if ( _defaultRoot == root_r && _defaultDbPath == dbPath_r )
return;
else {
- ERR << "Can't switch to " << stringPath( root_r, dbPath_r )
- << " while accessing " << stringPath( _defaultRoot, _defaultDbPath ) << endl;
- ZYPP_THROW(Exception("Error::E_RpmDB_already_open"));
+ ZYPP_THROW(RpmDbAlreadyOpenException(_defaultRoot, _defaultDbPath, root_r, dbPath_r));
}
}
void librpmDb::dbAccess()
{
if ( _dbBlocked ) {
- WAR << "Access is blocked: " << stringPath( _defaultRoot, _defaultDbPath ) << endl;
- ZYPP_THROW(Exception("Error::E_RpmDB_access_blocked"));
+ ZYPP_THROW(RpmAccessBlockedException(_defaultRoot, _defaultDbPath));
}
if ( !_defaultDb ) {
try {
dbAccess();
}
- catch (Exception & excpt_r)
+ catch (const RpmException & excpt_r)
{
+ ZYPP_CAUGHT(excpt_r);
ptr_r = 0;
ZYPP_RETHROW(excpt_r);
}
DBG << "dbRelease: release" << (force_r && outstanding ? "(forced)" : "")
<< ", outstanding " << outstanding << endl;
- _defaultDb->_d._error = shared_ptr<Exception>(new Exception("Error::E_RpmDB_access_blocked")); // tag handle invalid
+ _defaultDb->_d._error = shared_ptr<RpmAccessBlockedException>(new RpmAccessBlockedException(_defaultDb->_d._root, _defaultDb->_d._dbPath));
+ // tag handle invalid
_defaultDb = 0;
break;
}
return _d._dbPath;
}
-#warning uncomment thsi function
-#if 0
///////////////////////////////////////////////////////////////////
//
//
// METHOD NAME : librpmDb::error
// METHOD TYPE : PMError
//
-PMError librpmDb::error() const
+shared_ptr<RpmException> librpmDb::error() const
{
return _d._error;
}
{
return( valid() && ! *db_const_iterator( this ) );
}
-#endif
///////////////////////////////////////////////////////////////////
//
public:
librpmDb::constPtr _dbptr;
-#warning use better type
- string _dberr;
+ shared_ptr<RpmException> _dberr;
RpmHeader::constPtr _hptr;
rpmdbMatchIterator _mi;
, _mi( 0 )
{
if ( !_dbptr ) {
- // try to get librpmDb's default db
-#warning FIXME uncomment
-#if 0
- _dberr = librpmDb::dbAccess( _dbptr );
-#endif
+ try {
+ librpmDb::dbAccess( _dbptr );
+ }
+ catch (const RpmException & excpt_r)
+ {
+ ZYPP_CAUGHT(excpt_r);
+ }
if ( !_dbptr ) {
WAR << "No database access: " << _dberr << endl;
}
_mi = ::rpmdbFreeIterator( _mi );
_hptr = 0;
}
-#warning uncomment
-#if 0
if ( _dbptr && _dbptr->error() ) {
_dberr = _dbptr->error();
WAR << "Lost database access: " << _dberr << endl;
_dbptr = 0;
}
-#endif
return false;
}
return _d._hptr;
}
-#warning FIXME this function
-#if 0
///////////////////////////////////////////////////////////////////
//
//
// METHOD NAME : librpmDb::db_const_iterator::dbError
// METHOD TYPE : PMError
//
-PMError librpmDb::db_const_iterator::dbError() const
+shared_ptr<RpmException> librpmDb::db_const_iterator::dbError() const
{
if ( _d._dbptr )
return _d._dbptr->error();
return _d._dberr;
}
-#endif
/******************************************************************
**
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
-/** \file zypp/target/rpm/
+/** \file zypp/target/rpm/librpmDb.h
*
*/
-/*---------------------------------------------------------------------\
-| |
-| __ __ ____ _____ ____ |
-| \ \ / /_ _/ ___|_ _|___ \ |
-| \ V / _` \___ \ | | __) | |
-| | | (_| |___) || | / __/ |
-| |_|\__,_|____/ |_| |_____| |
-| |
-| core system |
-| (C) SuSE GmbH |
-\----------------------------------------------------------------------/
-
- File: librpmDb.h
-
- Author: Michael Andres <ma@suse.de>
- Maintainer: Michael Andres <ma@suse.de>
-
- Purpose: Manage access to librpm database.
-
-/-*/
#ifndef librpmDb_h
#define librpmDb_h
#include "zypp/PathInfo.h"
#include "zypp/Package.h"
#include "zypp/target/rpm/RpmHeader.h"
+#include "zypp/target/rpm/RpmException.h"
namespace zypp {
namespace target {
* librpmDb::constPtr. Currently we don't want to provide non const
* handles, as the database is opened READONLY.
*
- * \throws Exception
+ * \throws RpmException
*
**/
static void dbAccess( librpmDb::Ptr & ptr_r );
* For internal use. Pointer returned should immediately be
* wrapped into librpmDb::Ptr.
*
- * \throws Exception
+ * \throws RpmException
*
**/
static librpmDb * newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r );
* created, you'll have to explicitly call @ref dbRelease to close the
* database.
*
- * \throws Exception
+ * \throws RpmException
*
**/
static void dbAccess();
* It's not allowed to switch to another location while a database
* is accessed. Use @ref dbRelease to force releasing the database first.
*
- * \throws Exception
+ * \throws RpmException
*
**/
static void dbAccess( const Pathname & root_r, const Pathname & dbPath_r );
* it should not be used longer than necessary. Be prepared that the
* handle might become invalid (see @ref dbRelease) later.
*
- * \throws Exception
+ * \throws RpmException
*
**/
static void dbAccess( librpmDb::constPtr & ptr_r );
* @return This handles directory that contains the rpmdb.
**/
const Pathname & dbPath() const;
-#warning uncomment
-#if 0
/**
* Return any database error. Usg. if the database was
* blocked by calling @ref dbRelease(true) or @ref blockAccess.
**/
- PMError error() const;
+ shared_ptr<RpmException> error() const;
/**
* @return Whether
**/
bool valid() const { return( ! error() ); }
-#endif
/**
* @return True if handle is valid and database is empty.
**/
~db_const_iterator();
-#warning FIXME this function
-#if 0
/**
* Return any database error.
*
* dbError will immediately report this, but an already running
* iteration will proceed to its end. Then the database is dropped.
**/
- PMError dbError() const;
-#endif
+ shared_ptr<RpmException> dbError() const;
/**
* Advance to next RpmHeader::constPtr.
* Commonly used by PMRpmPackageDataProvider.
**/
bool findPackage( const std::string & name_r, const Edition & ed_r );
-#warning define if eneded
-#if 0
- /**
- * Abbr. for <code>findPackage( which_r.name, which_r.edition );</code>
- **/
- bool findPackage( const PkgNameEd & which_r ) {
- return findPackage( which_r.name, which_r.edition );
- }
-#endif
+
/**
* Abbr. for <code>findPackage( which_r->name(), which_r->edition() );</code>
**/