From 60667dbcaacdf9a9f6c44537b435c9b75e343e74 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 11 Jan 2016 22:30:35 -0500 Subject: [PATCH] TW-1705: Directories in .task/hooks should not be reported as invalid hooks - Thanks to Tomas Babej. --- ChangeLog | 2 + src/Hooks.cpp | 19 ++++++---- src/commands/CmdDiagnostics.cpp | 67 ++++++++++++++++++--------------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 407e21d79..ff3ecc75b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,8 @@ - TW-1703 When on-modify hook is installed, some messages print UUIDs instead of IDs (thanks to Robin Green). - TW-1704 Use Task::identifier to reference the Task in the output +- TW-1705 Directories in .task/hooks should not be reported as invalid hooks + (thanks to Tomas Babej). - TW-1720 CmdContext uses a mix of both throw and std::cout to convey errors (thanks to Paul Beckingham). - TW-1723 task info causes segfault (thanks to Roman Golovin). diff --git a/src/Hooks.cpp b/src/Hooks.cpp index e6eac205f..61cfccffc 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -71,14 +71,17 @@ void Hooks::initialize () for (auto& i : _scripts) { Path p (i); - std::string name = p.name (); - if (name.substr (0, 6) == "on-add" || - name.substr (0, 9) == "on-modify" || - name.substr (0, 9) == "on-launch" || - name.substr (0, 7) == "on-exit") - context.debug ("Found hook script " + i); - else - context.debug ("Found misnamed hook script " + i); + if (! p.is_directory ()) + { + std::string name = p.name (); + if (name.substr (0, 6) == "on-add" || + name.substr (0, 9) == "on-modify" || + name.substr (0, 9) == "on-launch" || + name.substr (0, 7) == "on-exit") + context.debug ("Found hook script " + i); + else + context.debug ("Found misnamed hook script " + i); + } } } } diff --git a/src/commands/CmdDiagnostics.cpp b/src/commands/CmdDiagnostics.cpp index 0717a89e5..cdf60cc32 100644 --- a/src/commands/CmdDiagnostics.cpp +++ b/src/commands/CmdDiagnostics.cpp @@ -331,22 +331,24 @@ int CmdDiagnostics::execute (std::string& output) for (auto& hook : hooks) { Path p (hook); - - std::string name = p.name (); - - if (p.executable () && - (name.substr (0, 6) == "on-add" || - name.substr (0, 9) == "on-modify" || - name.substr (0, 9) == "on-launch" || - name.substr (0, 7) == "on-exit")) + if (! p.is_directory ()) { - out << (count++ ? " " : ""); + std::string name = p.name (); - out.width (longest); - out << std::left << name - << format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) - << (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") - << "\n"; + if (p.executable () && + (name.substr (0, 6) == "on-add" || + name.substr (0, 9) == "on-modify" || + name.substr (0, 9) == "on-launch" || + name.substr (0, 7) == "on-exit")) + { + out << (count++ ? " " : ""); + + out.width (longest); + out << std::left << name + << format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) + << (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") + << "\n"; + } } } @@ -355,25 +357,28 @@ int CmdDiagnostics::execute (std::string& output) for (auto& hook : hooks) { Path p (hook); - std::string name = p.name (); - - if (! p.executable () || - (name.substr (0, 6) != "on-add" && - name.substr (0, 9) != "on-modify" && - name.substr (0, 9) != "on-launch" && - name.substr (0, 7) != "on-exit")) + if (! p.is_directory ()) { - out << (count++ ? " " : ""); + std::string name = p.name (); - out.width (longest); - out << std::left << name - << (p.executable () ? format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) : format (" ({1})", STRING_CMD_DIAG_HOOK_NO_EXEC)) - << (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") - << ((name.substr (0, 6) == "on-add" || - name.substr (0, 9) == "on-modify" || - name.substr (0, 9) == "on-launch" || - name.substr (0, 7) == "on-exit") ? "" : format (" ({1})", STRING_CMD_DIAG_HOOK_NAME)) - << "\n"; + if (! p.executable () || + (name.substr (0, 6) != "on-add" && + name.substr (0, 9) != "on-modify" && + name.substr (0, 9) != "on-launch" && + name.substr (0, 7) != "on-exit")) + { + out << (count++ ? " " : ""); + + out.width (longest); + out << std::left << name + << (p.executable () ? format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) : format (" ({1})", STRING_CMD_DIAG_HOOK_NO_EXEC)) + << (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") + << ((name.substr (0, 6) == "on-add" || + name.substr (0, 9) == "on-modify" || + name.substr (0, 9) == "on-launch" || + name.substr (0, 7) == "on-exit") ? "" : format (" ({1})", STRING_CMD_DIAG_HOOK_NAME)) + << "\n"; + } } } }