Skip to content

Commit

Permalink
Let Zypper::instance return a reference rather than a smart_ptr.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandres committed Sep 5, 2017
1 parent d022eab commit 0698b50
Show file tree
Hide file tree
Showing 29 changed files with 153 additions and 160 deletions.
4 changes: 2 additions & 2 deletions src/PackageArgs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#include "repos.h"

PackageArgs::PackageArgs( const ResKind & kind, const Options & opts )
: zypper( *Zypper::instance() )
: zypper( Zypper::instance() )
, _opts( opts )
{
preprocess( zypper.arguments() );
argsToCaps( kind );
}

PackageArgs::PackageArgs( const std::vector<std::string> & args, const ResKind & kind, const Options & opts )
: zypper( *Zypper::instance() )
: zypper( Zypper::instance() )
, _opts( opts )
{
preprocess( args );
Expand Down
12 changes: 6 additions & 6 deletions src/SolverRequester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -471,19 +471,19 @@ void SolverRequester::updatePatches()
MIL << "got some pkgmgmt patches, will install these first" << endl;

// When (auto)restricting patch to the updatestack only, drop "--with-update"
if ( Zypper::instance()->runtimeData().solve_with_update )
if ( Zypper::instance().runtimeData().solve_with_update )
{
WAR << "Drop --with-update while patching the update stack" << endl;
Zypper::instance()->out().info(
Zypper::instance().out().info(
ColorString( ColorContext::MSG_WARNING,
str::Format(_("Ignoring option %s when updating the update stack first.")) % "--with-update"
).str()
);
Zypper::instance()->runtimeData().solve_with_update = false;
Zypper::instance().runtimeData().solve_with_update = false;
}
}

if ( Zypper::instance()->cOpts().count("updatestack-only") )
if ( Zypper::instance().cOpts().count("updatestack-only") )
{
MIL << "updatestack-only: will stop here!" << endl;
break;
Expand Down Expand Up @@ -518,9 +518,9 @@ bool SolverRequester::installPatch( const PackageSpec & patchspec, const PoolIte
if ( ignore_pkgmgmt || patch->restartSuggested() )
{
Patch::InteractiveFlags ignoreFlags = Patch::NoFlags;
if ( Zypper::instance()->globalOpts().reboot_req_non_interactive )
if ( Zypper::instance().globalOpts().reboot_req_non_interactive )
ignoreFlags |= Patch::Reboot;
if ( Zypper::instance()->cOpts().count("auto-agree-with-licenses") )
if ( Zypper::instance().cOpts().count("auto-agree-with-licenses") )
ignoreFlags |= Patch::License;

if ( selected.isUnwanted() )
Expand Down
14 changes: 7 additions & 7 deletions src/Summary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void Summary::readPool( const ResPool & pool )
}
}

for ( const auto & spkg : Zypper::instance()->runtimeData().srcpkgs_to_install )
for ( const auto & spkg : Zypper::instance().runtimeData().srcpkgs_to_install )
{ to_be_installed[ResKind::srcpackage].insert(spkg); }

// total packages to download & install
Expand Down Expand Up @@ -359,8 +359,8 @@ bool Summary::writeResolvableList( std::ostream & out,
{
static const ColorString quoteCh( "\"", ColorContext::HIGHLIGHT );

TriBool pkglistHighlight = Zypper::instance()->config().color_pkglistHighlight;
ansi::Color pkglistHighlightAttribute = Zypper::instance()->config().color_pkglistHighlightAttribute;
TriBool pkglistHighlight = Zypper::instance().config().color_pkglistHighlight;
ansi::Color pkglistHighlightAttribute = Zypper::instance().config().color_pkglistHighlightAttribute;
char firstCh = 0;

std::ostringstream s;
Expand Down Expand Up @@ -1377,16 +1377,16 @@ void Summary::writePackageCounts( std::ostream & out )

void Summary::dumpTo( std::ostream & out )
{
Zypper & zypper( *Zypper::instance() );
Zypper & zypper( Zypper::instance() );

struct SetColor
{
SetColor( bool force )
: docolors( Zypper::instance()->config().do_colors )
{ if (force) Zypper::instance()->config().do_colors = false; }
: docolors( Zypper::instance().config().do_colors )
{ if (force) Zypper::instance().config().do_colors = false; }

~SetColor()
{ Zypper::instance()->config().do_colors = docolors; }
{ Zypper::instance().config().do_colors = docolors; }

bool docolors;
};
Expand Down
2 changes: 1 addition & 1 deletion src/Table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ std::ostream & TableRow::dumpTo( std::ostream & stream, const Table & parent ) c
}
else
{
if ( !parent._inHeader && parent.editionStyle( c ) && Zypper::instance()->config().do_colors )
if ( !parent._inHeader && parent.editionStyle( c ) && Zypper::instance().config().do_colors )
{
// Edition column
if ( parent._editionStyle.size() == 2 )
Expand Down
18 changes: 6 additions & 12 deletions src/Zypper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ namespace {
{
if ( copts_r.count( old_r ) )
{
Zypper::instance()->out().warning( legacyCLIStr( old_r, new_r ), verbosity_r );
Zypper::instance().out().warning( legacyCLIStr( old_r, new_r ), verbosity_r );
if ( ! copts_r.count( new_r ) )
copts_r[new_r];
copts_r.erase( old_r );
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace
struct CommandHelpFormater
{
CommandHelpFormater()
: _mww( _str, Zypper::instance()->out().defaultFormatWidth( 150 ) )
: _mww( _str, Zypper::instance().out().defaultFormatWidth( 150 ) )
{}

/** Allow using the underlying steam directly. */
Expand Down Expand Up @@ -453,17 +453,11 @@ Zypper::~Zypper()
}


Zypper::Ptr & Zypper::instance()
Zypper & Zypper::instance()
{
static Zypper::Ptr _instance;

if ( !_instance )
_instance.reset( new Zypper() );
else
{
// PENDING SigINT? Some frequently called place to avoid exiting from within the signal handler?
_instance->immediateExitCheck();
}
static Zypper _instance;
// PENDING SigINT? Some frequently called place to avoid exiting from within the signal handler?
_instance.immediateExitCheck();
return _instance;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Zypper.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ typedef shared_ptr<RepoManager> RepoManager_Ptr;
class Zypper : private base::NonCopyable
{
public:
typedef RW_pointer<Zypper,rw_pointer::Scoped<Zypper> > Ptr;
typedef std::vector<std::string> ArgList;

static Ptr & instance();
static Zypper & instance();

int main( int argc, char ** argv );

Expand Down
2 changes: 1 addition & 1 deletion src/callbacks/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ZmartRecipients
{
virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
{
Out & out( Zypper::instance()->out() );
Out & out( Zypper::instance().out() );
switch ( type_r.asEnum() )
{
case MsgType::debug:
Expand Down
46 changes: 23 additions & 23 deletions src/callbacks/keyring.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ namespace zypp
{
inline void hintUnsignedData()
{
Zypper::instance()->out().notePar( 4, _("Signing data enables the recipient to verify that no modifications occurred after the data were signed. Accepting data with no, wrong or unknown signature can lead to a corrupted system and in extreme cases even to a system compromise.") );
Zypper::instance().out().notePar( 4, _("Signing data enables the recipient to verify that no modifications occurred after the data were signed. Accepting data with no, wrong or unknown signature can lead to a corrupted system and in extreme cases even to a system compromise.") );
}

inline void hintIfMasterIndex( const std::string & file_r )
{
if ( file_r == "repomd.xml" || file_r == "content" )
{
// translator: %1% is a file name
Zypper::instance()->out().notePar( 4, str::Format(_("File '%1%' is the repositories master index file. It ensures the integrity of the whole repo.") ) % file_r );
Zypper::instance().out().notePar( 4, str::Format(_("File '%1%' is the repositories master index file. It ensures the integrity of the whole repo.") ) % file_r );
}
}

inline void warnCanNotVerifyFile()
{
Zypper::instance()->out().warningPar( 4, str::Format(_("We can't verify that no one meddled with this file, so it might not be trustworthy anymore! You should not continue unless you know it's safe.") ) );
Zypper::instance().out().warningPar( 4, str::Format(_("We can't verify that no one meddled with this file, so it might not be trustworthy anymore! You should not continue unless you know it's safe.") ) );
}

inline void warnFileModifiedAfterSigning()
{
Zypper::instance()->out().warningPar( 4, str::Format(_("This file was modified after it has been signed. This may have been a malicious change, so it might not be trustworthy anymore! You should not continue unless you know it's safe.") ) );
Zypper::instance().out().warningPar( 4, str::Format(_("This file was modified after it has been signed. This may have been a malicious change, so it might not be trustworthy anymore! You should not continue unless you know it's safe.") ) );
}

std::ostream & dumpKeyInfo( std::ostream & str, const PublicKeyData & key, const KeyContext & context = KeyContext() )
{
Zypper & zypper = *Zypper::instance();
Zypper & zypper = Zypper::instance();
if ( zypper.out().type() == Out::TYPE_XML )
{
{
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace zypp
struct KeyRingReceive : public callback::ReceiveReport<KeyRingReport>
{
KeyRingReceive()
: _gopts(Zypper::instance()->globalOpts())
: _gopts(Zypper::instance().globalOpts())
{}

////////////////////////////////////////////////////////////////////
Expand All @@ -110,18 +110,18 @@ namespace zypp
{
if ( keyData_r.expired() )
{
Zypper::instance()->out().warning( str::Format(_("The gpg key signing file '%1%' has expired.")) % file_r );
Zypper::instance().out().warning( str::Format(_("The gpg key signing file '%1%' has expired.")) % file_r );
dumpKeyInfo( (std::ostream&)ColorStream(std::cout,ColorContext::MSG_WARNING), keyData_r, context );
}
else if ( keyData_r.daysToLive() < 15 )
{
Zypper::instance()->out().info( str::Format(
Zypper::instance().out().info( str::Format(
PL_( "The gpg key signing file '%1%' will expire in %2% day.",
"The gpg key signing file '%1%' will expire in %2% days.",
keyData_r.daysToLive() )) % file_r % keyData_r.daysToLive() );
dumpKeyInfo( std::cout, keyData_r, context );
}
else if ( Zypper::instance()->out().verbosity() > Out::NORMAL )
else if ( Zypper::instance().out().verbosity() > Out::NORMAL )
{
dumpKeyInfo( std::cout, keyData_r, context );
}
Expand All @@ -138,11 +138,11 @@ namespace zypp
<< ")" << std::endl;

if (context.empty())
Zypper::instance()->out().warning(
Zypper::instance().out().warning(
str::Format(_("Accepting an unsigned file '%s'.")) % file,
Out::HIGH);
else
Zypper::instance()->out().warning(
Zypper::instance().out().warning(
str::Format(_("Accepting an unsigned file '%s' from repository '%s'."))
% file % context.repoInfo().asUserString(),
Out::HIGH);
Expand All @@ -157,7 +157,7 @@ namespace zypp
else
// translator: %1% is a file name, %2% a repositories name
msg = str::Format(_("File '%1%' from repository '%2%' is unsigned.") ) % file % context.repoInfo().asUserString();
Zypper::instance()->out().warning( msg );
Zypper::instance().out().warning( msg );

hintUnsignedData();

Expand All @@ -166,7 +166,7 @@ namespace zypp

warnCanNotVerifyFile();

Zypper::instance()->out().gap();
Zypper::instance().out().gap();
// TODO: use text::join( msg, text::qContinue() )
// once the above texts for mgs are translated
std::string question;
Expand Down Expand Up @@ -199,11 +199,11 @@ namespace zypp
<< ")" << std::endl;

if (context.empty())
Zypper::instance()->out().warning(str::Format(
Zypper::instance().out().warning(str::Format(
_("Accepting file '%s' signed with an unknown key '%s'."))
% file % id);
else
Zypper::instance()->out().warning(str::Format(
Zypper::instance().out().warning(str::Format(
_("Accepting file '%s' from repository '%s' signed with an unknown key '%s'."))
% file % context.repoInfo().asUserString() % id);

Expand All @@ -217,7 +217,7 @@ namespace zypp
else
// translator: %1% is a file name, %2% is a gpg key ID, %3% a repositories name
msg = str::Format(_("File '%1%' from repository '%3%' is signed with an unknown key '%2%'.") ) % file % id % context.repoInfo().asUserString();
Zypper::instance()->out().warning( msg );
Zypper::instance().out().warning( msg );

hintUnsignedData();

Expand All @@ -226,7 +226,7 @@ namespace zypp

warnCanNotVerifyFile();

Zypper::instance()->out().gap();
Zypper::instance().out().gap();
std::string question;
// TODO: use text::join( msg, text::qContinue() )
// once the above texts for mgs are translated
Expand All @@ -248,7 +248,7 @@ namespace zypp
virtual KeyRingReport::KeyTrust askUserToAcceptKey(
const PublicKey &key, const KeyContext & context)
{
Zypper & zypper = *Zypper::instance();
Zypper & zypper = Zypper::instance();
std::ostringstream s;

s << std::endl;
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace zypp
<< _("Double-check this is not caused by some malicious"
" changes in the file!");

Zypper::instance()->out().warning(msg.str(), Out::QUIET);
Zypper::instance().out().warning(msg.str(), Out::QUIET);
return true;
}

Expand All @@ -360,7 +360,7 @@ namespace zypp
else
// translator: %1% is a file name, %2% a repositories name
msg = str::Format(_("Signature verification failed for file '%1%' from repository '%2%'.") ) % file % context.repoInfo().asUserString();
Zypper::instance()->out().error( msg );
Zypper::instance().out().error( msg );

hintUnsignedData();

Expand All @@ -369,7 +369,7 @@ namespace zypp

warnFileModifiedAfterSigning();

Zypper::instance()->out().gap();
Zypper::instance().out().gap();
return read_bool_answer( PROMPT_YN_GPG_CHECK_FAILED_IGNORE, text::join( msg, text::qContinue() ), false);
}

Expand All @@ -383,7 +383,7 @@ namespace zypp

struct DigestReceive : public callback::ReceiveReport<DigestReport>
{
DigestReceive() : _gopts(Zypper::instance()->globalOpts()) {}
DigestReceive() : _gopts(Zypper::instance().globalOpts()) {}

////////////////////////////////////////////////////////////////////

Expand All @@ -405,7 +405,7 @@ namespace zypp

virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
{
Zypper & zypper = *Zypper::instance();
Zypper & zypper = Zypper::instance();
std::string unblock( found.substr( 0, 4 ) );

zypper.out().gap();
Expand Down
6 changes: 3 additions & 3 deletions src/callbacks/locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace zypp {
virtual Action conflict( const PoolQuery& query, ConflictState state )
{
if (state == SAME_RESULTS)
Zypper::instance()->out().error(
Zypper::instance().out().error(
_("The following query locks the same objects as the one you want to remove:"));
else
Zypper::instance()->out().error(
Zypper::instance().out().error(
_("The following query locks some of the objects you want to unlock:"));

query.serialize(std::cout);
Expand All @@ -41,7 +41,7 @@ namespace zypp {
{
virtual Action execute( const PoolQuery& query )
{
Zypper::instance()->out().error(
Zypper::instance().out().error(
_("The following query does not lock anything:"));

query.serialize(std::cout);
Expand Down
6 changes: 3 additions & 3 deletions src/callbacks/media.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace ZmartRecipients
const std::vector<std::string> & devices,
unsigned & index)
{
Zypper & zypper = *Zypper::instance();
Zypper & zypper = Zypper::instance();

DBG << "medium problem, url: " << url.asString()
<< ", error " << error
Expand Down Expand Up @@ -271,7 +271,7 @@ namespace ZmartRecipients
if ( zypper.runtimeData().action_rpm_download
&& !zypper.runtimeData().seen_verify_hint )
{
print_verify_hint( Zypper::instance()->out() );
print_verify_hint( Zypper::instance().out() );
}
zypper.requestExit( false );
}
Expand All @@ -291,7 +291,7 @@ namespace ZmartRecipients
const std::string & description,
media::AuthData & auth_data )
{
Zypper & zypper = *Zypper::instance();
Zypper & zypper = Zypper::instance();

if ( geteuid() != 0 && url.getQueryString().find("credentials=") != std::string::npos )
{
Expand Down
Loading

0 comments on commit 0698b50

Please sign in to comment.