[Aptitude-svn-commit] r4317 - in branches/aptitude-0.3/aptitude: .
src src/cmdline
Daniel Burrows
dburrows at costa.debian.org
Tue Sep 27 22:00:29 UTC 2005
Author: dburrows
Date: Tue Sep 27 22:00:26 2005
New Revision: 4317
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.cc
branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.h
branches/aptitude-0.3/aptitude/src/main.cc
Log:
Don't die horribly when we get EOF on stdin.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Tue Sep 27 22:00:26 2005
@@ -1,5 +1,14 @@
2005-09-27 Daniel Burrows <dburrows at debian.org>
+ * src/main.cc, src/cmdline/cmdline_prompt.cc, src/cmdline/cmdline_prompt.h:
+
+ Toss an exception from the command-line code when EOF is
+ encountered, and write a corresponding catch handler; also
+ replace the special-cased catch blocks in main.cc with generic
+ catches for the Exception type (so the exception gets printed to
+ stderr). In particular, this means that aptitude no longer goes
+ nuts when it encounters an EOF. (Closes: #318749)
+
* src/ui.cc:
Check for the existence of the old temporary directory on
Modified: branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.cc (original)
+++ branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.cc Tue Sep 27 22:00:26 2005
@@ -28,6 +28,11 @@
using namespace std;
+string StdinEOFException::errmsg() const
+{
+ return _("Unexpected end-of-file on standard input");
+}
+
struct fetchinfo
{
double FetchBytes, FetchPBytes, DebBytes;
@@ -273,12 +278,15 @@
cin.getline(buf, 1023);
rval+=buf;
- while(!cin)
+ while(!cin && !cin.eof())
{
cin.getline(buf, 1023);
rval+=buf;
}
+ if(!cin)
+ throw StdinEOFException();
+
return rval;
}
@@ -338,9 +346,12 @@
cin.getline(buf, 1023);
bool rval=(prompt==buf);
- while(!cin)
+ while(!cin && !cin.eof())
cin.getline(buf, 1023);
+ if(!cin)
+ throw StdinEOFException();
+
return rval;
}
@@ -399,6 +410,9 @@
cin.getline(buf, 1023);
buf[1023]='\0';
+ if(cin.eof())
+ throw StdinEOFException();
+
const bool is_ok=(strncasecmp(okstr.c_str(), buf, okstr.size())==0);
const bool is_abort=(strncasecmp(abortstr.c_str(), buf, abortstr.size())==0);
Modified: branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.h (original)
+++ branches/aptitude-0.3/aptitude/src/cmdline/cmdline_prompt.h Tue Sep 27 22:00:26 2005
@@ -7,6 +7,17 @@
#include "cmdline_common.h"
+#include <generic/util/exception.h>
+
+/** Thrown when we get EOF on stdin. Should never be thrown
+ * to the toplevel.
+ */
+class StdinEOFException : public Exception
+{
+public:
+ std::string errmsg() const;
+};
+
/** The main preview-prompt-adjust-preview loop for the command-line
* interface. Displays a preview of what will happen, then allows
* the user to confirm, cancel, or perform a number of other actions.
@@ -29,6 +40,8 @@
* \param force_no_change if \b true, try extra-hard to preserve
* the user's explicit requests (as
* specified in to_install et al)
+ *
+ * \throws StdinEOFException
*/
bool cmdline_do_prompt(bool as_upgrade,
pkgset &to_install,
@@ -47,6 +60,8 @@
*
* \param prompt a message to display before reading input.
* \return the text the user entered
+ *
+ * \throws StdinEOFException
*/
string prompt_string(const string &prompt);
Modified: branches/aptitude-0.3/aptitude/src/main.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/main.cc (original)
+++ branches/aptitude-0.3/aptitude/src/main.cc Tue Sep 27 22:00:26 2005
@@ -48,6 +48,7 @@
#include <cmdline/cmdline_dump_resolver.h>
#include <cmdline/cmdline_forget_new.h>
#include <cmdline/cmdline_moo.h>
+#include <cmdline/cmdline_prompt.h>
#include <cmdline/cmdline_search.h>
#include <cmdline/cmdline_show.h>
#include <cmdline/cmdline_update.h>
@@ -468,15 +469,15 @@
exit(1);
}
}
- catch(NoMoreSolutions)
+ catch(StdinEOFException)
{
- fprintf(stderr, "%s", _("Internal error: uncaught 'out of solutions' exception.\n"));
- exit(-1);
+ printf("%s", _("Abort.\n"));
+ return -1;
}
- catch(NoMoreTime)
+ catch(const Exception &e)
{
- fprintf(stderr, "%s", _("Internal error: uncaught 'out of time' exception.\n"));
- exit(-1);
+ fprintf(stderr, _("Uncaught exception: %s\n"), e.errmsg().c_str());
+ return -1;
}
}
@@ -510,15 +511,10 @@
ui_main();
}
- catch(NoMoreSolutions)
+ catch(const Exception &e)
{
- fprintf(stderr, "%s", _("Internal error: uncaught 'out of solutions' exception.\n"));
- exit(-1);
- }
- catch(NoMoreTime)
- {
- fprintf(stderr, "%s", _("Internal error: uncaught 'out of time' exception.\n"));
- exit(-1);
+ fprintf(stderr, _("Uncaught exception: %s\n"), e.errmsg().c_str());
+ return -1;
}
return 0;
More information about the Aptitude-svn-commit
mailing list