ACC SHELL
/**
* File: modules/PackageLock.ycp
* Package: yast2
* Summary: Packages manipulation (system)
* Authors: Martin Vidner <mvidner@suse.cz>
*
* $Id: PackageLock.ycp 61908 2010-04-29 10:16:18Z jsrain $
*
* This should be used everywhere before Pkg is first used. #160319
*/
{
module "PackageLock";
textdomain "base";
import "Popup";
import "Label";
boolean have_lock = nil;
boolean aborted = false;
/**
* Tries to acquire the packager (zypp) lock.
* Reports an error if another process has the lock already.
* Will only report once even if called multiple times.
* @return true if we can continue
*/
global boolean Check () {
// we already have a lock
if (have_lock != nil) return have_lock;
// just to allow 'Retry', see more in bug #280383
boolean try_again = true;
// while not having a lock and user wants to try again
while (try_again) {
// Invoke a cheap call that accesses the zypp lock
have_lock = Pkg::Connect () == true; // nil guard
if (have_lock == true) break;
if (have_lock != true) {
try_again = (Popup::AnyQuestion (
// TRANSLATORS: a popup headline
_("Accessing the Software Management Failed"),
Pkg::LastError() + "\n\n" +
// TRANSLATORS: an error message with question
_("Would you like to continue without having access
to the software management or retry to access it?
"),
Label::ContinueButton(),
Label::RetryButton(),
// 'Continue' instead of 'Retry'
`focus_yes
) == false);
}
if (try_again) y2milestone ("User decided to retry...");
}
y2milestone ("PackageLock::Check result: %1", have_lock);
return have_lock;
}
/**
* Tries to acquire the packager (zypp) lock.
* Reports an error if another process has the lock already.
* Will only report once even if called multiple times.
* @param show_continue_button show option to continue without access
* @return map with lock status and user reaction
*/
global map<string,any> Connect(boolean show_continue_button)
{
// we already have a lock
if (have_lock != nil) return $[ "connected" : have_lock, "aborted" : aborted ];
boolean try_again = true;
// while not having a lock and user wants to try again
while (try_again) {
// Invoke a cheap call that accesses the zypp lock
have_lock = Pkg::Connect () == true; // nil guard
if (have_lock == true) break;
if (have_lock != true) {
if (show_continue_button)
{
symbol ret = Popup::AnyQuestion3(
// TRANSLATORS: a popup headline
_("Accessing the Software Management Failed"),
Pkg::LastError() + "\n\n" +
// TRANSLATORS: an error message with question
_("Would you like to retry accessing the software manager,
continue without having access to the software management,
or abort?
"),
Label::RetryButton(),
Label::ContinueButton(),
Label::AbortButton(),
// default is 'Retry'
`focus_yes
);
try_again = (ret == `yes);
// NOTE: due to the changed labels this actually means that [Abort] was pressed!!
if (ret == `retry)
{
aborted = true;
}
}
else
{
boolean ret = Popup::AnyQuestion(
// TRANSLATORS: a popup headline
_("Accessing the Software Management Failed"),
Pkg::LastError() + "\n\n" +
// TRANSLATORS: an error message with question
_("Would you like to abort or try again?\n"),
Label::RetryButton(),
Label::AbortButton(),
// default is 'Retry'
`focus_yes
);
try_again = ret;
aborted = !ret;
}
y2milestone("try_again: %1, aborted: %2", try_again, aborted);
}
if (try_again) y2milestone ("User decided to retry...");
}
map<string,any> ret = $[ "connected" : have_lock, "aborted" : aborted ];
y2milestone ("PackageLock::Connect result: %1", ret);
return ret;
}
}
ACC SHELL 2018