- Implemented the safety mechanism that checks for confirmation is a
  write command processes a filter, but the filter expression is blank.
  For example, running "task delete" would delete all tasks unless this
  safety check is in place.
This commit is contained in:
Paul Beckingham 2014-05-24 23:48:20 -04:00
parent 4e9c8ede2b
commit 1964ffc053

View file

@ -32,6 +32,8 @@
#include <Variant.h> #include <Variant.h>
#include <Dates.h> #include <Dates.h>
#include <Filter.h> #include <Filter.h>
#include <i18n.h>
#include <util.h>
extern Context context; extern Context context;
@ -289,25 +291,31 @@ bool Filter::pendingOnly ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Disaster avoidance mechanism. // Disaster avoidance mechanism. If a WRITECMD has no filter, then it can cause
// all tasks to be modified. This is usually not intended.
void Filter::safety () void Filter::safety ()
{ {
/* Tree* tree = context.a3t.tree ();
if (! _read_only) std::vector <Tree*>::iterator i;
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
{ {
A3 write_filter = context.a3.extract_filter (); if ((*i)->hasTag ("WRITECMD"))
if (!write_filter.size ()) // Potential disaster. {
if (context.a3t.getFilterExpression () == "")
{ {
// If user is willing to be asked, this can be avoided. // If user is willing to be asked, this can be avoided.
if (context.config.getBoolean ("confirmation") && if (context.config.getBoolean ("confirmation") &&
confirm (STRING_TASK_SAFETY_VALVE)) confirm (STRING_TASK_SAFETY_VALVE))
return; return;
// No. // Sounds the alarm.
throw std::string (STRING_TASK_SAFETY_FAIL); throw std::string (STRING_TASK_SAFETY_FAIL);
} }
// Nothing to see here. Move along.
return;
}
} }
*/
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////