From f0c8330ebf1a64ddd3730a2992a05e2f742e86f4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 12 Jul 2015 22:02:11 -0400 Subject: [PATCH] Filter: Added a mechanism to override ::safety --- src/Filter.cpp | 38 ++++++++++++++++++++++++-------------- src/Filter.h | 6 ++++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Filter.cpp b/src/Filter.cpp index 9695e707a..ba950f704 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -58,6 +58,7 @@ bool domSource (const std::string& identifier, Variant& value) Filter::Filter () : _startCount (0) , _endCount (0) +, _safety (true) { } @@ -261,28 +262,37 @@ bool Filter::pendingOnly () // all tasks to be modified. This is usually not intended. void Filter::safety () { - for (auto& a : context.cli2._args) + if (_safety) { - if (a.hasTag ("CMD")) + for (auto& a : context.cli2._args) { - if (a.hasTag ("WRITECMD")) + if (a.hasTag ("CMD")) { - if (! context.config.getBoolean ("allow.empty.filter")) - throw std::string (STRING_TASK_SAFETY_ALLOW); + if (a.hasTag ("WRITECMD")) + { + if (! context.config.getBoolean ("allow.empty.filter")) + throw std::string (STRING_TASK_SAFETY_ALLOW); - // If user is willing to be asked, this can be avoided. - if (context.config.getBoolean ("confirmation") && - confirm (STRING_TASK_SAFETY_VALVE)) - return; + // If user is willing to be asked, this can be avoided. + if (context.config.getBoolean ("confirmation") && + confirm (STRING_TASK_SAFETY_VALVE)) + return; - // Sounds the alarm. - throw std::string (STRING_TASK_SAFETY_FAIL); + // Sounds the alarm. + throw std::string (STRING_TASK_SAFETY_FAIL); + } + + // CMD was found. + return; } - - // CMD was found. - return; } } } //////////////////////////////////////////////////////////////////////////////// +void Filter::disableSafety () +{ + _safety = false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Filter.h b/src/Filter.h index e2c4c3d44..80c84487a 100644 --- a/src/Filter.h +++ b/src/Filter.h @@ -44,10 +44,12 @@ public: void subset (std::vector &, bool applyContext = true); bool pendingOnly (); void safety (); + void disableSafety (); private: - int _startCount; - int _endCount; + int _startCount; + int _endCount; + bool _safety; }; #endif