if (_config->FindI("quiet",0) < 2
&& _config->FindB("APT::Get::Assume-Yes",false) == false)
{
- c2out << _("Install these packages without verification?") << std::flush;
- if (!YnPrompt(false))
+ if (!YnPrompt(_("Install these packages without verification?"), false))
return _error->Error(_("Some packages could not be authenticated"));
return true;
// TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
// careful with hard to type or special characters (like non-breaking spaces)
const char *Prompt = _("Yes, do as I say!");
- ioprintf(c2out,
+ std::string question;
+ strprintf(question,
_("You are about to do something potentially harmful.\n"
"To continue type in the phrase '%s'\n"
" ?] "),Prompt);
- c2out << std::flush;
- if (AnalPrompt(Prompt) == false)
+ if (AnalPrompt(question, Prompt) == false)
{
c2out << _("Abort.") << std::endl;
exit(1);
if (_config->FindI("quiet",0) < 2 &&
_config->FindB("APT::Get::Assume-Yes",false) == false)
{
- c2out << _("Do you want to continue?") << std::flush;
- if (YnPrompt() == false)
+ if (YnPrompt(_("Do you want to continue?")) == false)
{
c2out << _("Abort.") << std::endl;
exit(1);
// YnPrompt - Yes No Prompt. /*{{{*/
// ---------------------------------------------------------------------
/* Returns true on a Yes.*/
-bool YnPrompt(bool Default)
+bool YnPrompt(char const * const Question, bool Default)
{
+ auto const AssumeYes = _config->FindB("APT::Get::Assume-Yes",false);
+ auto const AssumeNo = _config->FindB("APT::Get::Assume-No",false);
+ // if we ask interactively, show warnings/notices before the question
+ if (AssumeYes == false && AssumeNo == false)
+ {
+ if (_config->FindI("quiet",0) > 0)
+ _error->DumpErrors(c2out);
+ else
+ _error->DumpErrors(c2out, GlobalError::DEBUG);
+ }
+
+ c2out << Question << std::flush;
+
/* nl_langinfo does not support LANGUAGE setting, so we unset it here
to have the help-message (hopefully) match the expected characters */
char * language = getenv("LANGUAGE");
free(language);
}
- if (_config->FindB("APT::Get::Assume-Yes",false) == true)
+ if (AssumeYes)
{
// TRANSLATOR: "Yes" answer printed for a yes/no question if --assume-yes is set
c1out << _("Y") << std::endl;
return true;
}
- else if (_config->FindB("APT::Get::Assume-No",false) == true)
+ else if (AssumeNo)
{
// TRANSLATOR: "No" answer printed for a yes/no question if --assume-no is set
c1out << _("N") << std::endl;
// AnalPrompt - Annoying Yes No Prompt. /*{{{*/
// ---------------------------------------------------------------------
/* Returns true on a Yes.*/
-bool AnalPrompt(const char *Text)
+bool AnalPrompt(std::string const &Question, const char *Text)
{
+ if (_config->FindI("quiet",0) > 0)
+ _error->DumpErrors(c2out);
+ else
+ _error->DumpErrors(c2out, GlobalError::DEBUG);
+ c2out << Question << std::flush;
+
char Buf[1024];
std::cin.getline(Buf,sizeof(Buf));
if (strcmp(Buf,Text) == 0)
void Stats(std::ostream &out, pkgDepCache &Dep);
// prompting
-bool YnPrompt(bool Default=true);
-bool AnalPrompt(const char *Text);
+bool YnPrompt(char const * const Question, bool Default=true);
+bool AnalPrompt(std::string const &Question, const char *Text);
std::string PrettyFullName(pkgCache::PkgIterator const &Pkg);
std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg);
{
bool res;
pkgSourceList sl;
- std::string outs;
std::string sourceslist;
if (CmdL.FileList[1] != NULL)
int lockfd = GetLock(sourceslist);
if (lockfd < 0)
return false;
-
+
do {
EditFileInSensibleEditor(sourceslist);
_error->PushToStack();
res = sl.Read(sourceslist);
if (!res) {
- _error->DumpErrors(std::cerr, GlobalError::DEBUG, false);
- strprintf(outs, _("Failed to parse %s. Edit again? "),
- sourceslist.c_str());
- std::cout << outs;
+ std::string outs;
+ strprintf(outs, _("Failed to parse %s. Edit again? "), sourceslist.c_str());
// FIXME: should we add a "restore previous" option here?
- res = !YnPrompt(true);
+ res = !YnPrompt(outs.c_str(), true);
}
_error->RevertToStack();
} while (res == false);
close(lockfd);
if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) {
- strprintf(
- outs, _("Your '%s' file changed, please run 'apt-get update'."),
+ ioprintf(
+ std::cout, _("Your '%s' file changed, please run 'apt-get update'."),
sourceslist.c_str());
- std::cout << outs << std::endl;
}
return true;
msgtest "Good link instead of a file as apt.conf ignored"
echo 'Test::APT::Link "good";' > rootdir/etc/apt/good-link.conf
ln -s rootdir/etc/apt/good-link.conf rootdir/etc/apt/apt.conf
-test -n "$(aptconfig shell TestLink 'Test::APT::Link')" && msgfail || msgpass
+testempty aptconfig shell TestLink 'Test::APT::Link'
rm rootdir/etc/apt/apt.conf
msgtest "Broken link instead of a file as apt.conf ignored"
msgtest "Good link instead of a file as sources.list ignored"
echo 'deb file:///tmp/debian sid main' > rootdir/etc/apt/good-link.list
ln -s rootdir/etc/apt/good-link.list rootdir/etc/apt/sources.list
-test -n "$(aptget update --print-uris)" && msgfail || msgpass
+testempty aptget update --print-uris
rm rootdir/etc/apt/sources.list
msgtest "Broken link instead of a file as sources.list ignored"
ln -s /tmp/doesnt-exist rootdir/etc/apt/sources.list
-test -n "$(aptget update --print-uris)" && msgfail || msgpass
+testempty aptget update --print-uris
rm rootdir/etc/apt/sources.list
Pin: release a=now
Pin-Value: 1000' > rootdir/etc/apt/good-link.pref
ln -s rootdir/etc/apt/good-link.pref rootdir/etc/apt/preferences
-test -n "$(aptcache policy | grep '1000 ')" && msgfail || msgpass
+testsuccess aptcache policy
+testfailure grep '1000 ' rootdir/tmp/testsucess.output
rm rootdir/etc/apt/preferences
msgtest "Broken link instead of a file as preferences ignored"