From 1964ffc05391769c98e0e735cc73a557067ae0a9 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 24 May 2014 23:48:20 -0400 Subject: [PATCH] Filter - 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. --- src/Filter.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Filter.cpp b/src/Filter.cpp index 2a5b8a13d..88c77aa3b 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include 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 () { -/* - if (! _read_only) + Tree* tree = context.a3t.tree (); + std::vector ::iterator i; + for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i) { - A3 write_filter = context.a3.extract_filter (); - if (!write_filter.size ()) // Potential disaster. + if ((*i)->hasTag ("WRITECMD")) { - // If user is willing to be asked, this can be avoided. - if (context.config.getBoolean ("confirmation") && - confirm (STRING_TASK_SAFETY_VALVE)) - return; + if (context.a3t.getFilterExpression () == "") + { + // If user is willing to be asked, this can be avoided. + if (context.config.getBoolean ("confirmation") && + confirm (STRING_TASK_SAFETY_VALVE)) + return; - // No. - throw std::string (STRING_TASK_SAFETY_FAIL); + // Sounds the alarm. + throw std::string (STRING_TASK_SAFETY_FAIL); + } + + // Nothing to see here. Move along. + return; } } -*/ } ////////////////////////////////////////////////////////////////////////////////