TW-1705: Directories in .task/hooks should not be reported as invalid hooks

- Thanks to Tomas Babej.
This commit is contained in:
Paul Beckingham
2016-01-11 22:30:35 -05:00
parent 19f57ffead
commit 60667dbcaa
3 changed files with 49 additions and 39 deletions

View File

@@ -22,6 +22,8 @@
- TW-1703 When on-modify hook is installed, some messages print UUIDs - TW-1703 When on-modify hook is installed, some messages print UUIDs
instead of IDs (thanks to Robin Green). instead of IDs (thanks to Robin Green).
- TW-1704 Use Task::identifier to reference the Task in the output - 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 - TW-1720 CmdContext uses a mix of both throw and std::cout to convey
errors (thanks to Paul Beckingham). errors (thanks to Paul Beckingham).
- TW-1723 task info causes segfault (thanks to Roman Golovin). - TW-1723 task info causes segfault (thanks to Roman Golovin).

View File

@@ -71,14 +71,17 @@ void Hooks::initialize ()
for (auto& i : _scripts) for (auto& i : _scripts)
{ {
Path p (i); Path p (i);
std::string name = p.name (); if (! p.is_directory ())
if (name.substr (0, 6) == "on-add" || {
name.substr (0, 9) == "on-modify" || std::string name = p.name ();
name.substr (0, 9) == "on-launch" || if (name.substr (0, 6) == "on-add" ||
name.substr (0, 7) == "on-exit") name.substr (0, 9) == "on-modify" ||
context.debug ("Found hook script " + i); name.substr (0, 9) == "on-launch" ||
else name.substr (0, 7) == "on-exit")
context.debug ("Found misnamed hook script " + i); context.debug ("Found hook script " + i);
else
context.debug ("Found misnamed hook script " + i);
}
} }
} }
} }

View File

@@ -331,22 +331,24 @@ int CmdDiagnostics::execute (std::string& output)
for (auto& hook : hooks) for (auto& hook : hooks)
{ {
Path p (hook); Path p (hook);
if (! p.is_directory ())
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"))
{ {
out << (count++ ? " " : ""); std::string name = p.name ();
out.width (longest); if (p.executable () &&
out << std::left << name (name.substr (0, 6) == "on-add" ||
<< format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) name.substr (0, 9) == "on-modify" ||
<< (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") name.substr (0, 9) == "on-launch" ||
<< "\n"; 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) for (auto& hook : hooks)
{ {
Path p (hook); Path p (hook);
std::string name = p.name (); if (! p.is_directory ())
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++ ? " " : ""); std::string name = p.name ();
out.width (longest); if (! p.executable () ||
out << std::left << name (name.substr (0, 6) != "on-add" &&
<< (p.executable () ? format (" ({1})", STRING_CMD_DIAG_HOOK_EXEC) : format (" ({1})", STRING_CMD_DIAG_HOOK_NO_EXEC)) name.substr (0, 9) != "on-modify" &&
<< (p.is_link () ? format (" ({1})", STRING_CMD_DIAG_HOOK_SYMLINK) : "") name.substr (0, 9) != "on-launch" &&
<< ((name.substr (0, 6) == "on-add" || name.substr (0, 7) != "on-exit"))
name.substr (0, 9) == "on-modify" || {
name.substr (0, 9) == "on-launch" || out << (count++ ? " " : "");
name.substr (0, 7) == "on-exit") ? "" : format (" ({1})", STRING_CMD_DIAG_HOOK_NAME))
<< "\n"; 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";
}
} }
} }
} }